Click here to Skip to main content
15,896,522 members
Articles / Programming Languages / C++

COM from scratch - PART TWO

Rate me:
Please Sign up or sign in to vote.
4.85/5 (44 votes)
17 Apr 200414 min read 229.5K   6K   134  
An article about COM Library.
// Create.cpp 
#include "iostream.h" 
#include "unknwn.h" 
#include "Create.h" 

typedef IUnknown* (*CREATEFUNCPTR)();

///////////////////////////////
void _TRACE(const char* msg)
{ 
	cout << "Client :\t" <<msg<<endl;
}

/////////////////////////////////////////////
IUnknown* CallCreateInstance(char* dllname)
{
    //-----------------------------------------------------------------------------------//
    // Load dynamic link library into client's process.
    //Loadlibrary maps a DLL module and return a handle that can be used in GetProcAddress
    //to get the address of a DLL function
    //----------------------------------------------------------------------------------//
    _TRACE("Attempting to Load component's server...");
    HMODULE hm = ::LoadLibrary(dllname) ;
    if (hm == NULL)
    {
        _TRACE("CallCreateInstance:\tError: Cannot load the component's server.");
        return NULL ;
    }
    
    // Getting the address of the CreateInstance function.
    CREATEFUNCPTR Function= (CREATEFUNCPTR)::GetProcAddress(hm, "CreateInstance") ;
    
    if (Function == NULL)
    {
        _TRACE("Function is not found!.");
        return NULL ;
    }
    _TRACE("Component's server is loaded sucsussfully.");
    return Function() ;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions