The code below executes without problems in a 32bit c#-application.
object obj = system.Runtime.InteropServices.Marshal.GetActiveObject("Due.Application");
var due = (Due.IDueApplication2)obj;
Now, I try to get the same code working in a 64bit c#-application and therefore I followed the instructions at
http://www.gfi.com/blog/32bit-object-64bit-environment/ or http://www.codeproject.com/Tips/267554/Using-bit-COM-Object-from-bit-Application
Two cases when running the 64bit application
HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)
. That's fine and happens in the 32bit version as well.obj
receives a COM-object. But then, the second code-line throws an InvalidCastException
because QueryInterface
fails with HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)
. (Obviously, this works in the 32bit version.)Q What must I do, to make the cast in the 2nd code-line to succeed?
Edit As suggested by @HansPassant, I fired up the ProcessMonitor and monitored both the 32bit and 64bit application. I observed that the 64bit application when executing GetActiveObject
(1st code-line) omitted accessing a COM-object specific dll (CreateFile, QueryBasicInformationFile, QueryNameInformationFile, ...) which in contrast the 32bit application did, even though I've added the according registry entries beforehand, i.e. AppID
, DllSurrogate
.
Edit1 I removed all the registry-entries I added and double-checked the results including the log-files of the ProcessMonitor. I didn't notice any difference - same symptoms as before.
Update In the directory of the 3rd party software I found a Due.tlb
and I tried to create a runtime-callable-wrapper as hinted in 64 to 32 bit Interop - how?.
I created an Interop.due.dll
with tlbimp.exe Due.tlb /out:Interop.due.dll
. Unfortunately, when I replaced the original 32-bit Interop.deu.dll
with the newly created platform-agnostic one my solution failed to compile (missing references).
The only thing which worked was an out-of-process solution. I implemented a 32-bit WCF-service which provides the access to the COM-objects for the 64-bit process. (Hence, I implemented the proxy myself.)
ad Update
good news
By utilizing the information in this post I was able to regenerate a platform agnostic version of the Interop.due.dll
. Even though, TlbImp.exe
warned me with warning TI3002 : Importing a type library into a platform agnostic assembly. This can cause errors if the type library is not truly platform agnostic.
bad news
The promised glue code was not provided and therefore the bridging of 64bit and 32bit did not work out. (The 32bit only version worked as before.)
User contributions licensed under CC BY-SA 3.0