Groups | Blog | Home
all groups > dotnet interop > january 2005 >

dotnet interop : QueryInterface does not work for services, works for other applications.



sdaman29 NO[at]SPAM gmail.com
1/30/2005 5:01:49 AM
hello,
I've got a problem that can be more or less reliably reproduced.
I've got a com object described in a c++ written com library. There's
also an interop for this library. the object has two interfaces. as
long as use the default interface, everything works fine, but when I
cast to the other interface and try to execute methods on it, it
throws the error "QueryInterface failed for interface..."

example:

1 Strong.Name.InterfaceName i_variable = new
Strong.Name.InterfaceNameClass();
2 Strong.Name.AnotherInterfaceName i_anotherVariable =
(Strong.Name.AnotherInterfaceName)i_variable;
3 i_anotherVariable.someFunction();

The error happens either in line 2 or 3. On the same machine it works
just fine for a normal (windows forms desktop) application in C# but
fails in a windows service written also in C#. Declaring the function
where the code is or the portion of the code as STA does not help.
Does anybody know a cure?
Thank You
Daniel Petersson, Cefalo
1/30/2005 10:11:02 PM
hi,

The STAThread attribute only applies to the main entry point
of the application, to set the apartmentmodel later use
set the Thread.ApartmentState property in your code.
// Daniel


[quoted text, click to view]
AddThis Social Bookmark Button