TYPE_E_CANTLOADLIBRARY when using a COM object on a separate thread on Windows 2003 x64 only
I have a Windows Forms app (compiled as x86) accessing a COM object. It gives me the following error, only on Windows 2003 x64, when the code is run on a separate thread:
Exception during creation of IDoc:Unable to cast COM object of type 'PTISG.COM.TeklogixQueue.QueueClass' to interface type 'PTISG.COM.TeklogixQueue._Queue'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3CBD7297-27D8-11D6-B75D-00902761DFA4}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))
And the code looks like this:
Private Sub Button3_Click(...)
If _separateThreadCheckBox.Checked Then
Dim t As Thread
t = New Thread(AddressOf Me.CreateQueue)
t.Start()
Else
Me.CreateQueue()
End If
End Sub
And CreateQueue() looks something like this:
Dim q As New TeklogixQueue.Queue q.Object = .... 'Has to use the object
I've tried the same code on different OS and here's the result:
- Windows 7 x64. Works.
- Windows 2008 x64. Works.
- Windows 2003 R2 Server Standard x64. Fails.
If I don't execute the code on a separate thread, then it works on all platforms.
I've used ProcessMonitor to capture the registry reads for that interface id, and here's one difference between Windows 2003 vs. Windows 7:
Windows 2003:
"1:09:13.2616131 PM","IDocSend.exe","2704","RegOpenKey","HKCU\Software\Classes\Wow6432Node\Interface{3CBD7297-27D8-11D6-B75D-00902761DFA4}","NAME NOT FOUND",""
"1:09:13.2616360 PM","IDocSend.exe","2704","RegOpenKey","HKCR\Wow6432Node\Interface{3CBD7297-27D8-11D6-B75D-00902761DFA4}","SUCCESS",""
"1:09:13.2617100 PM","IDocSend.exe","2704","RegQueryKey","HKCR\Wow6432Node\Interface{3CBD7297-27D8-11D6-B75D-00902761DFA4}","SUCCESS","Query: Name"
Windows 7:
"1:10:01.6212010 PM","IDocSend.exe","4548","RegOpenKey","HKCU\Software\Classes\Wow6432Node\Interface{3CBD7297-27D8-11D6-B75D-00902761DFA4}","NAME NOT FOUND","Desired Access: Read","32-bit"
"1:10:01.6212518 PM","IDocSend.exe","4548","RegOpenKey","HKCR\Wow6432Node\Interface{3CBD7297-27D8-11D6-B75D-00902761DFA4}","SUCCESS","Desired Access: Read","32-bit"
"1:10:01.6212927 PM","IDocSend.exe","4548","RegSetInfoKey","HKCR\Wow6432Node\Interface{3CBD7297-27D8-11D6-B75D-00902761DFA4}","SUCCESS","KeySetInformationClass: KeySetHandleTagsInformation, Length: 0","32-bit"
"1:10:01.6213324 PM","IDocSend.exe","4548","RegQueryKey","HKCR\Wow6432Node\Interface{3CBD开发者_开发知识库7297-27D8-11D6-B75D-00902761DFA4}","SUCCESS","Query: Name","32-bit"
Note on Windows 7, there's an extra "RegSetInfoKey" call.
Also, if I don't run on a separate thread, there's nothing captured in ProcessMonitor. Dunno why.
Anyone has an idea why this fails on a separate thread?
Thanks, Harold
精彩评论