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!@@
LVL 1
HahoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
naveenkohliConnect With a Mentor Commented:
You can do it with DLL only. You will import the DLL. The only condition is that your type lib should be included your DLL.
In the header file of your console app,

Example .....

#import "ConObject.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids
0
 
chensuCommented:
If it comes with a type library, you can use #import. See the documentation for more information.
0
 
HahoAuthor Commented:
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?
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
NorbertCommented:
Typelib is not *.lib it is *.tlb
0
 
naveenkohliCommented:
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.dll" 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->GetOSInformation (&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;
}
0
 
chensuCommented:
A type library may be incorporated into a DLL.
0
 
HahoAuthor Commented:
thanks, and also to chensu...
sorry for not knowing what a type lib (tlb) is....

0
All Courses

From novice to tech pro — start learning today.