COM Exception "Class Not Registered" when trying to instantiate an object from a 32 bit dll

  • Thread starter Thread starter Sagar R. Kapadia
  • Start date Start date
S

Sagar R. Kapadia

Guest
I have two separate apps, 64 bit and 32 bit for a specific piece of functionality. The structure is that there is a 64 bit app, ProcessMonitorLibX64 and a supporting dll HookDLL_X64.dll, both written in C++. The HookDLL instantiates an inproc COM server SocketClient [interface ISocketClient] from a C# class library called SocketCommunicationLibraryX64, and uses it.

There is a similar setup for 32 bit.

The problem is, the 64 bit system works perfectly, but in the case of the 32 bit DLL, [HookDLL_X86], there is a "REGDB_E_CLASSNOTREG" exception while trying to instantiate the inproc server SocketClient. I tried doing regasm explicitly, and it succeeds, but this error still persists. I made sure that there are separate 64 and 32 bit versions of all 3 components, ProcessMonitorLib, HookDLL and SocketCommunicationLibrary and they refer to the correct bit versions. The code I use is below. The Guids seem to match too. So I cant figure out what is wrong. Please help. It obviously works fine on the development machine.

[
ComVisible(true),
Guid("92CDE606-8FC2-43D1-A8D4-87BC438AA03F"),
InterfaceType(ComInterfaceType.InterfaceIsDual)
]
public interface ISocketClient {}

[
ComVisible(true),
Guid("730E9E8E-449D-4902-A8CB-E29035642375"),
ProgId("BizBrainAgent.SocketCommunicationLibrary.SocketClient"),
ClassInterface(ClassInterfaceType.AutoDispatch),
]
public class SocketClient:ISocketClient {}




#import "..\\..\\DLLs\\SocketCommunicationLibraryX86\\bin\Debug\\SocketCommunicationLibraryX86.tlb"
using namespace SocketCommunicationLibraryX86;
using namespace std;
void LaunchCacheLoaderAppEx() {
if (FAILED(CoInitialize(NULL)))
{
cout << "Failed to Initialize COM" << endl;;
MessageBoxA(0, "Failed to Initialize COM", "Failed", MB_OK);
}
else
{
cout << "Successfully Initialized COM" << endl;
MessageBoxA(0, "Successfully Initialized COM", "Success", MB_OK);
}

CComPtr<ISocketClient>ptr;
HRESULT hr = ptr.CoCreateInstance(__uuidof(SocketClient), NULL, CLSCTX_ALL);

switch (hr) {
case REGDB_E_CLASSNOTREG:
MessageBoxA(0, "REGDB_E_CLASSNOTREG", "Failed", MB_OK);
break;
case CLASS_E_NOAGGREGATION:
MessageBoxA(0, "REGDB_E_NOAGGREGATION", "Failed", MB_OK);
break;
case CO_E_CLASSSTRING:
MessageBoxA(0, "REGDB_E_CLASSSTRING", "Failed", MB_OK);
break;
case E_NOINTERFACE:
MessageBoxA(0, "NOINTERFACE", "Failed", MB_OK);
break;
}
const char * isNull = (ptr == NULL) ? "IS NULL" : "CREATED INSTANCE";
cout << isNull<<endl;
MessageBoxA(0, isNull, "Check", MB_OK);
CoUninitialize();

}

int main(int argc, char* argv[])
{
LaunchCacheLoaderAppEx();
return 0;

}



//socketcommunicationlibraryx86.tlh

struct __declspec(uuid("92cde606-8fc2-43d1-a8d4-87bc438aa03f"))
ISocketClient : IDispatch
{}

struct __declspec(uuid("730e9e8e-449d-4902-a8cb-e29035642375"))
SocketClient;


Type Library

[
uuid(BF95375F-51D2-4E69-9581-224A2954D838),
version(1.0),
helpstring("MyTallyApp Agent Socket Communication Library"),
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, "SocketCommunicationLibraryX86, Version=1.0.0.1, Culture=neutral, PublicKeyToken=ddd12b78ed5ab5f6")

]
library SocketCommunicationLibraryX86
{
// TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

// Forward declare all types defined in this typelib
interface ISocketClient;
interface ISocketEvents;
interface ISocketCommand;
interface _SocketClient;
interface _SocketCommand;
interface _SocketServer;

[
odl,
uuid(92CDE606-8FC2-43D1-A8D4-87BC438AA03F),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.ISocketClient")

]
interface ISocketClient : IDispatch {
[id(0x60020000)]
HRESULT Connect(
[in] BSTR host,
[in] long port,
[out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020001),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "Connect")]
HRESULT Connect_2(
[in] BSTR host,
[in] long port,
[in] ISocketEvents* listener,
[out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020002)]
HRESULT RegisterListener([in] ISocketEvents* listener);
[id(0x60020003)]
HRESULT UnregisterListener([in] ISocketEvents* listner);
[id(0x60020004)]
HRESULT Disconnect();
[id(0x60020005)]
HRESULT Listen();
[id(0x60020006)]
HRESULT SendMessage([in] BSTR message);
[id(0x60020007),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SendMessage")]
HRESULT SendMessage_2([in] ISocketCommand* cmd);
[id(0x60020008)]
HRESULT ReceiveMessage([out, retval] BSTR* pRetVal);
};

[
odl,
uuid(6BE4961F-BB53-47D6-AED2-57DD6242D743),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.ISocketEvents")

]
interface ISocketEvents : IDispatch {
[id(0x60020000)]
HRESULT MessageReceived([in] BSTR message);
[id(0x60020001)]
HRESULT OnConnect();
[id(0x60020002)]
HRESULT OnDisconnect();
};

[
uuid(730E9E8E-449D-4902-A8CB-E29035642375),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.SocketClient")
]
coclass SocketClient {
[default] interface _SocketClient;
interface _Object;
interface ISocketClient;
};

[
odl,
uuid(63A32FB5-2208-4D64-B03C-93EBD14FDF7D),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.ISocketCommand")

]
interface ISocketCommand : IDispatch {
[id(0x60020000), propget]
HRESULT Command([out, retval] BSTR* pRetVal);
[id(0x60020000), propput]
HRESULT Command([in] BSTR pRetVal);
[id(0x60020002), propget]
HRESULT Parameters([out, retval] SAFEARRAY(BSTR)* pRetVal);
[id(0x60020002), propput]
HRESULT Parameters([in] SAFEARRAY(BSTR) pRetVal);
};

[
uuid(55E459DE-6DFE-4FC7-8711-EAF24F0281D5),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.SocketCommand")
]
coclass SocketCommand {
[default] interface _SocketCommand;
interface _Object;
interface ISocketCommand;
};

[
uuid(02DEC5EB-82E4-31C9-B1B0-87B0FA958BD8),
version(1.0),
noncreatable,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.SocketServer")
]
coclass SocketServer {
[default] interface _SocketServer;
interface _Object;
};

[
odl,
uuid(E7627D53-1E6E-3F54-9DA5-31C93D9B94B7),
hidden,
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.SocketClient")

]
interface _SocketClient : IDispatch {
};

[
odl,
uuid(2B1FFF79-1BD5-3C04-A992-05AF43C5A40A),
hidden,
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.SocketCommand")

]
interface _SocketCommand : IDispatch {
};

[
odl,
uuid(A3EA7198-AE0E-375D-8AC0-71F2899A0918),
hidden,
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "SocketCommunicationLibrary.SocketServer")

]
interface _SocketServer : IDispatch {
};
};

Continue reading...
 
Back
Top