P/Invoke: 'System.MissingMethodException'

G

Guest

Hi,

I am trying to P/Invoke a video coder .DLL in my C# application for Pocket Pc.
I wrote the regular P/Invoke adaptation for the methods of the .DLL.
When I debug the application, I get the exception
'System.MissingMethodException', when I call any method from this DLL.

This is my first P/Invoke, I don't know what to do in this situation... how
to debug?

I checked with DLL Viewer that those methods are "external" in the DLL, this
point is fine.

I have a doubt if the DLL is compiled for pocket pc, how can I check ?


Thank you for your support!

Lionel Reyero


my method call which generate the exception:

Encoder.MSFCEnc_Init(this.width, this.height);

my P/invoke code in C#

[DllImport("MSFCEnc.dll")] public static extern UInt32 MSFCEnc_Init(int cx,
int cy);

the method in C is :

MSFCENC_API HRESULT MSFCEnc_Init(int cx, int cy);
 
P

Paul G. Tobey [eMVP]

You're *sure* that it *is* in C, right? Not a .cpp file? C++ mangles
function names to include information on parameter types (allowing function
overloading, multiple functions with the same name, distinguished by their
parameter types). If you let that happen to your function, your declaration
in C# must include the mangling.

Paul T.
 
P

Peter Foot [MVP]

Check that:-
* You dll is present in the app folder or windows folder
* Your dll is built for the correct CPU architecture - e.g. ARM for a
PPC2003 device
* You dll exports functions with unmangled names - use Depends or a similar
tool to examine the exported functions

If your dll exports mangled function names you can still call it by adding
the EntryPoint parameter to your DllImport attribute with the exact mangled
name used e.g.
[DllImport("MSFCEnc.dll", EntryPoint="@MSFCEnc_Init£^£$%$%£$%")]

Peter
 
G

Guest

You were right Paul, and Peter. The problem was the mangling of the function
names. I could get the real one by opening the DLL in DLL Export Viewer, and
then used the EntryPoint property.

I would like to thank you for your great support!
Every time I post on this newsgroup I get the solution to my problems within
a few hours! That's great!

Regards,

Lionel Reyero
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top