|
| Invoking a native DLL export |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.compactframework.
| Casper Hornstrup |
| GOOD ANSWER |
I'm having trouble with calling an exported function in a native DLL compiled with eMbedded Visual C++ using C#.
Basicly, I have one exported function in the DLL:
#define NATIVE_API __declspec(dllexport) extern "C" { NATIVE_API int fnNative(void) { return 42; } }
and a C# client of the DLL:
using System; using System.Data; using System.Runtime.InteropServices;
namespace Client { class Class1 { [ DllImport("native.dll", EntryPoint="fnNative") ] public static extern int fnNative();
static void Main(string[] args) { Console.WriteLine("Call fnNative()"); int x = fnNative(); //int x = 7; Console.WriteLine("fnNative() = " + x); Console.ReadLine(); } } }
When run, I get "An unhandled exception of type 'System.MissingMethodException' occurred in Client.exe".
Dumpbin /exports of the DLL looks right: One export: _fnNative@0.
I have tried changing calling convention with no luck. I have successfully called an export in coredll.dll using similar C# code, so I'm possibly doing something wrong when creating the DLL?
Full project files are located here: http://ch.wox.org/Native.zip
Thanks, Casper
|
|
|
| |
|
|
| |
| |
| Mark Hurley |
| GOOD ANSWER |
Use dumpbin /exports (something like that) and see if your method is correctly being exported, it will also tell you if the exported names are being mangled.
What did you get?
Mark
"Casper Hornstrup" <Click here to reveal e-mail address> wrote in message news:eoUGeR4JCHA.2552@tkmsftngp08... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Casper Hornstrup |
| GOOD ANSWER |
Dumpbin /exports gives _fnNative@0
"Mark Hurley" <Click here to reveal e-mail address> wrote in message news:#KnnJF5JCHA.1772@tkmsftngp09... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Jorge@tutopia.com |
| GOOD ANSWER |
Casper Hornstrup <Click here to reveal e-mail address> escribió en el mensaje de noticias uDgHWx#JCHA.1900@tkmsftngp11... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| PaulYao [eMVP] |
| GOOD ANSWER |
The name of your function is fnNative@0 (note that the "@0" is, in fact, part of your fn name).
You need to do one of two things - I recommend #2, as I have never done #1 - but it might give you a quick and dirty way to do this: 1) Change your C# code:
[Original message clipped]
2) Change your DLL: 2.1 Add a new file to your DLL project named "Myapp.Def" (the Myapp part is not important, the ".def" is). 2.2 In that file, add the following lines:
EXPORTS fnNative
Check you work by running dumpbin/exports (or depends.exe) to make sure that the name is now "fnNative" and not fnNative@0.
Is this running on an actual device or on the emulator? If on an actual device, are you sure that your DLL is present on the device?? (For that matter, is it present on the emulator - the last time I tried the eVC++ emulator was different - that is it was a different process - from the one started up by my .NETcf dev tools.)
My Best, Paul
-- Paul Yao The Paul Yao Company http://www.paulyao.com
Power Programming Workshops eCoaching for Programmers Microsoft eMVP
"Click here to reveal e-mail address" <Click here to reveal e-mail address> wrote in message news:#hoZk3kbCHA.1940@tkmsftngp11... [Original message clipped]
|
|
|
| |
|
|
| |
|
|
| |
| Jorge@tutopia.com |
| GOOD ANSWER |
Casper Hornstrup <Click here to reveal e-mail address> escribió en el mensaje de noticias uDgHWx#JCHA.1900@tkmsftngp11... [Original message clipped]
|
|
|
| |
|
|
| |
|
| |
| Jorge@tutopia.com |
| GOOD ANSWER |
Casper Hornstrup <Click here to reveal e-mail address> escribió en el mensaje de noticias uDgHWx#JCHA.1900@tkmsftngp11... [Original message clipped]
|
|
|
| |
|
|
| |
|
|
|
| |
| Mark Hurley |
| GOOD ANSWER |
Use dumpbin /exports (something like that) and see if your method is correctly being exported, it will also tell you if the exported names are being mangled.
What did you get?
Mark
"Casper Hornstrup" <Click here to reveal e-mail address> wrote in message news:eoUGeR4JCHA.2552@tkmsftngp08... [Original message clipped]
|
|
|
| |
|
|
| |
|
| |
| Baccarin |
| GOOD ANSWER |
Casper,
Did you include a .def file in your eVC++ dll with your function name?
Baccarin.
"Casper Hornstrup" <Click here to reveal e-mail address> escreveu na mensagem news:eoUGeR4JCHA.2552@tkmsftngp08... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Casper Hornstrup |
| GOOD ANSWER |
If eVC is anything like Visual C++ this should not be necesarry when using dllexport (and according to dumpbin it is exported). Does anyone use .def files?
I tried creating an executable that will link to native.dll in eVC. It runs fine in the Pocket PC emulator that comes with eVT 3.0, but in the Pocket PC emulator that comes with .NET Compact Framework it will not run (complains about the application performing an illegal operation). Exception: 0xc0000005 @ address 00000000.
Casper
"Baccarin" <Click here to reveal e-mail address> wrote in message news:u1kFxMIKCHA.668@tkmsftngp09... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Mark Hurley |
| GOOD ANSWER |
Correct....in my eVC dll's I dropped the .def file all together in favor of the __declspec(dllexport)... here is a sample method ... which works:
extern "C" int __declspec(dllexport) myIsScanSuspended(void) { return IsScanSuspended(); }
Casper -- just for trial and error....have you tried dropping the entry point?
[Original message clipped]
I wonder if some sort of "bug" could be messing it up? All of my pInvoked functions do not use the entry point, so I'm not sure if that is proven on the "compact framework" to function correctly. You don't need it, as your keeping your method name consistent. But you probably already knew that. ;)
Mark
"Casper Hornstrup" <Click here to reveal e-mail address> wrote in message news:uWIW0sLKCHA.2060@tkmsftngp11... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Casper Hornstrup |
| GOOD ANSWER |
"Mark Hurley" <Click here to reveal e-mail address> wrote in message news:#n$MxQbKCHA.2324@tkmsftngp13... > Correct....in my eVC dll's I dropped the .def file all together in favor of [Original message clipped]
Tried that with your example, same results. Do you have a simple example with project files I could try (that works for you)? Maybe I'm missing some configuration option somewhere.
Thanks, Casper
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|