开发者

Marshalling fixed Tchar[] in .netcompactFramework

开发者 https://www.devze.com 2023-02-20 15:20 出处:网络
How can one Marshal the fixedTchar[] in .Net compact Framework and in.net Framework typedefst开发者_开发问答ruct _VXN_REGISTRATION_RESPONSE

How can one Marshal the fixed Tchar[] in .Net compact Framework and in.net Framework

typedef  st开发者_开发问答ruct _VXN_REGISTRATION_RESPONSE
{
       char        DID [257]; 
       TCHAR       PrimarySDCURL [257];
       TCHAR       SecondarySDCURL [257];
} VXN_REGISTRATION_RESPONSE, *LPVXN_REGISTRATION_RESPONSE;


I'm assuming that TCHAR is wide. If not then you can work it out since it's the same as the char field.

The struct wants to be declared like this:

public struct LPRData
{
    [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 257)]
    public byte[] DID;
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 257)]
    public string PrimarySDCURL;
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 257)]
    public string SecondarySDCURL;
}

The only difficult bit is that compact framework doesn't make it easy to convert from Unicode to ANSI. So to assign to DID you need:

string DID = ...;
LPRData data = new LPRData();
data.DID = DID.Encoding.ASCII.GetBytes(DID);
0

精彩评论

暂无评论...
验证码 换一张
取 消