By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,947 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,947 IT Pros & Developers. It's quick & easy.

Problems writing SMS's to sim card on pocketpc using simmanager api....

P: n/a

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

public void WriteFirstMessage(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
hResult = SimManagerWrapper.SimWriteMessage(simHandle, 1,
0, ref Message);

if (hResult != 0) // if SimWriteMessage() fails
throw (new Exception("SimManagerWrapper 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(UnmanagedType.ByValTStr, SizeConst = 1500)]
public string lpszAddress; //An array that contains the actual
phone number

public int dwAddressType; //A SIM_ADDRTYPE constant
SIM_ADDRTYPE_INTERNATIONAL = International number.
SIM_ADDRTYPE_NATIONAL 0ne National = number.
SIM_ADDRTYPE_NETWKSPECIFIC Network = specific number.
SIM_ADDRTYPE_ALPHANUM Alphanumeric = address.
SIM_ADDRTYPE_ABBREV Abbreviated = number.

public int dwNumPlan; //A SIM_NUMPLAN constant
SIM_NUMPLAN_TELEPHONE = ISDN/telephone numbering plan
SIM_NUMPLAN_DATA = Data numbering plan (X.121).
SIM_NUMPLAN_TELEX = Telex numbering plan.
SIM_NUMPLAN_NATIONAL = National numbering plan.
SIM_NUMPLAN_PRIVATE = Private numbering plan.
SIM_NUMPLAN_ERMES ERMES = numbering plan (ETSI DE/PS 3 01-3).
public DateTime stReceiveTime; //Timestamp for the incoming

public int cbHdrLength; //Header length in bytes

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1500)]
public byte[] rgbHeader; //An array containing the actual
header data

[MarshalAs(UnmanagedType.ByValTStr, 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:

typedef struct simmessage_tag {
DWORD cbSize;
DWORD dwParams;
DWORD dwAddressType;
DWORD dwNumPlan;
SYSTEMTIME stReceiveTime;
DWORD cbHdrLength;

In order to access the unmanaged struct I used platform invoke methods
as follows:

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

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....


Mar 2 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.