Hey!
At the time being I'm working on a backup solution for a Qtek9090
pocketpc, which should be able to find and backup outlook data to a
server, local files, messages and contact from the sim card (and backup
them to a server as well) all written in C#. So I'm making a wrapper
for the sim manager api. In order to use it's functions in my device
application, I've used platform invoke method, to acces the simmanager
functions from managed c# code. This brings both good and bad - now I
can read messages from the sim card (SimReadMessage function from the
sim manager api, through my wrapper), but when I want to write af
message to the sim card using SimWriteMessage (HSIM hSim, DWORD
dwStorage, LPDWORD lpdwIndex, LPSIMMESSAGE lpSimMessage) or as it looks
in my wrapper (a function just writing an sms to first index on the sim
card):
public void WriteFirstMessa ge(ref SimMessageTag Message)
{
//The arguments: int simHandle, 1 for the storage location, 0 for
the index on the sim card, ref Message is a struct I've made,
corresponding to the struct in the sim manager api representing a
message.
hResult = SimManagerWrapp er.SimWriteMess age(simHandle, 1,
0, ref Message);
if (hResult != 0) // if SimWriteMessage () fails
throw (new Exception("SimM anagerWrapper failed"));
}
I get an error saying that there is invalid parameter.
I think the error occurs because I made some wrong conversions from the
simmanager struct to my c# struct, but I can't see whats wrong.
Here is the c# struct, the conversions I'm most insecure about are the
places where I use the "MarshalAs" function:
public struct SimMessageTag
{
public int cbSize; // Size of the structure in bytes
public int dwParams; //Indicates valid parameter values
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 1500)]
public string lpszAddress; //An array that contains the actual
phone number
public int dwAddressType; //A SIM_ADDRTYPE constant
/*
SIM_ADDRTYPE_UN KNOWN = Unknown.
SIM_ADDRTYPE_IN TERNATIONAL = International number.
SIM_ADDRTYPE_NA TIONAL 0ne National = number.
SIM_ADDRTYPE_NE TWKSPECIFIC Network = specific number.
SIM_ADDRTYPE_SU BSCRIBER Subscriber = number
(protocol-specific).
SIM_ADDRTYPE_AL PHANUM Alphanumeric = address.
SIM_ADDRTYPE_AB BREV Abbreviated = number.
*/
public int dwNumPlan; //A SIM_NUMPLAN constant
/*
SIM_NUMPLAN_UNK NOWN = Unknown.
SIM_NUMPLAN_TEL EPHONE = ISDN/telephone numbering plan
(E.164/E.163).
SIM_NUMPLAN_DAT A = Data numbering plan (X.121).
SIM_NUMPLAN_TEL EX = Telex numbering plan.
SIM_NUMPLAN_NAT IONAL = National numbering plan.
SIM_NUMPLAN_PRI VATE = Private numbering plan.
SIM_NUMPLAN_ERM ES ERMES = numbering plan (ETSI DE/PS 3 01-3).
*/
public DateTime stReceiveTime; //Timestamp for the incoming
message
public int cbHdrLength; //Header length in bytes
[MarshalAs(Unman agedType.ByValA rray, SizeConst = 1500)]
public byte[] rgbHeader; //An array containing the actual
header data
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 10000)]
public string lpszMessage; //An array containing the actual
message data
}
And here is the simmanager struct (from the unmanaged code)
can also be found here:
http://msdn.microsoft.com/library/de...simmessage.asp
typedef struct simmessage_tag {
DWORD cbSize;
DWORD dwParams;
TCHAR lpszAddress[MAX_LENGTH_ADDR ESS];
DWORD dwAddressType;
DWORD dwNumPlan;
SYSTEMTIME stReceiveTime;
DWORD cbHdrLength;
BYTE rgbHeader[MAX_LENGTH_HEAD ER];
TCHAR lpszMessage[MAX_LENGTH_MESS AGE];
} SIMMESSAGE, FAR *LPSIMMESSAGE;
In order to access the unmanaged struct I used platform invoke methods
as follows:
[DllImport("cell core.dll")]
public static extern int SimWriteMessage (int hSim, int
dwStorage, int lpdwIndex, ref SimMessageTag SmsStructType);
So if anybody can help me getting this problem solved It would very
helpful.
If you know that writing messages to the sim card simply isn't doable,
does anyone know if it is possible just to copy all the messages (e.g.
if they lie in af file on the sim or a database), and then restore this
entire file or db instead of taking the sms's one by one?
Sorry for the topic being so long, but I had to led you know what I'm
working on....
Cheers
Bo