Re: marshalling struct to class problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Andrea (andreno_spamalmieri_at_enmo_spamm)
Date: 03/03/04


Date: Wed, 3 Mar 2004 11:18:48 +0100

My structure:

typedef struct CK_SLOT_INFO {
 unsigned char slotDescription[64];
 unsigned char manufacturerID[32];
 long flags;
} CK_SLOT_INFO;

my c#
 declaration

class Pkcs11{
.......
[StructLayout(LayoutKind.Sequential)]

public class CK_SLOT_INFO

{

    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=64 )]

    public byte[] slotDescription = null;

    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=32 )]

    public byte[] manufacturerID = null;

    public Int32 flags;

}

my method declaration

[DllImport("teststruct.dll")]

public static extern int getslot(Int32 slotID, ref CK_SLOT_INFO si);

my invocation

Pkcs11.CK_SLOT_INFO slotInfo = new Pkcs11.CK_SLOT_INFO() ;

ret = Pkcs11.getslot(i, ref slotInfo);

can you see where the problem is ?
Andrea

"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> ha scritto nel messaggio
news:ulvqpbJAEHA.2036@TK2MSFTNGP12.phx.gbl...
>
> >I already tried using ByValTStr, but some result...It doesn't work !!!
>
> So how are you using this type?
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.



Relevant Pages