Click to See Complete Forum and Search --> : [RESOLVED] Help on Struct


KLBADBOY
October 8th, 2008, 08:06 AM
Hi I'm trying to convert Embedded C++ application to C#.
I'm stuck with Struct conversion problem. Here is the detail of my problem.
I hope anyon can help me please. Thanks in advanced.

C++
typedef struct __SMSPARAMS {
DWORD Index;
TCHAR SMS_Status[1024];
TCHAR CallerID[1024];
DATETIMEPARAMS DateTime;
DWORD msglength;
TCHAR message[1024];
} SMSPARAMS, *PSMSDPARAMS;


typedef struct __LSMSPARAMS {
SMSPARAMS *lsmsParams[50];
} LSMSPARAMS, *PLSMSDPARAMS;


LSMSPARAMS pLSMSParams;

function A(int *MsgCount,LSMSPARAMS *pSMSParamsStruct);
-------------------------------------------------------------------------------------------

How should I convert this struct into C# ? Especially the "LSMSPARAMS" ?

I have tried the following but, it's not working.


C#
public struct SMSPARAMS
{
[MarshalAs(UnmanagedType.U4)]
int Index;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string SMS_Status;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string CallerID;
DATETIMEPARAMS DateTime;
[MarshalAs(UnmanagedType.U4)]
int msglength;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string message;
}

public struct LSMSPARAMS
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public SMSPARAMS[] pSMSPARAM;
}

function A(ref int MsgCount,ref LSMSPARAMS pSMSParamsStruct);

Anyone please help me...

Arjay
October 8th, 2008, 08:57 AM
See www.pinvoke.net