How to define SmsSetMessageNotification function in .net cf?

  • Thread starter Thread starter LirenZhao
  • Start date Start date
L

LirenZhao

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 tszParams[SMS_MAX_PARAMS_LENGTH];//260
TCHAR tszProtocolName[SMS_MAX_PROTOCOLNAME_LENGTH]; //260
} SMSREGISTRATIONDATA, *LPSMSREGISTRATIONDATA;


How to define them in c# ?
 
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;
}
}
 
Windows CE is unicode only OS, thus you have to double the size for
tszAppName, tszParams and tszProtocolName from 260 to 520. And don't
forget to replace the System.Text.ASCIIEncoding.ASCII.GetBytes with
System.Text.Encoding.Unicode.GetBytes.
 
private const string TextProvider = "Microsoft Text SMS Protocol";
private const string NotificationProvider = "Microsoft Notification SMS
Protocol (Receive Only)";
private const string WdpProvider = "Microsoft WDP SMS Protocol";

private void Form1_Load(object sender, System.EventArgs e)
{
string app =
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
SMSHoo.SMSREGISTRATIONDATA ms = new
SMSREGISTRATIONDATA(app,"",TextProvider);
int RET = SMSHoo.SmsH.SmsSetMessageNotification(ms.ToBytes());
Text = RET.ToString();
}
RET = -2147024809; :(

Any one can help me?


LirenZhao said:
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;
}
}









LirenZhao said:
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# ?
 
One point that springs to mind is that cbSize should be declared as an int
(4 byte) not a long (8 bytes in .NET).

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

LirenZhao said:
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;
}
}









LirenZhao said:
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# ?
 
I changed cbSize as int ,It return the same result.

Peter Foot said:
One point that springs to mind is that cbSize should be declared as an int
(4 byte) not a long (8 bytes in .NET).

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

LirenZhao said:
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;
}
}









LirenZhao said:
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# ?
 
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


LirenZhao said:
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;
}
}









LirenZhao said:
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# ?
 
Thank Alex

I read your article,but I still have trouble on the struct.Is there anything
wrong in my code?

typedef struct smsregistrationdata_tag {
DWORD cbSize;
TCHAR tszAppName[SMS_MAX_APPNAME_LENGTH];
TCHAR tszParams[SMS_MAX_PARAMS_LENGTH];
TCHAR tszProtocolName[SMS_MAX_PROTOCOLNAME_LENGTH];
} SMSREGISTRATIONDATA, *LPSMSREGISTRATIONDATA;public class
SMSREGISTRATIONDATA
{
const int MAX_PATH = 260;
uint cbSize;
byte[] tszAppName;
byte[] tszParams;
byte[] tszProtocolName;

SMSREGISTRATIONDATA()
{
tszAppName = new byte[MAX_PATH];
tszParams = new byte[MAX_PATH];
tszProtocolName = new byte[MAX_PATH];
cbSize = 3 * MAX_PATH + 4;
}

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;
}
}




Alex Yakhnin said:
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


LirenZhao said:
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;
}
}









LirenZhao said:
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# ?
 
I don't see anything wrong with that. What exception do you get?
Which device are trying it on?

Also remember that this is a privileged API, that required signing your app.
--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


LirenZhao said:
Thank Alex

I read your article,but I still have trouble on the struct.Is there anything
wrong in my code?

typedef struct smsregistrationdata_tag {
DWORD cbSize;
TCHAR tszAppName[SMS_MAX_APPNAME_LENGTH];
TCHAR tszParams[SMS_MAX_PARAMS_LENGTH];
TCHAR tszProtocolName[SMS_MAX_PROTOCOLNAME_LENGTH];
} SMSREGISTRATIONDATA, *LPSMSREGISTRATIONDATA;public class
SMSREGISTRATIONDATA
{
const int MAX_PATH = 260;
uint cbSize;
byte[] tszAppName;
byte[] tszParams;
byte[] tszProtocolName;

SMSREGISTRATIONDATA()
{
tszAppName = new byte[MAX_PATH];
tszParams = new byte[MAX_PATH];
tszProtocolName = new byte[MAX_PATH];
cbSize = 3 * MAX_PATH + 4;
}

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;
}
}




Alex Yakhnin said:
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


LirenZhao said:
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# ?
 
no Exception ,just return -14xxxxxxx ,big number

Alex Yakhnin said:
I don't see anything wrong with that. What exception do you get?
Which device are trying it on?

Also remember that this is a privileged API, that required signing your
app.
--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


LirenZhao said:
Thank Alex

I read your article,but I still have trouble on the struct.Is there
anything
wrong in my code?

typedef struct smsregistrationdata_tag {
DWORD cbSize;
TCHAR tszAppName[SMS_MAX_APPNAME_LENGTH];
TCHAR tszParams[SMS_MAX_PARAMS_LENGTH];
TCHAR tszProtocolName[SMS_MAX_PROTOCOLNAME_LENGTH];
} SMSREGISTRATIONDATA, *LPSMSREGISTRATIONDATA;public class
SMSREGISTRATIONDATA
{
const int MAX_PATH = 260;
uint cbSize;
byte[] tszAppName;
byte[] tszParams;
byte[] tszProtocolName;

SMSREGISTRATIONDATA()
{
tszAppName = new byte[MAX_PATH];
tszParams = new byte[MAX_PATH];
tszProtocolName = new byte[MAX_PATH];
cbSize = 3 * MAX_PATH + 4;
}

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;
}
}




Alex Yakhnin said:
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# ?
 
unsafe public static int SetMessageNotification(string strAppName, string
strParams, string strProtocolName)
{
IntPtr hSms = IntPtr.Zero;
IntPtr hSms1 = IntPtr.Zero;

SMSTest.SMSREGISTRATIONDATA objRegData = new
SMSREGISTRATIONDATA(strAppName, strParams, strProtocolName);

Byte[] bSMSData = new byte[objRegData.cbSize];

Byte[] bMsgType = new Byte[516];

fixed (byte* pSMSData = bSMSData, pSMSType = bMsgType)

{
byte* pCurrentData = pSMSType;
foreach (byte b in Encoding.Unicode.
GetBytes(strProtocolName))
{
Marshal.WriteByte((IntPtr)pCurrentData, b);
pCurrentData++;
}
hSms = SMSTest.SMS.SmsClearMessageNotification((IntPtr)
pSMSType);

pCurrentData = pSMSData;
foreach (byte b in objRegData.ToBytes()){
Marshal.WriteByte((IntPtr)pCurrentData, b);
pCurrentData++;
}
hSms1 = SMSTest.SMS.SmsSetMessageNotification((IntPtr)
pSMSData);
}
return (int)hSms1;
}
 
Assuming you are using Windows Mobile 5.0 or above you should use the
Microsoft.WindowsMobile.PocketOutlook.MessageInterception functionality as
this will allow you to run your application when any message meeting a
specific rule is received. The SmsSetMessageNotification function is
deprecated and you should use either IMailRuleClient or the managed
equivalent to react to incoming messages.

Peter
 
unsafe public static int SetMessageNotification(string strAppName, string
strParams, string strProtocolName)

{

IntPtr hSms = IntPtr.Zero;

IntPtr hSms1 = IntPtr.Zero;

SMSTest.SMSREGISTRATIONDATA objRegData = new SMSREGISTRATIONDATA(strAppName,
strParams, strProtocolName);


Byte[] bSMSData = new byte[objRegData.cbSize];

Byte[] bMsgType = new Byte[516];

fixed (byte* pSMSData = bSMSData, pSMSType = bMsgType)


{

byte* pCurrentData = pSMSType;

foreach (byte b in Encoding.Unicode.GetBytes(strProtocolName))

{

Marshal.WriteByte((IntPtr)pCurrentData, b);

pCurrentData++;

}

hSms = SMSTest.SMS.SmsClearMessageNotification((IntPtr)pSMSType);


pCurrentData = pSMSData;

foreach (byte b in objRegData.ToBytes()){

Marshal.WriteByte((IntPtr)pCurrentData, b);

pCurrentData++;

}

hSms1 = SMSTest.SMS.SmsSetMessageNotification((IntPtr)pSMSData);

}

return (int)hSms1;

}
 
Back
Top