PC Review


Reply
Thread Tools Rate Thread

CoCreateInstance and P/Invoke

 
 
igd
Guest
Posts: n/a
 
      22nd Jan 2007
Hello!

I would like to code a wrapper for the C/C++-ASIO API. In one of the
functions exported by an unmanaged ASIO driver DLL (loadAsioDriver)
CoCreateInstance is called. When I call loadAsioDriver() from an
unmanaged client, it works but when I call that function from managed
code (P/Invoke) CoCreateInstance in loadAsioDriver() returns
E_NOINTERFACE. How can I fix this?

Thanks in advance!

 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      22nd Jan 2007
"igd" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello!
>
> I would like to code a wrapper for the C/C++-ASIO API. In one of the
> functions exported by an unmanaged ASIO driver DLL (loadAsioDriver)
> CoCreateInstance is called. When I call loadAsioDriver() from an
> unmanaged client, it works but when I call that function from managed
> code (P/Invoke) CoCreateInstance in loadAsioDriver() returns
> E_NOINTERFACE. How can I fix this?
>
> Thanks in advance!
>


This is not a C# issue, even not a .NET issue. What happens if you call this function from a
native client (say C++)?

Willy.



 
Reply With Quote
 
igd
Guest
Posts: n/a
 
      22nd Jan 2007
As I wrote in my last post ("When I call loadAsioDriver() from an
unmanaged client, it works but when I call that function from managed
code (P/Invoke) CoCreateInstance in loadAsioDriver() returns
E_NOINTERFACE") it works. The >same< DLL called from native c++ works
how it should be. That's why I think it is a .NET issue. Any idea?

Willy Denoyette [MVP] schrieb:

> This is not a C# issue, even not a .NET issue. What happens if you call this function from a
> native client (say C++)?
>
> Willy.


 
Reply With Quote
 
igd
Guest
Posts: n/a
 
      22nd Jan 2007
I have found out how it works. The Main()-Method must be decorated with
[STAThread()].

igd schrieb:

> As I wrote in my last post ("When I call loadAsioDriver() from an
> unmanaged client, it works but when I call that function from managed
> code (P/Invoke) CoCreateInstance in loadAsioDriver() returns
> E_NOINTERFACE") it works. The >same< DLL called from native c++ works
> how it should be. That's why I think it is a .NET issue. Any idea?
>
> Willy Denoyette [MVP] schrieb:
>
> > This is not a C# issue, even not a .NET issue. What happens if you call this function from a
> > native client (say C++)?
> >
> > Willy.


 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      22nd Jan 2007
"igd" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> As I wrote in my last post ("When I call loadAsioDriver() from an
> unmanaged client, it works but when I call that function from managed
> code (P/Invoke) CoCreateInstance in loadAsioDriver() returns
> E_NOINTERFACE") it works. The >same< DLL called from native c++ works
> how it should be. That's why I think it is a .NET issue. Any idea?
>


True, but It's not your C# code who calls CoCreateInstance which means it's not a .NET
issue. It's quite impossible to help you with this without seeing any code, especially what
arguments are you passing to the loadAsioDriver() function?

Willy.



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      22nd Jan 2007
"igd" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have found out how it works. The Main()-Method must be decorated with
> [STAThread()].
>


That means that the native code does not initialize COM (call CoInitialize()), but instead
relies on the caller to have done this before calling into the unmanaged dll, this is not
the correct behavior the native caller is the COM client, so he should initialize COM.
This aside, did you check the COM apartment requirements of the COM server? are you sure it
needs a STA to run in? Maybe it's a 'free' or 'both' threaded COM server which means you
better apply the [MTAThread] attribute.


Willy.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CoCreateInstance to IStoreNamespace rakesh Windows Vista Mail 0 1st Oct 2008 12:49 PM
CoCreateInstance in XP =?Utf-8?B?QXNoYQ==?= Windows XP General 1 19th Mar 2004 07:15 AM
CoCreateInstance Equiv in VB.NET ChrisWoodruff Microsoft VB .NET 2 24th Sep 2003 10:07 AM
Re: COM CoCreateInstance Roy Fine Microsoft VC .NET 0 21st Aug 2003 02:21 PM
CoCreateInstance COM Duncan Winn Microsoft VC .NET 0 21st Aug 2003 01:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:53 PM.