Click here to Skip to main content
15,884,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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<lpwstr> (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
Updated 29-Oct-12 20:08pm
v2
Comments
Argonia 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
http://msdn.microsoft.com/en-us/library/aa910763.aspx
Virendra_ec10 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;
HRESULT hr;
CoInitialize (NULL);
if (FAILED(m_ptr.CreateInstance(L"mbase32")) || m_isis == 0)
{
printf("Fail!");
}
hr=m_ptr->CreateBuffer(65536) ;//here hr = -858993460
return 0;
}
Please suggest, why I am getting a negative value of hr.

Thanks

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.
 
Share this answer
 
Please refer..

http://www.gfi.com/blog/32bit-object-64bit-environment/

It will really solve your problem...
 
Share this answer
 
v2
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..

C++
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;
}
 
Share this answer
 
Comments
Virendra_ec10 2-Nov-12 1:08am    
Hi Enhzflep,

Thanks for your response, but it dint help.

Thanks,
Vieer
enhzflep 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'.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900