The CF will marshal byte[] as a pointer. The only way to pass the
SMSREGISTRATIONDATA is to convert it the byte array. Check out my
article
on
MSDN:
http://msdn.microsoft.com/library/d.../dnnetcomp/html/ProcessManager.asp?frame=true
Or take a look at the SmartMarshaler:
http://www.opennetcf.org/PermaLink.aspx?guid=abe6694a-ff15-4617-a21f-8163d427a89c
--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com |
www.opennetcf.org
:
I try to byte[] but it does not work.
[DllImport("sms.dll")]
public static extern int SmsSetMessageNotification (byte[] psmsrd);
public class SMSREGISTRATIONDATA
{
long cbSize;
byte[] tszAppName; //260
byte[] tszParams; //260
byte[] tszProtocolName;//260
SMSREGISTRATIONDATA()
{
tszAppName = new byte[260];
tszParams = new byte[260];
tszProtocolName = new byte[260];
cbSize = 4 + tszAppName.Length + tszParams.Length +
tszProtocolName.Length;
}
public SMSREGISTRATIONDATA(string AppName,string Params,string
ProtocolName):this()
{
byte[] app = System.Text.ASCIIEncoding.ASCII.GetBytes(AppName);
app.CopyTo(tszAppName,0);
byte[] par = System.Text.ASCIIEncoding.ASCII.GetBytes(Params);
par.CopyTo(tszParams,0);
byte[] pna =
System.Text.ASCIIEncoding.ASCII.GetBytes(ProtocolName);
pna.CopyTo(tszProtocolName,0);
}
public byte[] ToBytes()
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms);
bw.Write(cbSize);
bw.Write(tszAppName);
bw.Write(tszParams);
bw.Write(tszProtocolName);
byte[] result = ms.ToArray();
bw.Close();
ms.Close();
return result;
}
}
HRESULT SmsSetMessageNotification (
const SMSREGISTRATIONDATA * psmsrd);
typedef struct smsregistrationdata_tag {
DWORD cbSize; //3 * 260 or 3 * 260 + 4 ???
TCHAR tszAppName[SMS_MAX_APPNAME_LENGTH];//260
TCHAR tszP
arams[SMS_MAX_PARAMS_LENGTH];//260
TCHAR tszProtocolName[SMS_MAX_PROTOCOLNAME_LENGTH]; //260
} SMSREGISTRATIONDATA, *LPSMSREGISTRATIONDATA;
How to define them in c# ?