Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 629009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:41:55+00:00 2026-05-13T19:41:55+00:00

First, COM is like black magic for me. But I need to use COM

  • 0

First, COM is like black magic for me. But I need to use COM dll in one project I’m working on.

So, I have a DLL I am developing and I need some functionalities that are available in a separate COM DLL. When I look to the COM DLL with Depends.exe I see methods like DllGetClassObject() and other functions but none of the functions I’m interested in.

I have access to the COM DLL (legacy) source code but it’s a mess and I’d rather like to use the COM DLL in binary like a big black box not knowing what’s going on inside.

So, how can I call the COM DLL functions from my code using LoadLibrary? Is it possible? If, yes, could you give me an example of how to do it?

I’m using Visual Studio 6 for this project.

Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:41:55+00:00Added an answer on May 13, 2026 at 7:41 pm

    Typically you would use CoCreateInstance() to instantiate an object from a COM DLL. When you do this, there’s no need to load the DLL first and get proc addresses like you would need to do with a normal DLL. This is because Windows “knows” about the types that a COM DLL implements, what DLL they are implemented in, and how to instantiate them. (Assuming of course that the COM DLL is registered, which it typically is).

    Suppose you have a COM DLL with the IDog interface you want to use. In that case,

    dog.idl

    interface IDog : IUnknown
    {
      HRESULT Bark();
    };
    
    coclass Dog
    {
      [default] Interface IDog;
    };
    

    myCode.cpp

    IDog* piDog = 0;
    CoCreateInstance(CLSID_DOG, 0,  CLSCTX_INPROC_SERVER, IID_IDOG,  &piDog); // windows will instantiate the IDog object and place the pointer to it in piDog
    piDog->Bark();  // do stuff
    piDog->Release();  // were done with it now
    piDog = 0;  // no need to delete it -- COM objects generally delete themselves
    

    All this memory management stuff can get pretty grungy, though, and the ATL provides smart pointers that make the task of instantiating & managing these objects a little easier:

    CComPtr<IDog> dog;
    dog.CoCreateInstance(CLSID_DOG);
    dog->Bark();
    

    EDIT:

    When I said above that:

    Windows “knows” about the types that a COM DLL implements […and]
    what DLL they are implemented in

    …I really glossed over exactly how Windows knows this. It’s not magic, although it might seem a little occult-ish at first.

    COM libraries come with Type Libraries, which list the Interfaces and CoClasses that the library provides. This Type Library is in the form of a file on your hard drive — very often it is embedded directly in the same DLL or EXE as the library itself. Windows knows where to find the Type Library and the COM Library itself by looking in the Windows Registry. Entries in the Registry tell Windows where on the hard drive the DLL is located.

    When you call CoCreateInstance, Windows looks the clsid up in the Windows Registry, finds the corresponding DLL, loads it, and executes the proper code in the DLL that implements the COM object.

    How does this information get in to the Windows Registry? When a COM DLL is installed, it is registered. This is typically done by running regsvr32.exe, which in turn loads your DLL in to memory and calls a function named DllRegisterServer. That function, implemented in your COM server, adds the necesarry information to the Registry. If you are using ATL or another COM framework, this is probably being done under the hood so that you don’t have to interface with the Registry directly. DllRegisterServer only needs to be called once, at install-time.

    If you try to call CoCreateInstance for a COM object that has not yet been registered via the regsvr32/DllRegisterServer process, then CoCreateInstance will fail with an error that says:

    Class Not Registered

    Fortunately, the fix for this is to simply call regsvr32 on your COM server, and then try again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I know how to build a Java application. But I have
First off, I'm working on an app that's written such that some of your
First off, according to http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx , the List.Find method is only listed as throwing
First off, I am using Windows XP. I have multiple hard drives and it
First, let's get the security considerations out of the way. I'm using simple authentication
First off, I understand the reasons why an interface or abstract class (in the
First off if you're unaware, samba or smb == Windows file sharing, \\computer\share etc.
First off, there's a bit of background to this issue available on my blog:
First off: I'm using a rather obscure implementation of javascript embedded as a scripting
First let me say that I really feel directionless on this question. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.