Problem in calling native DLL functions in C# in PocketPC 2002 environment

P

Pawan Aggarwal

I'm having trouble with calling an exported function in a
native DLL compiled with eMbedded Visual C++ in C#
application in PocketPC 2002 OS.

Problem Description follows:
I have one exported function in the DLL:
I am making an application for pocket Pc in C# using this
DLL Function.
whenever I execute this exe in Pocket pc it returns
MissingMethod Exception.

Following is the listing of NativeFunctions.h,
NativeFunctions.cpp , NativeApp.cs files


Code listing for DLL is follows:

/***********************/
NativeFunctions.h
********************/
#ifdef NATIVEDLL_EXPORTS
#define DLLEXPORT _declspec(dllexport)
#else
#define DLLEXPORT _declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
DLLEXPORT int function();
#ifdef __cplusplus
}//end extern "C"
#endif

/******************
NativeFunction.cpp
*******************/
#include "stdafx.h"
#include "NativeFunctions.h"
int function()
{
return 25;
}

******************/
C# client of the DLL follows:
/*********************************
NativeApp.cs
*****************/
using System;
using System.Data;
using System.Runtime.InteropServices;

namespace Client
{
class Class1
{
[ DllImport("NativeFunctions.dll", EntryPoint="function") ]
public static extern int function();

static void Main(string[] args)
{
int x = function();
MessageBox.Show(x.toString());
}
}
}
/*****************************************/
 
L

Lewis Wang [MSFT]

Hi Pawan,

You can check this link. I think it will be helpful:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=2
bd0ecc8165653eb&seekm=012301c2c6ec%241db18570%24d2f82ecf%40TK2MSFTNGXA09#lin
k9

Hope this helps.

Best Regards,
Lewis

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Content-Class: urn:content-classes:message
| From: "Pawan Aggarwal" <[email protected]>
| Sender: "Pawan Aggarwal" <[email protected]>
| Subject: Problem in calling native DLL functions in C# in PocketPC 2002
environment
| Date: Tue, 29 Jul 2003 23:54:33 -0700
| Lines: 67
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNWZ254EDkHdhHWSym4QfvVt2sAMg==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:172886
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I'm having trouble with calling an exported function in a
| native DLL compiled with eMbedded Visual C++ in C#
| application in PocketPC 2002 OS.
|
| Problem Description follows:
| I have one exported function in the DLL:
| I am making an application for pocket Pc in C# using this
| DLL Function.
| whenever I execute this exe in Pocket pc it returns
| MissingMethod Exception.
|
| Following is the listing of NativeFunctions.h,
| NativeFunctions.cpp , NativeApp.cs files
|
|
| Code listing for DLL is follows:
|
| /***********************/
| NativeFunctions.h
| ********************/
| #ifdef NATIVEDLL_EXPORTS
| #define DLLEXPORT _declspec(dllexport)
| #else
| #define DLLEXPORT _declspec(dllimport)
| #endif
| #ifdef __cplusplus
| extern "C" {
| #endif
| DLLEXPORT int function();
| #ifdef __cplusplus
| }//end extern "C"
| #endif
|
| /******************
| NativeFunction.cpp
| *******************/
| #include "stdafx.h"
| #include "NativeFunctions.h"
| int function()
| {
| return 25;
| }
|
| ******************/
| C# client of the DLL follows:
| /*********************************
| NativeApp.cs
| *****************/
| using System;
| using System.Data;
| using System.Runtime.InteropServices;
|
| namespace Client
| {
| class Class1
| {
| [ DllImport("NativeFunctions.dll", EntryPoint="function") ]
| public static extern int function();
|
| static void Main(string[] args)
| {
| int x = function();
| MessageBox.Show(x.toString());
| }
| }
| }
| /*****************************************/
|
 

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