Desparate - ASAP - P/Invoke probs

  • Thread starter Thread starter Programmer
  • Start date Start date
P

Programmer

Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Pocket OS does not have the concept of current directory...

try this..

[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..

[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Make sure your exported functions are declared with
extern "C"
othewrwise you will get C++ mangled names
Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
2 things that have bitten me -- and note, I'm not a C++ programmer so a lot
this is completely new to me:

1. Make sure you're compiling for the right processor ... emulator/device.
2. Put an extern "C" on the method declaration ... something like
#define MYSTUFF_API extern "C" __declspec(dllexport)

Can't be more help as I don't know C++....

Good luck,
Brian



Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..

[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and
try to p/invoke a function in the DLL. I always get
System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows
folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Run dumpbin.exe on the DLL and see what it's actually exporting.

http://msdn.microsoft.com/library/d.../en-us/dnnetcomp/html/netcfdumpbinpinvoke.asp

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
I wasn't even thinking about the problem being on the dll sid... look at this
#ifdef DLL_IMPORT_EXPORT
#undef DLL_IMPORT_EXPORT
#endif

#ifdef DLL_SOURCE_CODE
#define DLL_IMPORT_EXPORT __declspec(dllexport) __stdcall
#else
#define DLL_IMPORT_EXPORT __declspec(dllimport) __stdcall
#endif

#ifdef __cplusplus
#define NoMangle extern "C"
#else
#define NoMangle
#endif

#undef MY_API
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
///////////////////////
NoMangle __declspec (dllexport) long __stdcall keyfobGetData();



Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..

[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Still no go:

Here's the latest C code I have:

extern "C" __declspec (dllexport) int __stdcall PlainFunction()
{
return 123;
}

Here's the latest .NET CF code:

[System.Runtime.InteropServices.DllImport(@"\Program Files\PcketMeds\MyStuff.dll")]
public static extern int PlainFunction();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = PlainFunction();
MessageBox.Show(DLLReturned.ToString());
}

I also tried 2 other variations on .NET types for the function return type: I tried System.Int16 and System.Int32 (on both the "public static..." line and on the "int DLLReturned..." line.)

I'm still stuck! :(

Does anybody have a working example of an embedded VC++ 3.0 DLL and a ..NET CF app that successfully calls it?

Thanks,
Desperate!
I wasn't even thinking about the problem being on the dll sid... look at this
#ifdef DLL_IMPORT_EXPORT
#undef DLL_IMPORT_EXPORT
#endif

#ifdef DLL_SOURCE_CODE
#define DLL_IMPORT_EXPORT __declspec(dllexport) __stdcall
#else
#define DLL_IMPORT_EXPORT __declspec(dllimport) __stdcall
#endif

#ifdef __cplusplus
#define NoMangle extern "C"
#else
#define NoMangle
#endif

#undef MY_API
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
///////////////////////
NoMangle __declspec (dllexport) long __stdcall keyfobGetData();



Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..

[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Thanks. I hadn't had the extern "C". I tried that and still no go :(

Oh! And I'm compiling for the ARM processor.
 
I always just put my DLLs in a good location, like the \Windows directory.
Maybe you should put it there and remove the path from your DllImport
entirely. You don't need the __stdcall attribute on your function, either.
You might also use the depends.exe viewer on your DLL to make sure that the
function name is what you're expecting. Depends.exe comes with eVC.

Paul T.

Still no go:

Here's the latest C code I have:

extern "C" __declspec (dllexport) int __stdcall PlainFunction()
{
return 123;
}

Here's the latest .NET CF code:

[System.Runtime.InteropServices.DllImport(@"\Program
Files\PcketMeds\MyStuff.dll")]
public static extern int PlainFunction();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = PlainFunction();
MessageBox.Show(DLLReturned.ToString());
}

I also tried 2 other variations on .NET types for the function return type:
I tried System.Int16 and System.Int32 (on both the "public static..." line
and on the "int DLLReturned..." line.)

I'm still stuck! :(

Does anybody have a working example of an embedded VC++ 3.0 DLL and a .NET
CF app that successfully calls it?

Thanks,
Desperate!
I wasn't even thinking about the problem being on the dll sid... look at
this
#ifdef DLL_IMPORT_EXPORT
#undef DLL_IMPORT_EXPORT
#endif

#ifdef DLL_SOURCE_CODE
#define DLL_IMPORT_EXPORT __declspec(dllexport) __stdcall
#else
#define DLL_IMPORT_EXPORT __declspec(dllimport) __stdcall
#endif

#ifdef __cplusplus
#define NoMangle extern "C"
#else
#define NoMangle
#endif

#undef MY_API
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
///////////////////////
NoMangle __declspec (dllexport) long __stdcall keyfobGetData();



Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..


[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF
app and try to p/invoke a function in the DLL. I always get
System.MissingMethodException.

I've copied the DLL to both my application's folder and in the
\windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs
e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Thanks. Did that... still no go :(
Make sure your exported functions are declared with
extern "C"
othewrwise you will get C++ mangled names
Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
"PlainFunction" is now the function I'm testing with... It's declared like this:

extern "C" __declspec (dllexport) int __stdcall PlainFunction()
{
return 123;
}

and in .NET, I use it like this:

[System.Runtime.InteropServices.DllImport(@"\Program Files\MyStuff\MyStuff.dll")]
public static extern int PlainFunction();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = PlainFunction();
MessageBox.Show(DLLReturned.ToString());
}

DumpBin.EXE displays the following for exports...


Microsoft (R) COFF/PE Dumper Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file MyStuff.dll

File Type: DLL

Section contains the following exports for MyStuff.dll

00000000 characteristics
3FE35DE5 time date stamp Fri Dec 19 15:21:57 2003
0.00 version
1 ordinal base
6 number of functions
6 number of names

ordinal hint RVA name

[deleted irrellevent stuff...]
6 5 00001024 PlainFunction

Summary

1000 .data
1000 .edata
1000 .pdata
1000 .rdata
1000 .reloc
1000 .text

Run dumpbin.exe on the DLL and see what it's actually exporting.

http://msdn.microsoft.com/library/d.../en-us/dnnetcomp/html/netcfdumpbinpinvoke.asp

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
HOORAY! I removed the __stdcall (didn't change anything), but putting it in
the Windows folder and removing the hard coded path worked (though I did
that 50% of the time for the 1st 100 tries... argh!). Anyway, it's now
working!

Thanks to everyone!

Paul G. Tobey said:
I always just put my DLLs in a good location, like the \Windows directory.
Maybe you should put it there and remove the path from your DllImport
entirely. You don't need the __stdcall attribute on your function, either.
You might also use the depends.exe viewer on your DLL to make sure that the
function name is what you're expecting. Depends.exe comes with eVC.

Paul T.

Still no go:

Here's the latest C code I have:

extern "C" __declspec (dllexport) int __stdcall PlainFunction()
{
return 123;
}

Here's the latest .NET CF code:

[System.Runtime.InteropServices.DllImport(@"\Program
Files\PcketMeds\MyStuff.dll")]
public static extern int PlainFunction();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = PlainFunction();
MessageBox.Show(DLLReturned.ToString());
}

I also tried 2 other variations on .NET types for the function return type:
I tried System.Int16 and System.Int32 (on both the "public static..." line
and on the "int DLLReturned..." line.)

I'm still stuck! :(

Does anybody have a working example of an embedded VC++ 3.0 DLL and a .NET
CF app that successfully calls it?

Thanks,
Desperate!
I wasn't even thinking about the problem being on the dll sid... look at
this
#ifdef DLL_IMPORT_EXPORT
#undef DLL_IMPORT_EXPORT
#endif

#ifdef DLL_SOURCE_CODE
#define DLL_IMPORT_EXPORT __declspec(dllexport) __stdcall
#else
#define DLL_IMPORT_EXPORT __declspec(dllimport) __stdcall
#endif

#ifdef __cplusplus
#define NoMangle extern "C"
#else
#define NoMangle
#endif

#undef MY_API
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
///////////////////////
NoMangle __declspec (dllexport) long __stdcall keyfobGetData();



Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..


[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF
app and try to p/invoke a function in the DLL. I always get
System.MissingMethodException.

I've copied the DLL to both my application's folder and in the
\windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs
e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
It's now resolved! Thanks to everyone!
Thanks. Did that... still no go :(
Make sure your exported functions are declared with
extern "C"
othewrwise you will get C++ mangled names
Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
It's now resolved! Thanks to everyone!

Programmer said:
Thanks. I hadn't had the extern "C". I tried that and still no go :(

Oh! And I'm compiling for the ARM processor.

Brian said:
2 things that have bitten me -- and note, I'm not a C++ programmer so a lot
this is completely new to me:

1. Make sure you're compiling for the right processor ... emulator/device.
2. Put an extern "C" on the method declaration ... something like
#define MYSTUFF_API extern "C" __declspec(dllexport)

Can't be more help as I don't know C++....

Good luck,
Brian



Still didn't work. Thanks for the quick response!

Can you think of anything else?
Pocket OS does not have the concept of current directory...

try this..

[System.Runtime.InteropServices.DllImport(@"\Windows\MyStuff.dll")]
public static extern int fnMyStuff();


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and
try to p/invoke a function in the DLL. I always get
System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows
folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
It's now resolved! Thanks to everyone!
"PlainFunction" is now the function I'm testing with... It's declared like this:

extern "C" __declspec (dllexport) int __stdcall PlainFunction()
{
return 123;
}

and in .NET, I use it like this:

[System.Runtime.InteropServices.DllImport(@"\Program Files\MyStuff\MyStuff.dll")]
public static extern int PlainFunction();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = PlainFunction();
MessageBox.Show(DLLReturned.ToString());
}

DumpBin.EXE displays the following for exports...


Microsoft (R) COFF/PE Dumper Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file MyStuff.dll

File Type: DLL

Section contains the following exports for MyStuff.dll

00000000 characteristics
3FE35DE5 time date stamp Fri Dec 19 15:21:57 2003
0.00 version
1 ordinal base
6 number of functions
6 number of names

ordinal hint RVA name

[deleted irrellevent stuff...]
6 5 00001024 PlainFunction

Summary

1000 .data
1000 .edata
1000 .pdata
1000 .rdata
1000 .reloc
1000 .text

Run dumpbin.exe on the DLL and see what it's actually exporting.

http://msdn.microsoft.com/library/d.../en-us/dnnetcomp/html/netcfdumpbinpinvoke.asp

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
It's now resolved! Thanks to everyone!
Thanks. Did that... still no go :(
Make sure your exported functions are declared with
extern "C"
othewrwise you will get C++ mangled names
Major problems w/ deadline tonight! :(

I've created a DLL with the SmartPhone SDK. I've created a .NET CF app and try to p/invoke a function in the DLL. I always get System.MissingMethodException.

I've copied the DLL to both my application's folder and in the \windows folder on the PocketPC.

Here's my DLL code (actually, this is all auto-generated by the SDK)

#ifdef MYSTUFF_EXPORTS
#define MYSTUFF_API __declspec(dllexport)
#else
#define MYSTUFF_API __declspec(dllimport)
#endif

// This is an example of an exported function.
MYSTUFF_API int fnMyStuff(void)
{
return 42;
}

Here's the .NET code:

[System.Runtime.InteropServices.DllImport("MyStuff.dll")]
public static extern int fnMyStuff();

private void DLLButton_Click(object sender, System.EventArgs e)
{
int DLLReturned = fnMyStuff();
MessageBox.Show(DLLReturned.ToString());
}

The fnMyStuff() line is what triggers the exception.

Any help is greatly appreciated.. and the sooner the better! :)
 
Back
Top