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
- Due is not running and the first code-line fails with
HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)
. That's fine and happens in the 32bit version as well.
- Due is running and in the first code-line
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).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…