WinCe DLL Import

B

Bryan G

I am trying to access a native C dll in a VB.Net Smart
Device application. I believe I'm accessing the dll in the
correct way but I keep getting an:

An unhandled exception of
type 'System.NotSupportedException' occurred in
SmartDeviceApplication2.exe

error. This is the code I've been trying to use:

Imports System.Text
Imports System.Runtime.InteropServices

Module Module1
Public Declare Function GetMsg Lib "DBAccess.dll" ()
As StringBuilder

Sub Main()
Dim s As StringBuilder = New StringBuilder(15)
s = GetMsg()
Console.WriteLine(s)
End Sub
End Module

I make sure that DBAccess.dll is in the same folder as the
VB exectuable. Any suggestions as to what i'm doing wrong?
 
P

Paul G. Tobey [eMVP]

There are a couple of strange things with that:

1. I seriously doubt that your C DLL is returning a managed code
StringBuilder. I think that's wrong (and probably the cause of the
exception).

2. Even if it were returning a StringBuilder (somehow), you wouldn't
allocate the string builder, Dim s As StringBuilder = New StringBuilder(15),
and then set s = GetMsg().

Paul T.
 
B

Bryan G

You're correct the C dll does not return a StringBuilder,
it returns a char*, but I've found examples of VB code
which do NOT marshal explicity, it handles the
transformation automatically (which is useful seeing
as "marshal as" isn't in the .NET compact framework).
Also, I can get this code to run fine on a regular PC
console, it only fails on the CE emulator. I also tried it
with a function that takes no args, returns nothing and
does nothing and got the same error. This all leads me to
believe that the DLL isn't even being found on the
emulator but i'm not sure why.
 
P

Paul G. Tobey [eMVP]

Use the dependency viewer that comes with VS.NET 2003 and open that DLL.
Verify that the function is shown in the exports pane and that it shows *no
parameters*. If it shows parameters, you have a C++ DLL and the function
names are decorated. Also, make sure that you have the DLL compiled
properly for the emulator (correct processor, correct platform).

Paul T.
 
B

Bryan G

Recompiling the DLL sounds like the problem.

I've compiled it on my machine and then sent it to the
emulator. How would I go about compiling it for the
emulator, or CE specifically?

The first part is not a problem as I have the source of
the DLL.
 
P

Paul G. Tobey [eMVP]

You must use eVC, not VS.NET 2003, to compile for Windows CE. VS.NET has
*no* support for Windows CE native executables.

Paul T.
 
A

Alex Feinman [MVP]

If this is for CE.NET 4.2, make sure to get eVC 4.0 and sp2
For CE 3.0 (PocketPC 2002 and 2000) use eVC3
 

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