Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem when importing a C++ function on Windows CE 4.2

0 views
Skip to first unread message

jman0

unread,
Apr 22, 2009, 4:03:29 AM4/22/09
to
I have developed a C++ DLL with Embedded Visual C++ 4.0. Inside it
there's a function which in the past returned a bool value, and worked
perfectly when called from a C# project.

Now, I need that function to return a DWORD value. In C++, the
function header is as follows:

extern "C" LIB_API DWORD StartRASConnection(unsigned short *Name,
unsigned short *UserName, unsigned short *Password)

where LIB_API is declared as

#ifdef MIPLIB_EXPORTS
#define LIB_API __declspec(dllexport)
#else
#define LIB_API __declspec(dllimport)
#endif

In C#, function is imported as

[DllImport("miplib.dll")]
public static extern long StartRASConnection(string nombreConn, string
usuario, string pass);

The problem is that when I call StartRASConnection, an exception is
raised. The exception text is just "NotSupportedException". I think
the problem must be on the C# side, since there's a try...catch block
on the C++ code, which catches all exceptions and then returns the
number 25000 in case one is raised. When the same try...catch block
just returned 0 in the past (when the function returned bool) there
was no "NotSupportedException" issue.

When the C++ function returned a bool, everything worked fine, which
is driving me crazy.

Where's the problem with my code?

Thanks in advance.

Ben Voigt [C++ MVP]

unread,
Apr 24, 2009, 11:41:55 AM4/24/09
to

"jman0" <jm...@zapo.net> wrote in message
news:92af748f-0fb7-462a...@t21g2000yqi.googlegroups.com...

C# long isn't the same size as C++ DWORD. Use System.UInt32, which is the
correct equivalent to DWORD.

>
> Thanks in advance.

0 new messages