at first, create an IDL-File from your control :
msvc->Tools->OLE/COM-ObjectViewer->AllObjects->RightClickOnYourDll->ViewTypeInformation->Save
//be care with floats from visualbasic ! simple replace "SINGLE" with "float" in the IDL-File yourIDL-File.idl
now create the both c-files :
MIDL /ms_ext /c_ext /cstub yourImplFile.c /h yourImplHeader.h yourIDL-File.idl
as next, include the created interface in your code :
#include yourImplHeader.h
//from yourImplFile.c :
const IID IID__FloodNetDll = {0x0F405369,0xB9FF,0x45B9,{0x82,0x36,0x7E,0x52,0x7F,0x6D,0xA6,0x52}};
const CLSID CLSID_FloodNetDll = {0x92BEB9AE,0x8447,0x4C78,{0x98,0x5D,0x81,0x4F,0x37,0xA9,0x7E,0x3E}};
//now the instance :
_HRESULT hr;
// pointee to Interface from yourImplHeader.h
_yourImplClass *IFnDll;
// initiate COM
hr = CoInitialize(0);
//fill the pointee:
hr = CoCreateInstance( CLSID_FloodNetDll, NULL, CLSCTX_INPROC_SERVER,IID__FloodNetDll, (void**) &IFnDll);
//do something ith numbers:
float ret;
float n1, n2;
n1=5; n2=7;
hr = IFnDll->AddNumbers(&n1, &n2, &ret);
//do something with strings :
BSTR strPar;
wchar_t csPar[15]=L"TextParameter";
strPar=BSTR(csPar);
hr = IFnDll->ShowText(&strPar);
//release dll :
hr = IFnDll->Release();
// Uninitialize COM :
CoUninitialize();
Partager