Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to import COM object in VC6?

Posted on 1999-09-09
7
Medium Priority
?
423 Views
Last Modified: 2013-11-20
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!@@
0
Comment
Question by:Haho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2035730
If it comes with a type library, you can use #import. See the documentation for more information.
0
 
LVL 1

Author Comment

by:Haho
ID: 2036312
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
 
LVL 3

Expert Comment

by:Norbert
ID: 2036373
Typelib is not *.lib it is *.tlb
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 23

Accepted Solution

by:
naveenkohli earned 400 total points
ID: 2036635
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
 
LVL 23

Expert Comment

by:naveenkohli
ID: 2036762
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
 
LVL 23

Expert Comment

by:chensu
ID: 2037492
A type library may be incorporated into a DLL.
0
 
LVL 1

Author Comment

by:Haho
ID: 2047125
thanks, and also to chensu...
sorry for not knowing what a type lib (tlb) is....

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question