I believe the mappings would go as I have below. In C# (.Net) a char is a 16-bit UNICODE character by default. Through attributes you can marshal a UNICODE char as an 8-bit ANSI char. Same applies to string params. There are several ways to pass strings --
in this case I marked the string a LPTStr which means it is passed either as a null terminated ANSI string or a null terminated UNICODE string depending on the CharSet of the call. Also, a long in C# is 64-bits while a long in VC is 32-bits. An int in C# is
32-bits. extern "C" void __declspec(dllexport) __stdcall Func( char ch, char* pch, char* psz, short s, short* ps, long l, long* pl ) { } [DllImport("some.dll", EntryPoint="_Func@28", CharSet=CharSet.Ansi)] static extern void Func( char ch, ref char pch, [MarshalAs(UnmanagedType.LPTStr)]string
psz, short s, ref short ps, int l, ref int pl );
Tim McBride
This posting is provided "AS IS" with no warranties, and confers no rights.
timmcb
Contributor
2379 Points
471 Posts
Microsoft
Re: dllimport how to translate some parameters
Oct 22, 2003 02:07 AM|LINK
This posting is provided "AS IS" with no warranties, and confers no rights.