Click here to Skip to main content
11,802,636 members (68,998 online)
Rate this: bad
Please Sign up or sign in to vote.
Hello C++ Gurus,

I created a 64-bit COM DLL by compiling a 32-bit application in visual studio 2010(Mode-Release, Platform-x64) and registered it successfully using Regsvr32.exe tool.
I am trying to create the instance of the dll but, I am getting "Class Not registered " error in the below function:
hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));

I observed that for 32-bit DLL I am getting clsid as 'CLSID _IDispatch ibase32' in the function:
hr = CLSIDFromProgID(const_cast (clsidString), &clsid);
But it gives the Class ID not the IDispatch interface for 64-bit DLL.

Please anybody suggest the solution.

Thanks in Advance.
Posted 29-Oct-12 0:11am
Edited 29-Oct-12 20:08pm
Argonia at 29-Oct-12 10:21am
You cannot create an instance of a DLL . The instances are made of classes and you need a registered class which is derived by some interfaces (maybe control and /or one for events) which describes the functions from these interfaces . Maybe this link will help you. There is really nice tutorial in msdn too
Virendra_ec10 at 5-Nov-12 6:38am
I registered the 64-bit DLL in the registry successfully. I am using the below code for creating the instance. I am getting a valid m_ptr pointer.However, when I am calling a function like m_ptr ->CreateBuffer(65536); it returns -858993460.


#include "stdafx.h"
#include "dlllib.tlh"

int _tmain(int argc, _TCHAR* argv[])
mPtr m_ptr = NULL;
CoInitialize (NULL);
if (FAILED(m_ptr.CreateInstance(L"mbase32")) || m_isis == 0)
hr=m_ptr->CreateBuffer(65536) ;//here hr = -858993460
return 0;
Please suggest, why I am getting a negative value of hr.

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I'm still(hopefully will remain?) pretty wet-behind-the-ears with respect to COM work. Though I do note that the behaviour you report is the same as that which I observe when starting a 32bit COM server under either windows xp or 7.

That is to say CLSIDFromProgId does just that - it returns a classID. A classID that you then use later to start the server with.

I work with gcc predominantly, so miss the advantages of the wizards in VS. as a result I've had to put together my own set of helper functions. Here's the one I use when starting a com server. Hope it's not entirely useless..

IDispatch *startServer(wchar_t *serverName)
   // Get CLSID for our server...
   CLSID clsid;
   wstring progId, errorMsg;
    progId = serverName;
    progId += L".Application";
   HRESULT hr = CLSIDFromProgID(progId.c_str(), &clsid);
   if(FAILED(hr)) {
      MessageBox(NULL, L"CLSIDFromProgID() failed", L"Error", 0x10010);
      return NULL;
   // Start server and get IDispatch...
   IDispatch *pResult;
   hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pResult);
   if(FAILED(hr)) {
       errorMsg = serverName;
       errorMsg += L" not registered properly";
      MessageBox(NULL, errorMsg.c_str(), L"Error", 0x10010);
      return NULL;
    return pResult;
Virendra_ec10 at 2-Nov-12 1:08am
Hi Enhzflep,

Thanks for your response, but it dint help.

enhzflep at 5-Nov-12 12:10pm
Hi Vieer, just got email of your response (strange - 3 days late).
Sorry it didn't help you.
The only other thing I can think of to check is that the permissions are okay. I run MSOffice as Admin, so I can save a document anywhere I like. The consequence of this is that if I try to create a COM object of excel or word (& the other programs if I tried them) it will only succeed if the program trying to create that object is also run as Admin. - I run xampp as a service so that it has the permisions needed, anything else I right-click and 'run-as-Admin'.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If you are trying to create a COM object from a 32 bit dll/exe , then your 64 bit com object cannot be instantiated .
Because Windows maintain separate entries for 32 bit and 64 bit COM objects. Hence make sure that your COM object and your container application belongs to same architecture (either 32 bit or 64 bit .....not mixed)

Search for SysWOW on on the net.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please refer..

It will really solve your problem...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,695
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 12 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100