Has anybody succesfully initialized RIL under C# using the ril.dll
interface? I'm trying to use the following commands but never managed to
receive a callback after invoking the proper methods.

public delegate void RILRESULTCALLBACK(int dwCode, void* hrCmdID,
void* lpData, int cbData, int dwParam);
public delegate void RILNOTIFYCALLBACK(int dwCode, void* lpData, int
cbData, int dwParam);
public static readonly int RIL_NCLASS_ALL = 0x0fffffff;

[DllImport("ril.dll")]
public static extern int RIL_Initialize(int dwIndex,
[MarshalAs(UnmanagedType.FunctionPtr)]RILRESULTCALLBACK pfnResult,
[MarshalAs(UnmanagedType.FunctionPtr)]RILNOTIFYCALLBACK pfnNotify, int
dwNotificationClasses, int dwParam, out void* lphRil);

And then I try:
RILRESULTCALLBACK resultCallback = new RILRESULTCALLBACK(f_result);
RILNOTIFYCALLBACK notifyCallback = new RILNOTIFYCALLBACK(f_notify);

where the receivers are:
private void f_notify(int dwCode, void* lpData, int cbData, int dwParam)
{...}
private void f_result(int dwCode, void* hrCmdID, void* lpData, int
cbData, int dwParam) {...}

My question is am a using correct argument types for the methods. Has
anyone done it, had it working and would share the solution with me?

Re: RIL C# Again... by Robin

Robin
Sun Mar 02 21:38:01 CST 2008

Hi,
Where your program running ?
My suggestion is: Create a C++ project and test the ril.dll.

"Tomasz Staroszczyk" <tomaszstaroszczyk@wp.pl> wrote in message
news:eM6m9UKfIHA.4140@TK2MSFTNGP04.phx.gbl...
> Has anybody succesfully initialized RIL under C# using the ril.dll
> interface? I'm trying to use the following commands but never managed to
> receive a callback after invoking the proper methods.
>
> public delegate void RILRESULTCALLBACK(int dwCode, void* hrCmdID, void*
> lpData, int cbData, int dwParam);
> public delegate void RILNOTIFYCALLBACK(int dwCode, void* lpData, int
> cbData, int dwParam); public static readonly int RIL_NCLASS_ALL =
> 0x0fffffff;
>
> [DllImport("ril.dll")]
> public static extern int RIL_Initialize(int dwIndex,
> [MarshalAs(UnmanagedType.FunctionPtr)]RILRESULTCALLBACK pfnResult,
> [MarshalAs(UnmanagedType.FunctionPtr)]RILNOTIFYCALLBACK pfnNotify, int
> dwNotificationClasses, int dwParam, out void* lphRil);
>
> And then I try:
> RILRESULTCALLBACK resultCallback = new RILRESULTCALLBACK(f_result);
> RILNOTIFYCALLBACK notifyCallback = new RILNOTIFYCALLBACK(f_notify);
> where the receivers are:
> private void f_notify(int dwCode, void* lpData, int cbData, int dwParam)
> {...}
> private void f_result(int dwCode, void* hrCmdID, void* lpData, int cbData,
> int dwParam) {...}
>
> My question is am a using correct argument types for the methods. Has
> anyone done it, had it working and would share the solution with me?


Re: RIL C# Again... by Tomasz

Tomasz
Mon Mar 03 10:17:25 CST 2008

Robin Zhang pisze:
> Hi,
> Where your program running ?
> My suggestion is: Create a C++ project and test the ril.dll.

It's running directly on the device, creating a C++ project is something
I wanted to avoid... I'm a little bit afraid of creating visual apps in
C++, or tell me that it's as simple as in C# and I'm convinced. Though
still looking for a C# example. Greets

RE: RIL C# Again... by MartinKofahl

MartinKofahl
Wed Mar 12 01:58:02 CDT 2008

take a look here:
http://maps.alphadex.de/datafiles/ril.cs


"Tomasz Staroszczyk" wrote:

> Has anybody succesfully initialized RIL under C# using the ril.dll
> interface? I'm trying to use the following commands but never managed to
> receive a callback after invoking the proper methods.
>
> public delegate void RILRESULTCALLBACK(int dwCode, void* hrCmdID,
> void* lpData, int cbData, int dwParam);
> public delegate void RILNOTIFYCALLBACK(int dwCode, void* lpData, int
> cbData, int dwParam);
> public static readonly int RIL_NCLASS_ALL = 0x0fffffff;
>
> [DllImport("ril.dll")]
> public static extern int RIL_Initialize(int dwIndex,
> [MarshalAs(UnmanagedType.FunctionPtr)]RILRESULTCALLBACK pfnResult,
> [MarshalAs(UnmanagedType.FunctionPtr)]RILNOTIFYCALLBACK pfnNotify, int
> dwNotificationClasses, int dwParam, out void* lphRil);
>
> And then I try:
> RILRESULTCALLBACK resultCallback = new RILRESULTCALLBACK(f_result);
> RILNOTIFYCALLBACK notifyCallback = new RILNOTIFYCALLBACK(f_notify);
>
> where the receivers are:
> private void f_notify(int dwCode, void* lpData, int cbData, int dwParam)
> {...}
> private void f_result(int dwCode, void* hrCmdID, void* lpData, int
> cbData, int dwParam) {...}
>
> My question is am a using correct argument types for the methods. Has
> anyone done it, had it working and would share the solution with me?
>

Re: RIL C# Again... by Tomasz

Tomasz
Sun Mar 16 18:23:02 CDT 2008

> take a look here:
> http://maps.alphadex.de/datafiles/ril.cs

Thank you for your reply I find this snippet very useful. Have you tried
running it on a device? After calling GetCellTowerInfo() the dwCode
parameter in f_result callback handler has the value of 3
(NullReferenceException error according to Marshal.GetExceptionForHR()).
And so the the others are
MCC: 0
MNC: 151380
CID: 0
LAC: 4
For my contry and operator the MNC should be 02, and MCC 260
Though it's curious that the results at least look a bit logical.

Could anyone try this code on one's WM 6.0 device and see if the results
are similar? I've tried this on ASUS P535 device. Thanks in advance

Tomek

Re: RIL C# Again... by MartinKofahl

MartinKofahl
Mon Mar 17 04:05:01 CDT 2008

Here's my init (most by Neil Young):

RILRESULTCALLBACK r = new RILRESULTCALLBACK(f_result);
RILNOTIFYCALLBACK n = new RILNOTIFYCALLBACK(f_notify);

uint dwNotificationClasses = RIL_NCLASS_RADIOSTATE | RIL_NCLASS_NETWORK |
RIL_NCLASS_ALL | RIL_NCLASS_CALLCTRL | RIL_NCLASS_MESSAGE |
RIL_NCLASS_FUNCRESULT | RIL_NCLASS_SUPSERVICE | RIL_NCLASS_MISC |
RIL_NCLASS_DEVSPECIFIC;

IntPtr res = RIL_Initialize(1, r, n, (int)dwNotificationClasses, 0, out hRil);


... calling CellTowerInfo

this.done = false;
IntPtr res = RIL_GetCellTowerInfo(hRil);
int i = 10;
while (i-- > 0 && !this.done)
{
System.Threading.Thread.Sleep(10000);
}


... and getting the data in f_result

// somewhere above:
// RILCELLTOWERINFO result = new RILCELLTOWERINFO();

Marshal.PtrToStructure(lpData, result);
done = true;


Re: RIL C# Again... by Tomasz

Tomasz
Mon Mar 17 14:32:04 CDT 2008

> Here's my init (most by Neil Young):

Hello again, could you please try to replace your f_result with the
following and check what Code value is it going to display? And also
what kind of device are you using? Is it Smartphone, or PocketPC? What
model? Thanks in advance.

public static void f_result(int dwCode, IntPtr hrCmdID, IntPtr lpData,
int cbData, int dwParam)
{
RILCELLTOWERINFO rci = new RILCELLTOWERINFO();
Marshal.PtrToStructure(lpData, rci);

result = String.Format("Code: {4}, MCC: {0}, MNC: {1}, CID: {2}, LAC: {3}",
rci.dwMobileCountryCode,
rci.dwMobileNetworkCode,
rci.dwLocationAreaCode,
rci.dwCellID,
dwCode);
done = true;
}


Re: RIL C# Again... by MartinKofahl

MartinKofahl
Thu Mar 20 01:58:00 CDT 2008

Hi,
your code looks good and works on WM6/iPaq. But:

- in f_result() dwCode is not the same as in f_notify! Here it's the result
of the RIL_GetCellTowserInfo call (RIL_RESULT_OK etc.)

- so you better check who f_result called, e.g. by comparing cbData with the
structure size ( if (cbData == Marshal.SizeOf(typeof(RILCELLTOWERINFO)) ) or
better by storing the ID returned by RIL_GetCellTowserInfo():

private Dictionary<IntPtr, uint> resultTable;

resultTable = new Dictionary<IntPtr, uint>();

resultTable.Add(ptr = RIL_GetCellTowerInfo(hRil),
RIL_NOTIFY_CELLTOWERINFO);
if (ptr.ToInt32() < 0) resultTable.Remove(ptr);

in f_result()

uint dwCode2;
if (resultTable.TryGetValue(hrCmdID, out dwCode2))
{
resultTable.Remove(hrCmdID);

RILCELLTOWERINFO rci = new RILCELLTOWERINFO();
Marshal.PtrToStructure(lpData, rci);
}


Hope it helps
Martin


"Tomasz Staroszczyk" wrote:

> > Here's my init (most by Neil Young):
>
> Hello again, could you please try to replace your f_result with the
> following and check what Code value is it going to display? And also
> what kind of device are you using? Is it Smartphone, or PocketPC? What
> model? Thanks in advance.
>
> public static void f_result(int dwCode, IntPtr hrCmdID, IntPtr lpData,
> int cbData, int dwParam)
> {
> RILCELLTOWERINFO rci = new RILCELLTOWERINFO();
> Marshal.PtrToStructure(lpData, rci);
>
> result = String.Format("Code: {4}, MCC: {0}, MNC: {1}, CID: {2}, LAC: {3}",
> rci.dwMobileCountryCode,
> rci.dwMobileNetworkCode,
> rci.dwLocationAreaCode,
> rci.dwCellID,
> dwCode);
> done = true;
> }
>
>