C# - Step 9 Writing C++ Test Application to test C# ClassLibrary
Here is the C++ code to test the C# Class Library (COM Server).
#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <atlbase.h>
#include <atlstr.h>
#include <iostream>
#import "../SFTCSServer/bin/x86/debug/SFTCSServer.tlb"
using namespace SFTCSServer;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
IMathCtrl *pMathCtrl = NULL;
CComPtr<IMathCtrl> ptr;
HRESULT hResult = ptr.CoCreateInstance(_T("SFTCSServer.MathCtrl"));
if(FAILED(hResult))
{
printf("Unable to create COM Object: 0x%x\n" , (DWORD)hResult);
return 0;
}
std::cout << ptr->AddNumbers(10, 15) << "\n";
std::cout << ptr->AddNumbers(10, 25) << "\n";
std::cout << ptr->AddNumbers(10, 35) << "\n";
return 0;
}
Back to Index of Steps for C# class Library Server and C++ Index
Click here to download the complete source code of C# Class Library Server and C++ Client
|