I need to call a DLL function in Pocket PC using C# for Compact
Framework. The function takes a "char *" variable. Assume the
function is declared something as following and "param" is an in and
out parameter:

extern "C" __declspec( dllexport ) char *Test(char *param)


In full .NET framework I can use the the following C# declaration and
use the function with no problem.


[DllImport("TestDLL.dll")]

public static extern string Test([MarshalAs(UnmanagedType.LPStr)]
StringBuilder buf);



But as you are aware, the Compact Framework does not support MarshalAs
attribute and I have not been able to call the function. I have
Googled for a solution but somehow I cannot find the right answer.

Would you please tell me how you pass a "char *" parameter in and out
of a DLL function in compact framework using C#.

Thanks in advance

Re: MarshalAs equivalent using C# in Compact Framework by Alex

Alex
Thu Apr 28 12:59:12 CDT 2005

Your best bet would be to declare the function as taking byte[] parameter
and returning IntPtr. The parameter to pass will be
byte[] buf = Encoding.ASCII.GetBytes(yourString);
Upon return you could get your string back by using
Encoding.ASCII.GetString()


--
Alex Feinman
---
Visit http://www.opennetcf.org
"Hitchkas" <hitchkas@gmail.com> wrote in message
news:1114710815.349489.252800@z14g2000cwz.googlegroups.com...
>I need to call a DLL function in Pocket PC using C# for Compact
> Framework. The function takes a "char *" variable. Assume the
> function is declared something as following and "param" is an in and
> out parameter:
>
> extern "C" __declspec( dllexport ) char *Test(char *param)
>
>
> In full .NET framework I can use the the following C# declaration and
> use the function with no problem.
>
>
> [DllImport("TestDLL.dll")]
>
> public static extern string Test([MarshalAs(UnmanagedType.LPStr)]
> StringBuilder buf);
>
>
>
> But as you are aware, the Compact Framework does not support MarshalAs
> attribute and I have not been able to call the function. I have
> Googled for a solution but somehow I cannot find the right answer.
>
> Would you please tell me how you pass a "char *" parameter in and out
> of a DLL function in compact framework using C#.
>
> Thanks in advance
>