Calling a function in a native DLL from a .NET compact framework app

  • Thread starter Christian Bruccoleri
  • Start date
C

Christian Bruccoleri

Hi,
I am trying to test an *elementary* interaction between an application
written in C# with V.S. .NET 2003 and a DLL written in C with eVC4.0

It seems that I can not find a way to convince the C# client to run a
function that is in the DLL. I can post the files, if needed, but they are
very simple. I am sure that the files have been uploaded correctly and the
client (SimpleCaller.exe) and the dll (TestDll.dll) are correctly uploaded
in the same folder on the pocket pc emulator. I used the _cdecl(dllexport)
declaration for my simple function that only sum two integers.
The error I get is always that it can't find the requested method.

Does anyone have a similar trivial example that works ?
Does anyone have some checks that I can do to see what's wrong ?
Do you know if this is a problem with the emulator (PPC 2003) that I am
trying to use ?

Thanks,
Christian
 
I

Ilya Tumanov [MS]

There's a bunch of reasons why it won't work:

1. Native DLL is not accessible/deployed. Make sure you have it on the
device in system folder/application folder.
2. Function name is mangled or not exported. Use dumpbin /EXPORTS
dllname.dll to make sure it is exported and the name is correct.
3. Native DLL is compiled for wrong CPU. For example, you have an ARM DLL,
but trying to run it on x86 emulator. Make sure it's not the case.

It sounds like you took care of #1 and #2, but I would recheck it anyway.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
A

Alex Feinman [MVP]

Did you forget to declare your function as extern "C" and it got mangled?
Are you deploying x86 build?
 
C

Christian Bruccoleri

I am deploying x86 build in the emulator, and I did include the extern "C"
declaration
I also checked with dumpbin that the names are not mangled.

Thanks,
Christian
 
C

Christian Bruccoleri

I did took care of all three steps. I also used dumpbin.exe to check that
the names were not mangled: they weren't.
I tried to use the CreateProcess function from the coredll.dll (a system
dll) and it works, so it must be something wrong with my dll.

Can anyone post an elementary example that has been tested to work ?

Thanks,
Christian

"Ilya Tumanov [MS]" said:
There's a bunch of reasons why it won't work:

1. Native DLL is not accessible/deployed. Make sure you have it on the
device in system folder/application folder.
2. Function name is mangled or not exported. Use dumpbin /EXPORTS
dllname.dll to make sure it is exported and the name is correct.
3. Native DLL is compiled for wrong CPU. For example, you have an ARM DLL,
but trying to run it on x86 emulator. Make sure it's not the case.

It sounds like you took care of #1 and #2, but I would recheck it anyway.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
From: "Christian Bruccoleri" <[email protected]>
Subject: Calling a function in a native DLL from a .NET compact framework app
Date: Tue, 12 Oct 2004 17:15:53 -0500
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: cbruccoleri.tamu.edu 165.91.183.142
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:63026
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi,
I am trying to test an *elementary* interaction between an application
written in C# with V.S. .NET 2003 and a DLL written in C with eVC4.0

It seems that I can not find a way to convince the C# client to run a
function that is in the DLL. I can post the files, if needed, but they are
very simple. I am sure that the files have been uploaded correctly and the
client (SimpleCaller.exe) and the dll (TestDll.dll) are correctly uploaded
in the same folder on the pocket pc emulator. I used the _cdecl(dllexport)
declaration for my simple function that only sum two integers.
The error I get is always that it can't find the requested method.

Does anyone have a similar trivial example that works ?
Does anyone have some checks that I can do to see what's wrong ?
Do you know if this is a problem with the emulator (PPC 2003) that I am
trying to use ?

Thanks,
Christian
 
I

Ilya Tumanov [MS]

How about this article?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/h
tml/unmanagedfuncs.asp

You can also try using .def files:

-------------- a.def
EXPORTS

Whatever
-------------

-------------- a.c
void Whatever(void * foo) {
// Whatever
}
---------------

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Christian Bruccoleri" <[email protected]>
References: <[email protected]>
Subject: Re: Calling a function in a native DLL from a .NET compact framework app
Date: Wed, 13 Oct 2004 16:19:37 -0500
Lines: 80
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: cbruccoleri.tamu.edu 165.91.183.142
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:63102
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

I did took care of all three steps. I also used dumpbin.exe to check that
the names were not mangled: they weren't.
I tried to use the CreateProcess function from the coredll.dll (a system
dll) and it works, so it must be something wrong with my dll.

Can anyone post an elementary example that has been tested to work ?

Thanks,
Christian

"Ilya Tumanov [MS]" said:
There's a bunch of reasons why it won't work:

1. Native DLL is not accessible/deployed. Make sure you have it on the
device in system folder/application folder.
2. Function name is mangled or not exported. Use dumpbin /EXPORTS
dllname.dll to make sure it is exported and the name is correct.
3. Native DLL is compiled for wrong CPU. For example, you have an ARM DLL,
but trying to run it on x86 emulator. Make sure it's not the case.

It sounds like you took care of #1 and #2, but I would recheck it anyway.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
From: "Christian Bruccoleri" <[email protected]>
Subject: Calling a function in a native DLL from a .NET compact
framework
app
Date: Tue, 12 Oct 2004 17:15:53 -0500
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: cbruccoleri.tamu.edu 165.91.183.142
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:63026
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi,
I am trying to test an *elementary* interaction between an application
written in C# with V.S. .NET 2003 and a DLL written in C with eVC4.0

It seems that I can not find a way to convince the C# client to run a
function that is in the DLL. I can post the files, if needed, but they are
very simple. I am sure that the files have been uploaded correctly and the
client (SimpleCaller.exe) and the dll (TestDll.dll) are correctly uploaded
in the same folder on the pocket pc emulator. I used the _cdecl(dllexport)
declaration for my simple function that only sum two integers.
The error I get is always that it can't find the requested method.

Does anyone have a similar trivial example that works ?
Does anyone have some checks that I can do to see what's wrong ?
Do you know if this is a problem with the emulator (PPC 2003) that I am
trying to use ?

Thanks,
Christian
 
A

Alex Feinman [MVP]

I belive the issue is resolved by now.

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Ilya Tumanov [MS]" said:
How about this article?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/h
tml/unmanagedfuncs.asp

You can also try using .def files:

-------------- a.def
EXPORTS

Whatever
-------------

-------------- a.c
void Whatever(void * foo) {
// Whatever
}
---------------

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
From: "Christian Bruccoleri" <[email protected]>
References: <[email protected]>
Subject: Re: Calling a function in a native DLL from a .NET compact framework app
Date: Wed, 13 Oct 2004 16:19:37 -0500
Lines: 80
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: cbruccoleri.tamu.edu 165.91.183.142
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:63102
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

I did took care of all three steps. I also used dumpbin.exe to check that
the names were not mangled: they weren't.
I tried to use the CreateProcess function from the coredll.dll (a system
dll) and it works, so it must be something wrong with my dll.

Can anyone post an elementary example that has been tested to work ?

Thanks,
Christian

"Ilya Tumanov [MS]" said:
There's a bunch of reasons why it won't work:

1. Native DLL is not accessible/deployed. Make sure you have it on the
device in system folder/application folder.
2. Function name is mangled or not exported. Use dumpbin /EXPORTS
dllname.dll to make sure it is exported and the name is correct.
3. Native DLL is compiled for wrong CPU. For example, you have an ARM DLL,
but trying to run it on x86 emulator. Make sure it's not the case.

It sounds like you took care of #1 and #2, but I would recheck it anyway.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
From: "Christian Bruccoleri" <[email protected]>
Subject: Calling a function in a native DLL from a .NET compact framework
app
Date: Tue, 12 Oct 2004 17:15:53 -0500
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: cbruccoleri.tamu.edu 165.91.183.142
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:63026
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi,
I am trying to test an *elementary* interaction between an application
written in C# with V.S. .NET 2003 and a DLL written in C with eVC4.0

It seems that I can not find a way to convince the C# client to run a
function that is in the DLL. I can post the files, if needed, but they
are
very simple. I am sure that the files have been uploaded correctly and
the
client (SimpleCaller.exe) and the dll (TestDll.dll) are correctly
uploaded
in the same folder on the pocket pc emulator. I used the
_cdecl(dllexport)
declaration for my simple function that only sum two integers.
The error I get is always that it can't find the requested method.

Does anyone have a similar trivial example that works ?
Does anyone have some checks that I can do to see what's wrong ?
Do you know if this is a problem with the emulator (PPC 2003) that I
am
trying to use ?

Thanks,
Christian
 
C

Christian Bruccoleri

Yes, I resolved the problem thanks to your help:
It was a silly, and subtle, mistake:

#ifdef _cplusplus <-- only one underscore here, should be two !
extern "C" {
#endif

Plus the fact that I was rebuilding the DLL with eVC and even if the file on
the disk was updated, VS .NET consistently uploaded the old version of the
dll in the emulator. In order to avoid this I must manually remove the dll
from the .NET project and add it again, (after it is modified). Quite
annoying.

Christian


Alex Feinman said:
I belive the issue is resolved by now.

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Ilya Tumanov [MS]" said:
 
C

Chris Tacke, eMVP

#ifdef _cplusplus <-- only one underscore here, should be two !
extern "C" {
#endif

A good reason to remove the #ifdef. If it's a .cpp file, then it's defined.
Plus the fact that I was rebuilding the DLL with eVC and even if the file on
the disk was updated, VS .NET consistently uploaded the old version of the
dll in the emulator. In order to avoid this I must manually remove the dll
from the .NET project and add it again, (after it is modified). Quite
annoying.

Change the eVC project settings to output the binary right into the managed
project directory so it's updated with every compile.

-Chris
 
C

Christian Bruccoleri

Chris Tacke said:
A good reason to remove the #ifdef. If it's a .cpp file, then it's
defined.

That's right.
Change the eVC project settings to output the binary right into the
managed
project directory so it's updated with every compile.
Yes, I did that. However it seems that the old version is still updated, or
the emulator is responsible. I don't know. It's just that even after
changing the content of a function in the dll I keep seeing the old-behavior
until I delete the reference to the project and re-add it again.

Christian
 

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