Haho
asked on
How to import COM object in VC6?
hi,
I am writing a VC console program that uses a COM object
(sdk.dll). Can anybody give me an working example and how it calls a sample function? The SDK comes with the dll and also the lib file but not the header files. Do I need the .h files?
Thnaks!@@
I am writing a VC console program that uses a COM object
(sdk.dll). Can anybody give me an working example and how it calls a sample function? The SDK comes with the dll and also the lib file but not the header files. Do I need the .h files?
Thnaks!@@
If it comes with a type library, you can use #import. See the documentation for more information.
ASKER
Sorry, but it doesn't work (assuming it doesn't have a
type lib (*.lib file) and only has a DLL file.
Import is only if u are using and IDL to "import" other
IDL files.
However, I tried adding to it my project library and I can
see it now BUT I cannot compile it.
What is wrong?
type lib (*.lib file) and only has a DLL file.
Import is only if u are using and IDL to "import" other
IDL files.
However, I tried adding to it my project library and I can
see it now BUT I cannot compile it.
What is wrong?
Typelib is not *.lib it is *.tlb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is example of the usage in a console application. This code is just a sample from a prototype. If you need the complete example.. let me know
#import "..\Bin\Debug\SystemInfo.d ll" raw_interfaces_only, raw_native_types, no_namespace, named_guids
int main(int argc, char* argv[])
{
char lpMultiByteStr[128];
cout << "Initializing COM" << endl;
if (FAILED (CoInitialize (NULL))) {
cout << "Failed to intialize COM" << endl;
return -1;
}
// Get the container object.
ISystemInformation *pSystemInfo = NULL;
hr = CoCreateInstance (CLSID_SystemInformation, NULL, CLSCTX_INPROC, IID_ISystemInformation,
(void **) &pSystemInfo);
if (FAILED (hr)) {
cout.setf (ios::hex, ios::basefield);
cout << "Failed to create SystemInfo object HR = " << hr << endl;
return -1;
}
BSTR bstrMinorVersion, bstrServicePack;
hr = pSystemInfo->GetOSInformat ion (&bstrPlatform, &bstrMinorVersion, &bstrServicePack,
&buildNumber);
if (FAILED (hr)) {
cout.setf (ios::hex, ios::basefield);
cout << "Failed to get SystemInfo object HR = " << hr << endl;
return -1;
}
WideCharToMultiByte (CP_ACP, 0, bstrPlatform, -1, lpMultiByteStr,
sizeof (lpMultiByteStr), NULL, NULL);
cout << "Platform = " << lpMultiByteStr << endl;
pSystemInfo->Release ();
::SysFreeString (bstrPlatform);
cout << "Sutting down COM" << endl;
CoUninitialize ();
return 0;
}
#import "..\Bin\Debug\SystemInfo.d
int main(int argc, char* argv[])
{
char lpMultiByteStr[128];
cout << "Initializing COM" << endl;
if (FAILED (CoInitialize (NULL))) {
cout << "Failed to intialize COM" << endl;
return -1;
}
// Get the container object.
ISystemInformation *pSystemInfo = NULL;
hr = CoCreateInstance (CLSID_SystemInformation, NULL, CLSCTX_INPROC, IID_ISystemInformation,
(void **) &pSystemInfo);
if (FAILED (hr)) {
cout.setf (ios::hex, ios::basefield);
cout << "Failed to create SystemInfo object HR = " << hr << endl;
return -1;
}
BSTR bstrMinorVersion, bstrServicePack;
hr = pSystemInfo->GetOSInformat
&buildNumber);
if (FAILED (hr)) {
cout.setf (ios::hex, ios::basefield);
cout << "Failed to get SystemInfo object HR = " << hr << endl;
return -1;
}
WideCharToMultiByte (CP_ACP, 0, bstrPlatform, -1, lpMultiByteStr,
sizeof (lpMultiByteStr), NULL, NULL);
cout << "Platform = " << lpMultiByteStr << endl;
pSystemInfo->Release ();
::SysFreeString (bstrPlatform);
cout << "Sutting down COM" << endl;
CoUninitialize ();
return 0;
}
A type library may be incorporated into a DLL.
ASKER
thanks, and also to chensu...
sorry for not knowing what a type lib (tlb) is....
sorry for not knowing what a type lib (tlb) is....