again a "can't find PInvoke DLL" problem

R

raludamian

Hello!

I'm trying to develop a GIS mapping software on smart devices using VS
2005, C#. need to use a library that was written in C++. Being open
source I compiled the C++ code VS 2005 --> C++ --> Smart Devices and I
obtained a DLL. Now I need to access the DLL functions (unmanaged
code) from my C# (managed code) application. Unfortunatelly I got a
"Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}

and just use it in C# to se if it works:

[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();

But again I got the same error.... I really don't understand!

I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll

00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluca
 
G

Guest

I'm not a guru in interop, but have you tried placing the native dll in the
Windows folder?

Simon.
 
R

raludamian

Hello!
Thank you for the reply!

Yes, I have.... But now a question: does it matter if it is in the C:
\windows folder if all the data is deployed onto the emulator?
Shouldn't I put it in another folder? I tried copying it on C:\Program
Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework
\2.0\v1.0\WindowsCE\ but still it doesn't work...

Raluca

Simon Hart a scris:
I'm not a guru in interop, but have you tried placing the native dll in the
Windows folder?

Simon.

Hello!

I'm trying to develop a GIS mapping software on smart devices using VS
2005, C#. need to use a library that was written in C++. Being open
source I compiled the C++ code VS 2005 --> C++ --> Smart Devices and I
obtained a DLL. Now I need to access the DLL functions (unmanaged
code) from my C# (managed code) application. Unfortunatelly I got a
"Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}

and just use it in C# to se if it works:

[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();

But again I got the same error.... I really don't understand!

I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll

00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluca
 
G

Guest

Sorry I am getting a bit confused by your questions. You need to deploy it to
the device, not your local C: drive. Is this what you are doing?

Simon.

Hello!
Thank you for the reply!

Yes, I have.... But now a question: does it matter if it is in the C:
\windows folder if all the data is deployed onto the emulator?
Shouldn't I put it in another folder? I tried copying it on C:\Program
Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework
\2.0\v1.0\WindowsCE\ but still it doesn't work...

Raluca

Simon Hart a scris:
I'm not a guru in interop, but have you tried placing the native dll in the
Windows folder?

Simon.

Hello!

I'm trying to develop a GIS mapping software on smart devices using VS
2005, C#. need to use a library that was written in C++. Being open
source I compiled the C++ code VS 2005 --> C++ --> Smart Devices and I
obtained a DLL. Now I need to access the DLL functions (unmanaged
code) from my C# (managed code) application. Unfortunatelly I got a
"Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}

and just use it in C# to se if it works:

[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();

But again I got the same error.... I really don't understand!

I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll

00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluca
 
G

Guest

If the DLL is tryuly in teh same folder as your app on the target device
then really the only other thing that could cause this is that you built it
for the wrong processor or the wrong OS.
 
R

raludamian

Right now I'm working only with an emulator, not with a phisical
device.... But doesn't the emulator build a separate filesystem or
something? I have read on a forum that there is a \windows folder on
the emulator and that one should try to copy the dlls there... I have
tried that - using active sync and cradle the dll (I have set active
sync on using DMA connections) but I don't really undertand what this
does...

I'm realy sorry if I'm not being quite clear here... :( It's a faculty
project and it's really important and I'm a sort of newbie into
embedded / CF domain...

Tank you!!

P.S. I will try to build again the dll but I don't really understand
how could it have been compiled for the wrong OS...

Simon Hart a scris:
Sorry I am getting a bit confused by your questions. You need to deploy it to
the device, not your local C: drive. Is this what you are doing?

Simon.

Hello!
Thank you for the reply!

Yes, I have.... But now a question: does it matter if it is in the C:
\windows folder if all the data is deployed onto the emulator?
Shouldn't I put it in another folder? I tried copying it on C:\Program
Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework
\2.0\v1.0\WindowsCE\ but still it doesn't work...

Raluca

Simon Hart a scris:
I'm not a guru in interop, but have you tried placing the native dll in the
Windows folder?

Simon.

:

Hello!

I'm trying to develop a GIS mapping software on smart devices using VS
2005, C#. need to use a library that was written in C++. Being open
source I compiled the C++ code VS 2005 --> C++ --> Smart Devices and I
obtained a DLL. Now I need to access the DLL functions (unmanaged
code) from my C# (managed code) application. Unfortunatelly I got a
"Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}

and just use it in C# to se if it works:

[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();

But again I got the same error.... I really don't understand!

I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll

00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluca
 
R

Ryan O'Neill

Hi Raluca,

I took your code and was able to use it without any issues.

Have you tried adding the test_C_2.dll file to your C# project? Set the File
Properties as the following:

Build Action: Content
COM Register: Don't Register
Copy to Output Directory: Copy always

Hope that helps.

Ryan

http://rhinomobile.blogspot.com/
 
R

raludamian

Hello!

"Missing Method Exception" was unhandled is the exception. It appears
when at this section of the code:

public static int fntest_C_wrap()
{
return fntest_C();
}

Raluca

P.S. And I have already included the dll in the project... :(

Tomer Gabel a scris:
Hello (e-mail address removed),

Which exception are you actually getting - FileNotFoundException or TypeLoadException?...

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)

Hello!

I'm trying to develop a GIS mapping software on smart devices using VS
2005, C#. need to use a library that was written in C++. Being open
source I compiled the C++ code VS 2005 --> C++ --> Smart Devices and I
obtained a DLL. Now I need to access the DLL functions (unmanaged
code) from my C# (managed code) application. Unfortunatelly I got a
"Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}
and just use it in C# to se if it works:

[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();
But again I got the same error.... I really don't understand!

I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll
00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name

1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluca
 
T

Tomer Gabel

Hello (e-mail address removed),

Try turning on interop logging: http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx
Paste your results, perhaps things will become clearer then.

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)

Hello!

"Missing Method Exception" was unhandled is the exception. It appears
when at this section of the code:

public static int fntest_C_wrap()
{
return fntest_C();
}
Raluca

P.S. And I have already included the dll in the project... :(

Tomer Gabel a scris:
Hello (e-mail address removed),

Which exception are you actually getting - FileNotFoundException or
TypeLoadException?...

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)
Hello!

I'm trying to develop a GIS mapping software on smart devices using
VS 2005, C#. need to use a library that was written in C++. Being
open source I compiled the C++ code VS 2005 --> C++ --> Smart
Devices and I obtained a DLL. Now I need to access the DLL functions
(unmanaged code) from my C# (managed code) application.
Unfortunatelly I got a "Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}
and just use it in C# to se if it works:
[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();
But again I got the same error.... I really don't understand!
I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll
00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluc
 
R

raludamian

Hello!
I have no idea on how to enable logging as I don't have a HKLM\Software
\Microsoft\.NETCompactFramework\Diagnostics\Logging\Enabled key...

I mean I only have HKLM\Software\Microsoft\.NETCompactFramework\ and :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v1.0.5000
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v1.0.5000.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v2.0.0.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v2.0.3600

And no "Debugging" key...

Another question now: I have tried to run one of the "samples"
projects existing in "C:\Program Files\Windows CE Tools\wce500\Windows
Mobile 5.0 Pocket PC SDK\Samples\Cs\Gps\"
This project uses [DllImport("gpsapi.dll")] and it works...
The problem is that gpsapi.dll doesn't exist on my computer ... I
don't understand!!!!!
What it does exist are: gpsapi.h, gpsapi.lib, gpsapi.exp... I have
already tried to copy test_C_2.h, test_C_2.lib, test_C_2.exp in the
exact same location as the other ones... but the problem is the
same...

Same error... :(

Thank you for the help... If anyone can give me more ideas I would
very very much appreciate it...

Raluca

First of all I have n
Tomer Gabel a scris:
Hello (e-mail address removed),

Try turning on interop logging: http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx
Paste your results, perhaps things will become clearer then.

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)

Hello!

"Missing Method Exception" was unhandled is the exception. It appears
when at this section of the code:

public static int fntest_C_wrap()
{
return fntest_C();
}
Raluca

P.S. And I have already included the dll in the project... :(

Tomer Gabel a scris:
Hello (e-mail address removed),

Which exception are you actually getting - FileNotFoundException or
TypeLoadException?...

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)
Hello!

I'm trying to develop a GIS mapping software on smart devices using
VS 2005, C#. need to use a library that was written in C++. Being
open source I compiled the C++ code VS 2005 --> C++ --> Smart
Devices and I obtained a DLL. Now I need to access the DLL functions
(unmanaged code) from my C# (managed code) application.
Unfortunatelly I got a "Can't find PInvoke dll" problem.

Afterwards I tryed to do a simple C++ Smart Device DLL:

extern "C" __declspec(dllexport) int __stdcall fntest_C()
{
return 42;
}
and just use it in C# to se if it works:
[DllImport("test_C_2.dll",EntryPoint="fntest_C")]
public static extern int fntest_C();
But again I got the same error.... I really don't understand!
I tied also dumpbin.exe /EXPORTS:
:
Section contains the following exports for test_C_2.dll
00000000 characteristics
45FA72B6 time date stamp Fri Mar 16 12:34:30 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00001000 fntest_C = fntest_C

Please help... I really don't know what to do... Should I try to
compile the C++ code using eVC instead of VS2005 ? I mention that I
have copied the C++ dll in the same directory as the C# exe file...

Thank you for your patience...

Kind regards,
Raluca
 
G

Guest

I have no idea on how to enable logging as I don't have a HKLM\Software
\Microsoft\.NETCompactFramework\Diagnostics\Logging\Enabled key...

Yes, you have to create it. Most registry editors can do that.
Another question now: I have tried to run one of the "samples"
projects existing in "C:\Program Files\Windows CE Tools\wce500\Windows
Mobile 5.0 Pocket PC SDK\Samples\Cs\Gps\"
This project uses [DllImport("gpsapi.dll")] and it works...
The problem is that gpsapi.dll doesn't exist on my computer ... I
don't understand!!!!!

What do you mean by "it works"? If the application runs, then the
gpsapi.dll library *must* exist on the target device. IIRC that library is
provided on WM 5.0 devices with a GPS.
What it does exist are: gpsapi.h, gpsapi.lib, gpsapi.exp... I have
already tried to copy test_C_2.h, test_C_2.lib, test_C_2.exp in the
exact same location as the other ones... but the problem is the
same...

No idea what you're trying here. C# doesn't have a clue what to do with a
..h, .lib or .exp file. It calls LoadLibrary and GetProcAddress based on you
P/Invoke declaration - no black magic there.


--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
 
R

raludamian

The steps that I follow:

(1) Project: Visual C++ ---> Smart Device ---> Win32 SmartDevice
Project ---> Windows Mobile 5.0 SDK ---> Application Type: DLL, Empty
project


(2) Project: Visual C# ---> Smart Device ---> Windows Mobile 5.0
Pocket PC ---> Class Library

(3) Project: Visual C# ---> Smart Device ---> Windows Mobile 5.0
Pocket PC ---> Device Application


The DLL resulted from (1) is C++ unmanaged code. I try to wrapp it in
step (2) using: [DllImport....] and Add - Existing Item Proprieties:
Build Action = Content and so on; and then I try to use it in step (3)
whare the wrapper dll from step (2) is used.

Am I doing something fundamentally wrong?

Raluca

I'm starting to give up hope....
 
R

raludamian

Wow! I managed to find the problem...

I had no Idea that I should have exported the native dll using the
Windows CE Remot File Viewer tool... (for others like me whou will
perhaps read this post this tool can be found at: C:\Program Files\CE
Remote Tools\5.01\bin)

I suppose it was so stupid that noone thought to mention it... :)...
but this was it... everything else was ok .

Thank you very much to all who found time to read this SOS message and
tried to help! :)

Raluca

(e-mail address removed) a scris:
 

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