Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows MFC COM COM+ VC++ , +
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 1:11am
Edited 29-Oct-12 21:08pm
v2
Comments
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
http://msdn.microsoft.com/en-us/library/aa910763.aspx
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;
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
Rate this: bad
good
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;
}
  Permalink  
Comments
Virendra_ec10 at 2-Nov-12 1:08am
   
Hi Enhzflep,
 
Thanks for your response, but it dint help.
 
Thanks,
Vieer
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
good
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please refer..
 
http://www.gfi.com/blog/32bit-object-64bit-environment/
 
It will really solve your problem...
  Permalink  
v2

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

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 Jul 2013
Copyright © CodeProject, 1999-2014
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