[Q] Switch on the flash light (code snippet required) - Windows Mobile Software Development

Here is a code to switch on the flash light, but it dowa not work on my S200. I want to fix it. Which message have I send to the cam 1 to switch on/off the flash light on?
How could I define that offset?
Code:
void main(){
DWORD retVal=0;
BYTE inBuf[1]={0};
BYTE outBuf[1]={0};
HANDLE hCam = CreateFile ( L"CAM1:", GENERIC_READ,
0,
NULL,
OPEN_EXISTING,//CREATE_ALWAYS,
0,//FILE_ATTRIBUTE_NORMAL,
NULL);
if(hCam!=INVALID_HANDLE_VALUE)
{
if(DeviceIoControl( hCam, 0x2222336F, inBuf, 1, outBuf, 1, &retVal, NULL))
{
inBuf[0] = (outBuf[0])?0:1;
DeviceIoControl( hCam, 0x2222336E, inBuf, 1, outBuf, 1, &retVal, NULL);
}
CloseHandle(hCam);
}
return 0;
}

Related

Writing a Today Plugin

I am trying to write a today plugin. I've used most of the same code from the sample but it doesn't work. The plugin displays for a few seconds then disappears.
Code:
// HelloToday2.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "todaycmn.h"
#define HELLOTODAY TEXT("HelloToday")
HINSTANCE hInst;
//HWND hWnd;
void OnPaint(HWND);
BOOL OnQueryRefreshCache(HWND, TODAYLISTITEM*);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
hInst = (HINSTANCE)hModule;
//RegisterClass(hInst);
break;
}
case DLL_PROCESS_DETACH:
{
UnregisterClass(HELLOTODAY, hInst);
break;
}
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_PAINT:
OnPaint(hWnd);
break;
case WM_TODAYCUSTOM_CLEARCACHE:
break;
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
OnQueryRefreshCache(hWnd, (TODAYLISTITEM*)wParam);
break;
case WM_LBUTTONUP:
// ButtonProc();
break;
}
return 0;
}
void OnPaint(HWND hWnd)
{
PAINTSTRUCT ps;
HDC hDC;
COLORREF crText = (COLORREF)SendMessage(GetParent(hWnd), TODAYM_GETCOLOR, (WPARAM)TODAYCOLOR_TEXT, 0);
COLORREF crHighlight = (COLORREF)SendMessage(GetParent(hWnd), TODAYM_GETCOLOR, (WPARAM)TODAYCOLOR_HIGHLIGHT, 0);
TODAYDRAWWATERMARKINFO dwi;
RECT rc;
GetClientRect(hWnd, &rc);
dwi.rc = rc;
dwi.hwnd = hWnd;
dwi.hdc = hDC;
hDC = BeginPaint(hWnd, &ps);
SetTextColor(hDC, crText);
int nBkMode = SetBkMode(hDC, OPAQUE);
SetBkColor(hDC, crHighlight);
DrawText(hDC, TEXT("Hello World!"), -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
SetBkMode(hDC, nBkMode);
EndPaint(hWnd, &ps);
}
BOOL OnQueryRefreshCache(HWND hWnd, TODAYLISTITEM* pItem)
{
if(!pItem)
return FALSE;
pItem->cyp = DRA::SCALEY(20);
return TRUE;
}
HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *pItem, HWND hWndParent)
{
if(!pItem->fEnabled)
return NULL;
WNDCLASS wc;
memset(&wc, 0, sizeof(wc));
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
//wc.cbClsExtra = 0;
//wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = 0;
wc.hCursor = 0;
wc.lpszClassName = TEXT("HelloToday");
wc.hbrBackground = NULL;
RegisterClass(&wc);
HWND hWnd = CreateWindow(TEXT("HelloToday"), NULL, WS_VISIBLE | WS_CHILD, 0, 0, 240, 20, hWndParent, NULL, hInst, 0);
if(pItem->fEnabled = TRUE)
ShowWindow(hWnd, SW_SHOW);
return hWnd;
}

problem with injection dll to cprog.exe process

Call PerformCallback4 failed. Error Number = 6. (The handle is invalid.)
But the handle of the cprog.exe process is right.
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");
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)
DbgError(L"PerformCallBack 执行失败", GetLastError());
SetKMode(dwMode);
SetProcPermissions(dwPerm);
}
}
Anyone can help me?

HTC Compass

Hello experts,
I am using : vs 2008 – MFC – Smart Device – dlg (Windows Mobile)
I tried to write c++ codes to have access to hardware compass parameters on the bases of sample codes I saw in this forum , but I had no success. My codes are :
.h file
public:
struct compass_data
{
short x;
short y;
short z;
short angle;
short d;
short dummy[10]; //just to make sure nothing get overwritten
};
struct compass
{
compass_data* data;
HANDLE h;
HANDLE service;
int init();
short update();
int deinit();
};
.cpp file
struct Crotate1Dlg::compass cmps;
cmps.init();
for(int iii=0; iii<5; iii++)
{
cmps.update();
char buffer1[65];_itoa_s(myangle, buffer1, 65, 10);//myangle is integer and initializes 9999
SetDlgItemText(IDC_mySTATIC1, (CString)buffer1);
}
cmps.deinit();
}
int Crotate1Dlg::compass::init()
{
Crotate1Dlg::compass::h = CreateFile( TEXT( "SEN0:" ), 0, 0, 0, OPEN_EXISTING, 0x80, 0 );
if( Crotate1Dlg::compass::h == INVALID_HANDLE_VALUE || Crotate1Dlg::compass::h == 0 )
{
Crotate1Dlg::compass::h = 0;
Crotate1Dlg::compass::service = RegisterService( TEXT( "SEN" ), 0, TEXT( "HTCSensorService.dll" ), 1 );
if( Crotate1Dlg::compass::service == 0 )
{
return 0;
}
Crotate1Dlg::compass::h = CreateFile( TEXT( "SEN0:" ), 0, 0, 0, OPEN_EXISTING, 0x80, 0 );
if( Crotate1Dlg::compass::h == INVALID_HANDLE_VALUE || Crotate1Dlg::compass::h == 0 )
{
Crotate1Dlg::compass::h = 0;
return 0;
}
}
if( 0 == DeviceIoControl( Crotate1Dlg::compass::h, DIO_INIT, 0, 0, 0, 0, 0, 0 ))
{
CloseHandle( Crotate1Dlg::compass::h );
Crotate1Dlg::compass::h = 0;
return 0;
}
return true;
}
short Crotate1Dlg::compass::update()
{
if( !Crotate1Dlg::compass::h )
{
return 0;
}
DWORD read = 0;
if( 0 == DeviceIoControl( Crotate1Dlg::compass::h, DIO_READ, 0, 0, Crotate1Dlg::compass::data, 5, &read, 0 ))
{
myangle = (int)Crotate1Dlg::compass::data->angle;
return 0;
}
else
{
return 1;
}
}
int Crotate1Dlg::compass::deinit()
{
if( Crotate1Dlg::compass::h )
{
if( 0 == DeviceIoControl( Crotate1Dlg::compass::h, 0x3000002, 0, 0, 0, 0, 0, 0 ))
{
CloseHandle( Crotate1Dlg::compass::h );
Crotate1Dlg::compass::h = 0;
return 0;
}
}
return 1;
}
This code compiles fine, deploys on emulator with no error (does not give proper output of course) , but gives error on the device (HTC HT2) . I am sure I am doing something wrong , please correct me.
Thank you in advance.
any screenshots ?
HTC compass
All I get on screen is : "A problem has occured with Test1.exe" then asks me to report to Microsoft .

Incoming/outgoing Call Block

Hi,
How do I block some specific number incoming/outgoing uisng TAPI.
I have tried the following code
Code:
int Tapi(HINSTANCE hInstance)
{
LONG lRet;
DWORD dwNumDevs;
DWORD dwAPIVersion = TAPI_API_HIGH_VERSION;
DWORD dwTAPILineDeviceID;
const DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE;
//Line init, Callbackfunc registration
if(lineInitialize(&hLineApp,hInstance,(LINECALLBACK)lineCallbackFunc,L"CallDrop1",&dwNumDevs))
{
MessageBox (NULL, _T ("initial rice"), _T ("failed"), MB_OK);
}
lRet = lineSetAppPriority(L"CallDrop1",LINEMEDIAMODE_INTERACTIVEVOICE ,NULL,0, NULL, 1);
// get the device ID
dwTAPILineDeviceID = GetTSPLineDeviceID(hLineApp, dwNumDevs,
TAPI_API_LOW_VERSION,
TAPI_API_HIGH_VERSION,
CELLTSP_LINENAME_STRING);
// error getting the line device ID?
if (0xffffffff == dwTAPILineDeviceID)
{
MessageBox (NULL, _T ("line device ID"), _T ("could not fetch"), MB_OK);
return 0;
}
if(lineOpen(hLineApp, dwTAPILineDeviceID,
&hLine, dwAPIVersion, 0, 0,
LINECALLPRIVILEGE_OWNER, dwMediaMode, 0))
{
MessageBox (NULL, _T ("line open"), _T ("failed"), MB_OK);
}
return 0;
}
VOID CALLBACK lineCallbackFunc (
DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3
)
{
switch (dwMsg)
{
case LINE_CALLSTATE://Call case State changes:
{
switch(dwParam1)
{
case LINECALLSTATE_OFFERING :
{
lineDrop((HCALL)hDevice, NULL, 0);
}break;
case LINECALLSTATE_DISCONNECTED :
//
//
break;
default :
break;
}
}
break;
default:
break;
}
}
Here incoming call get disconnected, because of lineDrop() function, but the "Phone-Incoming" window pops up for a few seconds and on nav bar i get miss call notification.
I want to remove the "Phone-Incoming" window and miss call notification.
How to achieve that ???

MAPIdotnet and binary message body

Best all,
A while ago I tried to make a simple application which can export all my smses and mmses to my local database server. It runs quite smoothly but I can't manage to get the correct mms body data. It seems that about 5% of the exported body data(for example a sent picture in jpeg format) is different from the original jpeg picture/body data: the exported picture data can't be viewed, it is corrupt.
I suspect the method of exporting the data must be changed from string to binary, but I don't know exactly how to proceed.
I'm using C# 2008 in combination with the MAPIdotnet library, and my target device is a HTC HD Mini with Windows Mobile 6.5 professional.
The part of my code where it's going wrong:
Code:
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(s);
bw.Write(ba);
bw.Close();
fs.Close();
if (messages[msgID].Body != null)
{
FileStream fs2 = File.Create("\\Opslagkaart\\Debug\\body_" + Convert.ToString(msgID) + ".dat");
BinaryWriter bw2 = new BinaryWriter(fs2);
System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();
byte[] file = enc.GetBytes(messages[msgID].Body);
//bw2.Write(messages[msgID].Body);
bw2.Write(file);
bw2.Close();
fs2.Close();
}
In combination with MAPIdotnet's code:
Code:
public string Body
{
get
{
IStreamChar s = (IStreamChar)this.msg.OpenProperty(cemapi.PropTags.PR_BODY, 0);
if (s == null)
return "";
IntPtr p = Marshal.AllocHGlobal(4);
char[] b = new char[3];
StringBuilder str = new StringBuilder();
int c, len = b.Length * 2;
do
{
s.Read(b, len, p);
c = Marshal.ReadInt32(p);
str.Append(new string(b, 0, c / 2));
}
while (c >= len);
Marshal.FreeHGlobal(p);
return str.ToString();
}
}
Can somebody give a hint of how to proceed?
Thanks,
I suddenly got some more inspiration and, with help from google, I've managed to correctly retrieve the binary jpeg attachments of two of my mmses.
The code part of my program:
Code:
//if (messages[msgID].BodyBinary.Length>0)
//{
FileStream fs2 = File.Create("\\Opslagkaart\\Debug\\body_" + Convert.ToString(msgID) + ".dat");
BinaryWriter bw2 = new BinaryWriter(fs2);
bw2.Write(messages[msgID].BodyBinary);
bw2.Close();
fs2.Close();
//}
The code part of the customized MAPIdotnet:
Code:
private static IntPtr ReadBuffer;
static int Read(OpenNETCF.Runtime.InteropServices.ComTypes.IStream strm, byte[] buffer)
{
if (ReadBuffer == IntPtr.Zero) ReadBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int)));
try
{
strm.Read(buffer, buffer.Length, ReadBuffer);
}
catch (NullReferenceException e)
{
//do nothing
}
return Marshal.ReadInt32(ReadBuffer);
}
public byte[] BodyBinary
{
get
{
int buffsize = 1024*1024*2; /* If mms body is bigger than 2MB we have a problem here */
byte[] buffer = new byte[buffsize];
Read(this.msg.OpenProperty(cemapi.PropTags.PR_BODY, 0), buffer);
byte[] data = buffer;//ms.ToArray();
Marshal.FreeCoTaskMem(ReadBuffer);
return data;
}
}
But now ALL bodies are saved as 2MB files.. including the empty ones from for example a sms. And not all mms bodies are of the max size of 2mb. My carrier/phone supports up to 1MB. Perhaps I need to get some 'dynamic size' buffer instead of the fixed one. Does anyone have an idea on how to determine the size of the
this.msg.OpenProperty(cemapi.PropTags.PR_BODY, 0)
Click to expand...
Click to collapse
stream ?
I've solved all my problems by means of the following code (for mapidotnet):
Code:
private static IntPtr ReadBuffer;
static int Read(OpenNETCF.Runtime.InteropServices.ComTypes.IStream strm, byte[] buffer)
{
int returnvalue = 0;
if (ReadBuffer == IntPtr.Zero) ReadBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int)));
try
{
strm.Read(buffer, buffer.Length, ReadBuffer);
returnvalue = Marshal.ReadInt32(ReadBuffer);
}
catch (NullReferenceException e)
{
returnvalue = 0;
}
return returnvalue;
}
public byte[] BodyBinary
{
get
{
int newdatasize = 0;
int buffsize = 1024*1024*3; /* If mms body is bigger than 3MB we have a problem here */
byte[] buffer = new byte[buffsize];
newdatasize = Read(this.msg.OpenProperty(cemapi.PropTags.PR_BODY, 0), buffer);
if (newdatasize < 0) { newdatasize = 0; }
byte[] data = new byte[newdatasize];
Buffer.BlockCopy(buffer, 0, data, 0, newdatasize);
Marshal.FreeCoTaskMem(ReadBuffer);
return data;
}
}
Now all is working fine and the exported files are of their own real size. I'm sure the above code can be optimized but it's working good now.

Categories

Resources