Cross-posting from the csharp newsgroup,

Are there any restrictions in using MarshalAs when p/invoke-ing from a class
library as opposed to a windows application in .NET CF 2.0?

The following code will not compile in a CF class library with the error
MarshalAs not found. The same code runs happily in both a Windows
Applicationa and a standard class library.

Is there a simple fix (other than pinvoking only from a .EXE file)?

using System.Runtime.InteropServices;
...
[DllImport("my.dll", CharSet = CharSet.Unicode)]
public static extern bool Test1([In, Out, MarshalAs UnmanagedType.U4)]
ref uint testValue)

Thanks,

Peter

Re: PInvoke from a class library by ctacke/>

ctacke/>
Wed Jul 19 09:43:25 CDT 2006

The CF marshaler is not as robust as the desktop. That said, I'm not sure
why you're decorated this method. A ref uint will marshal by default as
you're trying to tell it, and CE is always Unicode.

-Chris

"Peter" <Peter@discussions.microsoft.com> wrote in message
news:6BCAEB50-12C2-4454-B5A8-895FD8B42135@microsoft.com...
>
> Cross-posting from the csharp newsgroup,
>
> Are there any restrictions in using MarshalAs when p/invoke-ing from a
> class
> library as opposed to a windows application in .NET CF 2.0?
>
> The following code will not compile in a CF class library with the error
> MarshalAs not found. The same code runs happily in both a Windows
> Applicationa and a standard class library.
>
> Is there a simple fix (other than pinvoking only from a .EXE file)?
>
> using System.Runtime.InteropServices;
> ...
> [DllImport("my.dll", CharSet = CharSet.Unicode)]
> public static extern bool Test1([In, Out, MarshalAs UnmanagedType.U4)]
> ref uint testValue)
>
> Thanks,
>
> Peter
>