Marshal problems in .NET CF

  • Thread starter Thread starter Brad Combs
  • Start date Start date
B

Brad Combs

Newsgroup,

I was curious if anyone could help me with a problem I'm having with
p/invoke and a structure from the credential manager API in CE 5.0. The
structure is in cred.h as:

typedef struct _CRED {
DWORD dwVersion;
DWORD dwType;
PWCHAR wszUser;
DWORD dwUserLen;
PWCHAR wszTarget;
DWORD dwTargetLen;
PBYTE pBlob;
DWORD dwBlobSize;
DWORD dwFlags;
} CRED, *PCRED, **PPCRED;

So my two questions are:

1) Are the PWCHAR types just strings?
2) Does anyone have any insight into how to handle the PBYTE type?

Sorry if these are easy questions.

Thanks,
Brad
 
A PWCHAR is a pointer to a WCHAR. The PBYTE is a pointer to a BYTE. The
marshaller won't be able to do this one.

-Chris
 
For both you can use the IntPtr type. Then either allocate some native
memory and write the address here (LocalAlloc or MarshalEx.AllocHGlobal from
the SDF www.opennetcf.org/sdf/) or use a GCHandle to pin a managed byte
array containing the bytes or characters. Just remember that after using
either method you'll need to free the memory or un-pin the GCHandle once
you've finished with the API method.

Peter
 
Back
Top