So I have a Visual C++ application, in my code I use the CoCreateInstance function which is used to create a COM object and get an interface from the object:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx
This function:
hr = CoCreateInstance(CLSID_CppCmnBL, NULL, CLSCTX_INPROC_SERVER,
IID_ICppCmnBL, reinterpret_cast<void**>(&m_pBL));
Works fine on a 32 bit version of windows but fails on a 64 bit version of windows.
I've looked everywhre, it seems there are issues registering 32 bit objects on a 64 bit system.
Related issues:
http://forums.codeguru.com/showthread.php?400956-32-bit-app-CoCreateInstance-fails-on-64-bit
The exception I get is: System.AccessViolationException
Please do this:
I assumed you had one .exe (the one calling CoCreateInstance()), and one .dll (the Com/ActiveX object you're trying to instantiate). Is this correct?
dumpbin /all
on your binaries and post the results. Please run dumpbin on all relevant binaries; especially the COM/ActiveX class.
A Win32 .dll should like something like this:
FILE HEADER VALUES
14C machine (x86)
3 number of sections
5355B2AD time date stamp Mon Apr 21 17:07:09 2014
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2102 characteristics
Executable
32 bit word machine
DLL
OPTIONAL HEADER VALUES
10B magic # (PE32)
MSVS 6 won't work with .Net; MSVS 6 won't build C++11 code ... but it should be fine if all you're trying to do is get a legacy app working. Again, I'm assuming there's only one .exe, and one .dll in the mix.
I'm assuming the .exe can be compiled as a 32-bit Win32 .exe (not a .Net .exe), and the .dll is a Win32, COM/ActiveX class. Both should have "PE32" headers in dumpbin. Please advise if otherwise.
I'm assuming you have control over, and can rebuild and debug, ALL of the relevant source code for this app. Please advise if otherwise.
If you can't, that's probably an indicator that "something is wrong", and I'd focus your troubleshooting efforts there.
I hope that helps!
User contributions licensed under CC BY-SA 3.0