error LNK2028: unresolved token (0A000015) "extern "C" long __cdecl RIL_Initialize - Windows Mobile Development and Hacking General

error LNK2028: unresolved token (0A000015) "extern "C" long __cdecl RIL_Initialize
Trying to create a simple DLL from the ril code so that I can use the calls from within my VB.net code.
I'm more than a little out of my depth, but have got the tstril code working perfectly well. I've not really done any C++ before, however I've programmed in JAVA, PHP, VB etc. so although new to C++ I'm not completely new to programming.
Problem is when I create a new C++ project to create a DLL and drop in some simple code I get the above error when linking. The ril.lib file is in my project directory (I don't seem to be able to add the file specifically when linking - using microsoft visual studio 2005 prof).
Now I'm either missing something simple, or trying to do something that's not possible. Any advice would be greatly appreciated.
Here's my code:
#include "ril.h"
#include "stdafx.h"
#include "mobril.h"
#using <mscorlib.dll>
namespace mobril
{
//////////////////////////////////////////////////////////////////////
// Callback functions
//////////////////////////////////////////////////////////////////////
void CALLBACK NotifyCallback(DWORD dwCode, const void *lpData, DWORD cbData, DWORD dwParam)
{
ril::OnNotifyCallback(dwCode, lpData, cbData, dwParam);
}
void CALLBACK ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *lpData, DWORD cbData, DWORD dwParam)
{
ril::OnResultCallback(dwCode, hrCmdID, lpData, cbData, dwParam);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
bool ril::InitializeRIL()
{
HRIL hRil = 0;
DWORD dwParam = 0x55AA55AA;
DWORD dwNotificationClasses = 0xFF0000;
HRESULT result;
result = RIL_Initialize(1, ResultCallback, NotifyCallback, dwNotificationClasses, dwParam, &hRil);
return hRil!=NULL;
}
void ril::OnNotifyCallback(DWORD dwCode, const void *lpData, DWORD cbData, DWORD dwParam)
{
// ...
}
void ril::OnResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *lpData, DWORD cbData, DWORD dwParam)
{
// ...
}
}

I think my problem arrises from the fact that I have to write the dll as a clr standard windows application which obviously wouldn't know anything about the ril.dll. If I try and write the dll as a pocket pc dll then I don't seem able to reference the dll from within the vb application.
Anyone with any ideas?

Related

From Services.exe to Devices.exe

I have a background service DLL running on Windows Mobile 2003 in Services.exe.
I now wish to port it to run in Devices.exe. I have so far been unable to get it to run. Instead when I run the ActivateDevice or ActivateDeviceEx it returns with error 1,2 or 120.
What is required by my DLL to be compatable with Devices.exe?
I have added what I assume are the correct registry settings under HKLM\\Devices\\Name so i can only assume it is something wrong with the DLL itself.
If anyone can assist me with this problem it would be greatly appreciated.
Cheers Gerard
Do I need to use the Developer Platform to create the driver or is Embedded fine?
You can use eVC to create drivers.
To make your driver recognized by OS you should add registry keys:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\_name_]
"Prefix"="BLA" - 3 CAPS letters, it is your driver prefix
"Index"=dword:00000001
"Dll"="yourdriver.Dll"
And your driver should export functions:
BLA_Close
BLA_Deinit
BLA_IOControl
BLA_Init
BLA_Open
BLA_PowerDown
BLA_PowerUp
BLA_Read
BLA_Seek
BLA_Write
Later you can use CreateFile(L"BLA1:",...) to communicate with your driver. Read MSDN for more.
I have those entries in the registry and my DLL exports those functions.
However, I can not get the DLL to start through ActivateDeviceEx or ActivateDevice. If I reset the device the device freezes and requires a hard reset.
My DLL works fine in Services.exe but must need some changes to operate in Device.exe. The problem being that I can't find any examples where a Device Driver was written in C++ (all .c) and also can't find any examples of a Service being converted to a Device driver.
Any suggestions greatly appreciated
You don't need to call ActivateDexice[Ex] if you have manually added these keys to registry. The reason that your device hangs is in your DLL's entry point or in one of the exported functions. Probably BLA_Init or one of the power functions. You should add diagnostics code that outputs a trace log to SD-card or built-in storage so that you can read this file after hard reset. Or the reason may be that your driver is loaded before the one of the needed drivers, for example SD-card. In this case you should play with the "order" key.
I've wrote several drivers in C++. But none of them used C++ exceptions, I don't know how devices.exe would behave if exception is thrown. And you should remember not to allocate huge arrays/variables on stack.
I've found a small tutorial on MSDN - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnembedded/html/spotwincerambl.asp
Posted: Wed Mar 09, 2005 18:19
--------------------------------------------------------------------------------
So if I already have the registry entries in do I start the DLL with CreateFile or something similar? I assumed that the DLL was hanging on device startup due to attempting to include an unloaded module but this still occurs when setting Order to 99.
At the moment for testing purposes I am just getting all my exported functions to write to a log file... however none are ever entered. What is the DLL's entry point? Init? PowerUp? An additional method? Have you an example that I could possibly have a look at?
Thanks for your help.
Gerard
The first entry point is DllMain. Then init function is called. Then open when your device is opened. If you have global classes with constructors - constructors are called before DllMain (I have not tested that), one of them may be the reason of crash.
The sample is in the link I gave in the prev. post. or here is a sample driver that is a wrapper around Serial_BTUR.dll
Code:
// Serial.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "Serial.h"
#include <psapi.h>
#include <Mmsystem.h>
struct HCI_
{
char *Text;
int Code;
} Cmds[]=
{
"HCI_NOP",0x0000,
"HCI_Inquiry",0x0401,
"HCI_Inquiry_Cancel",0x0402,
"HCI_Periodic_Inquiry_Mode",0x0403,
"HCI_Exit_Periodic_Inquiry_Mode",0x0404,
"HCI_Create_Connection",0x0405,
"HCI_Disconnect",0x0406,
"HCI_Add_SCO_Connection",0x0407,
"HCI_Accept_Connection_Request",0x0409,
"HCI_Reject_Connection_Request",0x040a,
"HCI_Link_Key_Request_Reply",0x040b,
"HCI_Link_Key_Request_Negative_Reply",0x040c,
"HCI_PIN_Code_Request_Reply",0x040d,
"HCI_PIN_Code_Request_Negative_Reply",0x040e,
"HCI_Change_Connection_Packet_Type",0x040f,
"HCI_Authentication_Requested",0x0411,
"HCI_Set_Connection_Encryption",0x0413,
"HCI_Change_Connection_Link_Key",0x0415,
"HCI_Master_Link_Key",0x0417,
"HCI_Remote_Name_Request",0x0419,
"HCI_Read_Remote_Supported_Features",0x041b,
"HCI_Read_Remote_Version_Information",0x041d,
"HCI_Read_Clock_Offset",0x041f,
"HCI_Hold_Mode",0x0801,
"HCI_Sniff_Mode",0x0803,
"HCI_Exit_Sniff_Mode",0x0804,
"HCI_Park_Mode",0x0805,
"HCI_Exit_Park_Mode",0x0806,
"HCI_QoS_Setup",0x0807,
"HCI_Role_Discovery",0x0809,
"HCI_Switch_Role",0x080b,
"HCI_Read_Link_Policy_Settings",0x080c,
"HCI_Write_Link_Policy_Settings",0x080d,
"HCI_Set_Event_Mask",0x0c01,
"HCI_Reset",0x0c03,
"HCI_Set_Event_Filter",0x0c05,
"HCI_Flush",0x0c08,
"HCI_Read_PIN_Type",0x0c09,
"HCI_Write_PIN_Type",0x0c0a,
"HCI_Create_New_Unit_Key",0x0c0b,
"HCI_Read_Stored_Link_Key",0x0c0d,
"HCI_Write_Stored_Link_Key",0x0c11,
"HCI_Delete_Stored_Link_Key",0x0c12,
"HCI_Change_Local_Name",0x0c13,
"HCI_Read_Local_Name",0x0c14,
"HCI_Read_Connection_Accept_Timeout",0x0c15,
"HCI_Write_Connection_Accept_Timeout",0x0c16,
"HCI_Read_Page_Timeout",0x0c17,
"HCI_Write_Page_Timeout",0x0c18,
"HCI_Read_Scan_Enable",0x0c19,
"HCI_Write_Scan_Enable",0x0c1a,
"HCI_Read_PageScan_Activity",0x0c1b,
"HCI_Write_PageScan_Activity",0x0c1c,
"HCI_Read_InquiryScan_Activity",0x0c1d,
"HCI_Write_InquiryScan_Activity",0x0c1e,
"HCI_Read_Authentication_Enable",0x0c1f,
"HCI_Write_Authentication_Enable",0x0c20,
"HCI_Read_Encryption_Mode",0x0c21,
"HCI_Write_Encryption_Mode",0x0c22,
"HCI_Read_Class_Of_Device",0x0c23,
"HCI_Write_Class_Of_Device",0x0c24,
"HCI_Read_Voice_Setting",0x0c25,
"HCI_Write_Voice_Setting",0x0c26,
"HCI_Read_Automatic_Flush_Timeout",0x0c27,
"HCI_Write_Automatic_Flush_Timeout",0x0c28,
"HCI_Read_Num_Broadcast_Retransmissions",0x0c29,
"HCI_Write_Num_Broadcast_Retransmissions",0x0c2a,
"HCI_Read_Hold_Mode_Activity",0x0c2b,
"HCI_Write_Hold_Mode_Activity",0x0c2c,
"HCI_Read_Transmit_Power_Level",0x0c2d,
"HCI_Read_SCO_Flow_Control_Enable",0x0c2e,
"HCI_Write_SCO_Flow_Control_Enable",0x0c2f,
"HCI_Set_Host_Controller_To_Host_Flow_Control",0x0c31,
"HCI_Host_Buffer_Size",0x0c33,
"HCI_Host_Number_Of_Completed_Packets",0x0c35,
"HCI_Read_Link_Supervision_Timeout",0x0c36,
"HCI_Write_Link_Supervision_Timeout",0x0c37,
"HCI_Read_Number_Of_Supported_IAC",0x0c38,
"HCI_Read_Current_IAC_LAP",0x0c39,
"HCI_Write_Current_IAC_LAP",0x0c3a,
"HCI_Read_Page_Scan_Period_Mode",0x0c3b,
"HCI_Write_Page_Scan_Period_Mode",0x0c3c,
"HCI_Read_Page_Scan_Mode",0x0c3d,
"HCI_Write_Page_Scan_Mode",0x0c3e,
"HCI_Read_Local_Version_Information",0x1001,
"HCI_Read_Local_Supported_Features",0x1003,
"HCI_Read_Buffer_Size",0x1005,
"HCI_Read_Country_Code",0x1007,
"HCI_Read_BD_ADDR",0x1009,
"HCI_Read_Failed_Contact_Counter",0x1401,
"HCI_Reset_Failed_Contact_Counter",0x1402,
"HCI_Get_Link_Quality",0x1403,
"HCI_Read_RSSI",0x1405,
"HCI_Read_Loopback_Mode",0x1801,
"HCI_Write_Loopback_Mode",0x1802,
"HCI_Enable_Device_Under_Test_Mode",0x1803,
0,0
},Events[]=
{
"HCI_Inquiry_Complete_Event",0x01,
"HCI_Inquiry_Result_Event",0x02,
"HCI_Connection_Complete_Event",0x03,
"HCI_Connection_Request_Event",0x04,
"HCI_Disconnection_Complete_Event",0x05,
"HCI_Authentication_Complete_Event",0x06,
"HCI_Remote_Name_Request_Complete_Event",0x07,
"HCI_Encryption_Change_Event",0x08,
"HCI_Change_Connection_Link_Key_Complete_Event",0x09,
"HCI_Master_Link_Key_Complete_Event",0x0a,
"HCI_Read_Remote_Supported_Features_Complete_Event",0x0b,
"HCI_Read_Remote_Version_Information_Complete_Event",0x0c,
"HCI_QoS_Setup_Complete_Event",0x0d,
"HCI_Command_Complete_Event",0x0e,
"HCI_Command_Status_Event",0x0f,
"HCI_Hardware_Error_Event",0x10,
"HCI_Flush_Occured_Event",0x11,
"HCI_Role_Change_Event",0x12,
"HCI_Number_Of_Completed_Packets_Event",0x13,
"HCI_Mode_Change_Event",0x14,
"HCI_Return_Link_Keys_Event",0x15,
"HCI_PIN_Code_Request_Event",0x16,
"HCI_Link_Key_Request_Event",0x17,
"HCI_Link_Key_Notification_Event",0x18,
"HCI_Loopback_Command_Event",0x19,
"HCI_Data_Buffer_Overflow_Event",0x1a,
"HCI_Max_Slots_Change_Event",0x1b,
"HCI_Read_Clock_Offset_Complete_Event",0x1c,
"HCI_Connection_Packet_Type_Changed_Event",0x1d,
"HCI_QoS_Violation_Event",0x1e,
"HCI_Page_Scan_Mode_Change_Event",0x1f,
"HCI_Page_Scan_Repetition_Mode_Change_Event",0x20,
0,0
};
char *FindEvent(int id)
{
for(int i=0; Events[i].Text;i++)
{
if(Events[i].Code==id)
return Events[i].Text;
}
return "HCI_???";
}
char *FindMessage(int id)
{
for(int i=0; Cmds[i].Text;i++)
{
if(Cmds[i].Code==id)
return Cmds[i].Text;
}
return "HCI_???";
}
typedef BOOL t_COM_Deinit(DWORD dwOpenData);
typedef BOOL t_COM_IOControl(
DWORD dwOpenData,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut
);
typedef HANDLE t_COM_Init(
ULONG Identifier
);
typedef HANDLE t_COM_Open(
HANDLE pContext,
DWORD AccessCode,
DWORD ShareMode
);
typedef BOOL t_COM_PowerDown(
HANDLE pContext
);
typedef BOOL t_COM_PowerUp(
HANDLE pContext
);
typedef ULONG t_COM_Read(
HANDLE pContext,
PUCHAR pTargetBuffer,
ULONG BufferLength
);
typedef ULONG t_COM_Write(
HANDLE COM_Write,
PUCHAR pSourceBytes,
ULONG NumberOfBytes
);
typedef BOOL t_COM_Close(
DWORD pContext
);
t_COM_Deinit *_COM_Deinit=0;
t_COM_IOControl *_COM_IOControl=0;
t_COM_Init *_COM_Init=0;
t_COM_Open *_COM_Open=0;
t_COM_PowerDown *_COM_PowerDown=0;
t_COM_PowerUp *_COM_PowerUp=0;
t_COM_Read *_COM_Read=0;
t_COM_Write *_COM_Write=0;
t_COM_Close *_COM_Close=0;
HANDLE hEvent=0;
char* Dump(const unsigned char *Buff, int count)
{
static char Out[65536];
char* p=Out;
if(count==0)
{
p+=sprintf(p,"\n");
return Out;
}
{
bool OnlyASCII=true;
for(int i=0; i<count; i++)
if((Buff[i]&255)<32||Buff[i]==127)
{
if((i==count-1 && Buff[i]==0)||Buff[i]==0x0d||Buff[i]==0x0a||Buff[i]==9)
continue;
OnlyASCII=false;
break;
}
if(OnlyASCII)
{
p+=sprintf(p,"--- Plain text\n");
for(int i=0; i<count; i++)
if(Buff[i]!='\r')
p+=sprintf(p,"%c",Buff[i]);
// if(Buff[count-1]!='\n')
// fprintf(Log,"\n");
p+=sprintf(p,"\n--- End of text\n\n");
return Out;
}
int Pos=0;
char OBuff[3*16+2+1];
char Str[17];
for(i=0; i<(count+15)/16; i++)
{
for(int j=0; j<16; j++,Pos++)
{
if(Pos<count)
{
sprintf(OBuff+3*j+(j>7),"%02X ",Buff[Pos]&255);
if((Buff[Pos]&255)<32||Buff[Pos]==127)
Str[j]='.';
else
Str[j]=Buff[Pos];
} else
{
sprintf(OBuff+3*j+(j>7)," ");
Str[j]=' ';
}
}
Str[16]=0;
OBuff[3*16+1]=0;
p+=sprintf(p,"%08X: %s \"%s\"\n",i*16,OBuff,Str);
}
}
p+=sprintf(p,"\n");
return Out;
}
bool IsLogging(void)
{
return true;
// return WaitForSingleObject(hEvent,0)==WAIT_OBJECT_0;
}
void LogData(PUCHAR Data, int NBytes)
{
if(!IsLogging())
return;
HANDLE h=CreateFile(L"\\logging.txt",GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,
0,OPEN_ALWAYS,0,0);
if(h==INVALID_HANDLE_VALUE)
return;
SetFilePointer(h,0,0,FILE_END);
DWORD W;
WriteFile(h,Data,NBytes,&W,0);
CloseHandle(h);
}
void LogStr(char*Str)
{
LogData((PUCHAR)Str, strlen(Str));
LogData((PUCHAR)"\n",1);
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#undef SERIAL_API
#define SERIAL_API extern "C" __declspec(dllexport)
SERIAL_API BOOL COM_Close(
DWORD pContext
)
{
LogStr("COM_Close");
return _COM_Close(pContext);
}
SERIAL_API BOOL COM_Deinit(DWORD pContext)
{
LogStr("COM_Deinit");
return _COM_Deinit(pContext);
}
SERIAL_API BOOL COM_IOControl(
DWORD dwOpenData,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut
)
{
char Buff[1024];
sprintf(Buff,"COM_IOControl: %04X ",dwCode);
LogStr(Buff);
LogStr(Dump(pBufIn,dwLenIn));
return _COM_IOControl(
dwOpenData,
dwCode,
pBufIn,
dwLenIn,
pBufOut,
dwLenOut,
pdwActualOut);
}
SERIAL_API HANDLE COM_Init(
wchar_t* Identifier
)
{
LogStr("COM_Init");
if(hEvent==0)
{
hEvent=CreateEvent(0,TRUE,FALSE,L"seRILal logging event");
HINSTANCE H=LoadLibrary(L"Serial_BTUR.dll");
if(H==0)
{
LogStr("Error loading DLL");
return 0;
}
_COM_Deinit=(t_COM_Deinit*)GetProcAddress(H,L"COM_Deinit");
if(_COM_Deinit==0)
LogStr("COM_Deinit==0");
_COM_IOControl=(t_COM_IOControl*)GetProcAddress(H,L"COM_IOControl");
if(_COM_IOControl==0)
LogStr("COM_IOControl==0");
_COM_Init=(t_COM_Init*)GetProcAddress(H,L"COM_Init");
if(_COM_Init==0)
LogStr("COM_Init==0");
_COM_Open=(t_COM_Open*)GetProcAddress(H,L"COM_Open");
if(_COM_Open==0)
LogStr("COM_Open==0");
_COM_PowerDown=(t_COM_PowerDown*)GetProcAddress(H,L"COM_PowerDown");
if(_COM_PowerDown==0)
LogStr("COM_PowerDown==0");
_COM_PowerUp=(t_COM_PowerUp*)GetProcAddress(H,L"COM_PowerUp");
if(_COM_PowerUp==0)
LogStr("COM_PowerUp==0");
_COM_Read=(t_COM_Read*)GetProcAddress(H,L"COM_Read");
if(_COM_Read==0)
LogStr("COM_Read==0");
_COM_Write=(t_COM_Write*)GetProcAddress(H,L"COM_Write");
if(_COM_Write==0)
LogStr("COM_Write==0");
_COM_Close=(t_COM_Close*)GetProcAddress(H,L"COM_Close");
if(_COM_Close==0)
LogStr("COM_Close==0");
LogStr("DLL loaded");
}
HANDLE H=_COM_Init((DWORD)Identifier);
return H;
}
SERIAL_API HANDLE COM_Open(
HANDLE pContext,
DWORD AccessCode,
DWORD ShareMode
)
{
LogStr("COM_Open");
return _COM_Open(
pContext,
AccessCode,
ShareMode);
}
SERIAL_API BOOL COM_PowerDown(
HANDLE pContext
)
{
LogStr("COM_PowerDown");
return _COM_PowerDown(pContext);
}
SERIAL_API BOOL COM_PowerUp(
HANDLE pContext
)
{
LogStr("COM_PowerUp");
return _COM_PowerUp(pContext);
}
int SCO_Handle=0;
SERIAL_API ULONG COM_Read(
HANDLE pContext,
PUCHAR pTargetBuffer,
ULONG BufferLength
)
{
int L=_COM_Read(
pContext,
pTargetBuffer,
BufferLength);
if(L)
{
LogStr("COM_Read");
if(L>2&&pTargetBuffer[0]==4)
{
char Buff[1024];
int m=pTargetBuffer[1];
sprintf(Buff,"%s - %02X",FindEvent(m),m);
LogStr(Buff);
if(pTargetBuffer[1]==3 && pTargetBuffer[3]==0 && pTargetBuffer[12]==0)
{
LogStr("SCO connection");
SCO_Handle=pTargetBuffer[4]+pTargetBuffer[5]*256;
}
}
LogStr(Dump(pTargetBuffer,L));
}
return L;
}
SERIAL_API ULONG COM_Write(
HANDLE pContext,
PUCHAR pSourceBytes,
int NumberOfBytes
)
{
LogStr("COM_Write");
if(SCO_Handle)
{
LogStr("sending SCO packet");
char Buffer[256];
Buffer[0]=SCO_Handle&255;
Buffer[1]=SCO_Handle/255;
Buffer[2]=240;
for(int i=0; i<240; i++)
Buffer[3+i]=(i&2)?127:0;
_COM_Write(
pContext,
(unsigned char*)"\x03",
1);
_COM_Write(
pContext,
(unsigned char*)Buffer,
240+3);
SCO_Handle=0;
}
if(NumberOfBytes>2)
{
char Buff[1024];
int m=pSourceBytes[1]*256+pSourceBytes[0];
sprintf(Buff,"%s - %04X",FindMessage(m),m);
LogStr(Buff);
}
LogStr(Dump(pSourceBytes,NumberOfBytes));
return _COM_Write(
pContext,
pSourceBytes,
NumberOfBytes);
}
SERIAL_API ULONG COM_Seek()
{
return -1;
}
Thanks for your help. The reason I am porting my Dll from Services.exe to Device.exe is because I need it to run continuosly and when running in Services.exe when the device suspends of course no CPU time. That is, I was hoping to implement the Dll as a driver and catch the PowerDown message and prevent it from happening.
I noticed that in the MSDN example the PowerDown method is void but in yours it returns Bool. To prevent the power down do I convert the method to return a false bool value? Can this functionality be done?
Regards Gerard
GerardRaciti said:
I noticed that in the MSDN example the PowerDown method is void but in yours it returns Bool.
Click to expand...
Click to collapse
Don't always trust MSDN regarding Windows CE. I've taken these prototypes from some of MS own drivers.
You can prevent device from sleeping from your program using this method:
http://msdn.microsoft.com/library/d.../html/ppc_programming_pocket_pc_2002_lfyy.asp
That was the method I used originally to tackle this problem but it consumed too much power leaving the screen in that dimmed state.
I had the understanding that if I implemented my Dll in a device driver the screen could go blank but the device would only go into "sleep" mode where drivers would still receive CPU time as long as they responded to the PowerDown function.
Do you know if this is possible or am I wasting my time?
I don't know. I never worked with power levels. But probably this is possible in driver with functions SetPowerRequirement and DevicePowerNotify. But this would work only if device supports D1 (low on) power mode. Otherwise I think you would not notice any difference with keeping the device always on and shutting down LCD+backlight.
Thanks again for your help.
I have managed to port my service into a device driver but am having trouble handling Power Management issues. It seems as though it is in my Dll attempting to prevent a device suspension which is crashing the device. If I dont attempt to prevent suspend mode or set power requirements the Dll is quite stable. If anyone has any experience with Device driver power management or can point me in the right direction it would be much appreciated.
Regards Gerard
you may try to ask in microsoft newsgroups like microsoft.public.windowsce.app.development or microsoft.public.windowsce.platbuilder or similar

help to intialize - RIL initialize ??

Hey, i'm trying to Use some RIL functions in an MFC application. However i dont understand how to initialize it (RIL_Initialize) could i get some help ??? I'm trying to write an app which would change the PIN code of the SIM card as described in the RIL patent. Using this function.
HRESULT RIL_ChangeLockingPassword(
HRIL hRil,
DWORD dwFacility,
LPCSTR lpszOldPassword,
LPCSTR lpszNewPassword
);
My problem is the HRIL hRil , @parm handle to RIL instance returned by <f RIL_Initialize>
No too sure how to do it !!! Need Help !!!!
static void CALLBACK s_Notify(DWORD dwCode,
const void *lpData,
DWORD cbData,
DWORD dwParam);
static void CALLBACK s_Result(DWORD dwCode,
HRESULT hrCmdID,
const void *lpData,
DWORD cbData,
DWORD dwParam);
HRIL hRil;
HRESULT hr = RIL_Initialize(1, s_Result, s_Notify, 0xFFFFFFFF, NULL, &hRil);
OK thanks.
Question 1:
------------
What values would HRESULT hr variable take ?? ( what value will i get if i print it out )
Question 2:
------------
When the functions says , @parm handle to RIL instance returned by <f RIL_Initialize> , does that mean it should be the returned parameter hr ?? or the hRil ?? What is the difference ??
Thanks for your help!
for most functions returning a HRESULT, you have to check if the HRESULT contains an error, using IS_ERROR(hr).
other wise hr contains a function result identifier, for which the function results are returned back to your application via the RILRESULTCALLBACK function passed to RIL_Initialize. ... in the hrCmdID parameter.
see RilClass.cpp for an example.
willem
Thanks for the link , it helps quite a bit ... Now to use a practical example , i want to use the RIL_GetEquipmentInfo() function.
Code:
// Notify and Result Call back functions
void CALLBACK OnNotifyCallback(DWORD dwCode, const void *lpData, DWORD cbData, DWORD dwParam)
{
}
void CALLBACK OnResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *lpData, DWORD cbData, DWORD dwParam)
{
}
// RIL initialize and GetEquipment Info
result = ::RIL_Initialize(1, OnResultCallback, OnNotifyCallback, dwNotificationClasses, g_dwParam, &g_hRil);
if (result)
{
IS_ERROR(result);
return false;
}
HRESULT test = RIL_GetEquipmentInfo(g_hRil);
Now i want to print the result from the RIL_GetEquipement Info !!! The answer should be HTC. I thought i would just need to wsprintf test however it does not print what i want. Could you help me out ? I think i'm missing something really.
Thank you for your help, i'm new to this , i'm trying to understand.
RIL_GetEquipmentInfo() is async function
after operation will complete ResultCallback will be called by RIL
1)check dwCode it must be RIL_RESULT_OK
2)check hrCmdID it must be equal to return value of RIL_GetEquipmentInfo()
3)lpData is pointer to RILEQUIPMENTINFO (you must convert void* to LPRILEQUIPMENTINFO)

RIL

Hi there,
I begin to learn RIL functions (i work i-mate sp3i).
I'm stuck with RIL_Initialize returning a NULL handle .... ??? :?
Hvoid RilResultCallback(
DWORD dwCode, // @parm result code
HRESULT hrCmdID, // @parm ID returned by the command that originated>
const void* lpData, // @parm data associated with the notification
DWORD cbData, // @parm size of the strcuture pointed to lpData
DWORD dwParam // @parm parameter passed to <f RIL_Initialize>
)
{
}
void RilNotifyCallback(
DWORD dwCode, // @parm notification code
const void* lpData, // @parm data associated with the notification
DWORD cbData, // @parm size of the strcuture pointed to lpData
DWORD dwParam // @parm parameter passed to <f RIL_Initialize>
)
{
}
void fn()
{
HRIL hRil;
RIL_Initialize(1, RilResultCallback, RilNotifyCallback,
0, 0, &hRil);
if(hRil == NULL)
{
AfxMessageBox(L"hRil == NULL");
}else AfxMessageBox(L"hRil != NULL");
}
I don't understand what the problem is???
Thanks for any help.
what is the result code?
rc= RIL_Initialize( ... )
willem
if i understand you the question right, the result is:
rc=RIL_Initialize(1, RilResultCallback, RilNotifyCallback,
0, 0, &hRil);
hRil==0 , rc == 8........
tstril -- Answers too
8 is a very strange result value for RIL_Initialize.
the only possible answers i see are:
0x80070057 for invalid parameter
0x8007000E or 0x80004005 or 1
... ah, when you specify a notifyproc, you do have to specify some notificationclasses to go with it. .. the 4th param should not be 0 when notifyproc !=NULL
willem
I a beginner if am possible on more in detail,
and the full answer 0x80004005
thankful in advance
maybe your phone is in flightmode?
.. this error means ril did not initialize properly.
willem
Thanks all. I have understood. The certificate is necessary.

iTask development need help with dll files

Hi! I'm pretty stuck with developing more useful things for iTask so I'm entering the dark and dangerous world of c++.
I don't know anything about eMbedded VisualC++, so I hope someone here can help me get some more information out of the ppc, like free memory, storage, signal, etc, if it is easy and possible.
The flash command to read this is "GetPowerStatus". So that must be changed to something new in the script.
Hopeful for any answer!
This is the sample file that comes with bryht flashapp for importing battery percent info. It works.
if you need the evc files as well please post.
Here's the script:
#include "stdafx.h"
#include "plugin.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
const char *g_command[] = {
"GetPowerStatus",
NULL,
};
SETVARIABLE SetVariable = NULL;
FLASHAPPPLUGIN_API const char** WINAPI RegisterCommand(SETVARIABLE pSetVariable)
{
SetVariable = pSetVariable;
return g_command;
}
FLASHAPPPLUGIN_API int DoCommand(HWND hWnd, const char*cmd, const char*params, int argc, char* argv[])
{
if( _stricmp( cmd, "GetPowerStatus" ) == 0 )
{
#ifdef _WIN32_WCE
SYSTEM_POWER_STATUS_EX sp;
memset( &sp, 0, sizeof(sp));
GetSystemPowerStatusEx( &sp, TRUE );
#else //for windows desktop version
SYSTEM_POWER_STATUS sp;
memset( &sp, 0, sizeof(sp));
GetSystemPowerStatus( &sp, TRUE );
#endif
//send the value to Flash
char value[32];
sprintf( value, "%d", sp.BackupBatteryLifePercent );
if( argc>0 && argv[0]!= 0 )
SetVariable( argv[0], value );
}
return FLASHAPP_OK;
}

problem with injection DLL to specified process

Save me from madness!!!
I have a several smartphone devices with windows CE
CE 6.0 - hp IPAQ 500 series
CE 5.0 - Samsung i600
I need to inject DLL into the process "home.exe". I use method with performcallback4 function. This method works successfully for all processes ("device.exe", "service.exe", etc.) except process "home.exe". In what a problem?
source code : InjectDLL.exe link with toolhelp.lib
#include <windows.h>
#include <Tlhelp32.h>
typedef struct _CALLBACKINFO {
HANDLE hProc;
FARPROC pfn;
PVOID pvArg0;
} CALLBACKINFO;
extern "C"
{
DWORD PerformCallBack4(CALLBACKINFO *pcbi,...);
LPVOID MapPtrToProcess(LPVOID lpv, HANDLE hProc);
BOOL SetKMode(BOOL fMode);
DWORD SetProcPermissions(DWORD newperms);
};
DWORD GetProcessId(WCHAR *wszProcessName)
{
HANDLE hTH= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe;
pe.dwSize= sizeof(PROCESSENTRY32);
DWORD PID=0;
if (Process32First(hTH, &pe))
{
do {
if (wcsicmp(wszProcessName, pe.szExeFile)==0)
{
PID=pe.th32ProcessID;
}
} while (Process32Next(hTH, &pe));
}
CloseToolhelp32Snapshot(hTH);
return PID;
}
HMODULE GetDllHandle(DWORD ProcessId,WCHAR* ModuleName)
{
HANDLE ToolHelp=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,ProcessId);
if (ToolHelp!=INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry={sizeof MODULEENTRY32};
if (Module32First(ToolHelp,&ModuleEntry))
do
{
if (wcsicmp(ModuleEntry.szModule, ModuleName)==0)
return ModuleEntry.hModule;
}
while(Module32Next(ToolHelp,&ModuleEntry));
CloseToolhelp32Snapshot(ToolHelp);
}
return NULL;
}
BOOL InjectDll(WCHAR* ProcessName,WCHAR* ModuleName)
{
DWORD ProcessId=GetProcessId(ProcessName);
HMODULE ModuleHandle=GetDllHandle(ProcessId,ModuleName);
if (ModuleHandle!=NULL)
return TRUE;
HANDLE Process=OpenProcess(0,0,ProcessId);
if (Process==NULL)
return FALSE;
void* ModuleNamePtr=MapPtrToProcess(ModuleName,GetCurrentProcess());
if (ModuleNamePtr==NULL)
return FALSE;
CALLBACKINFO ci;
ci.hProc=Process;
void* LoadLibraryPtr=MapPtrToProcess(GetProcAddress(GetModuleHandle(L"coredll.dll"),L"LoadLibraryW"),Process);
if (LoadLibraryPtr==NULL)
return FALSE;
ci.pfn=(FARPROC)LoadLibraryPtr;
ci.pvArg0=ModuleNamePtr;
PerformCallBack4(&ci); in this place process exit. visual studio output message : "process exit with code 0xc0000030"
Sleep(500);
CloseHandle(Process);
return GetDllHandle(ProcessId,ModuleName)!=NULL;
}
extern "C"
{
BOOL SetKMode(BOOL fMode);
DWORD SetProcPermissions(DWORD newperms);
};
#define DLLNAME L"MyDll.dll"
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd)
{
WCHAR Path[MAX_PATH];
GetModuleFileName(NULL,Path,MAX_PATH);
wcscpy(wcsrchr(Path,L'\\')+1,DLLNAME);
WCHAR NewPath[MAX_PATH]=L"\\Windows\\";
wcscat(NewPath,DLLNAME);
CopyFile(Path,NewPath,FALSE);
BOOL Res=InjectDll(L"home.exe",L"MyDll.dll");
return 0;
}
the error code is
#define STATUS_INVALID_PARAMETER_MIX 0xC0000030
(maybe too fast for getting the thread infos?)
try to make the "Sleep(500);" before "PerformCallBack4(&ci);"
I have tried, a problem not in it. Any ideas?
I have not found the reason.... I Use other method without performcallback4
Problem with injection dll to cprog.exe process?
I want to inject dll to cprog.exe process. but it doesn't work.
source code.
Code:
VOID
InjectDllToCprog()
{
WCHAR DllPath[MAX_PATH] = L"";
CallbackInfo ci;
GetModuleFileName(NULL, DllPath, MAX_PATH);
PWCHAR p = wcsrchr(DllPath, L'\\');
DllPath[p - DllPath] = '\0';
wcscat(DllPath, L"\\CprogInject.dll");
ZeroMemory(&ci, sizeof(ci));
g_hCprog = FindCprogProcess(L"Cprog.exe"); // the handle is right.
if(g_hCprog != NULL)
{
DWORD dwMode = SetKMode(TRUE);
DWORD dwPerm = SetProcPermissions(0xFFFFFFFF);
FARPROC pFunc = GetProcAddress(GetModuleHandle(L"Coredll.dll"), L"LoadLibraryW");
ci.ProcId = (HANDLE)g_hCprog;
ci.pFunc = (FARPROC)MapPtrToProcess(pFunc, g_hCprog);
ci.pvArg0 = MapPtrToProcess(DllPath, GetCurrentProcess());
g_InjectCprog = (HINSTANCE)PerformCallBack4(&ci, 0, 0, 0);
if(GetLastError() != 0) // GetLastError() = 5
DbgError(L"PerformCallBack 执行失败", GetLastError());
SetKMode(dwMode);
SetProcPermissions(dwPerm);
}
}
GetLastError() return 0x00000005(Access is denied)
Anyone can help me? Sorry for my poor english.

Categories

Resources