HOWTO: Enable Flashlight on HTC devices - Windows Mobile Development and Hacking General

Some source code from Ateksoft!
http://www.ateksoft.com/dev/flashlight.htm

My experiments with extra brightness on the Magician have shown that MS saves this state somewhere else. If you don't change this place as well the real place (GPIO) is reset every 5 seconds or so.
Damn, my current Opera installation adds this to every post:
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }

Related

GSM modem port

Which port should I open for GSM modem?
I remember someone had posted the port allocation for different device before. Can someone shares that information again?
thanks,
- David :shock:
Code:
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HANDLE hCom;
char * xpos;
char rsltstr[5];
DWORD CellId;
int bufpos;
DCB dcb;
COMMTIMEOUTS to;
DWORD nWritten;
DWORD event;
DWORD nRead;
static char outbuf[20], buf[256];
BYTE comdevcmd[2]= {0x84, 0x00};
hCom= CreateFile(L"COM2:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hCom==NULL || hCom==INVALID_HANDLE_VALUE)
{
hCom= NULL;
return -1;
}
/* HANDLE hRil= CreateFile(L"RIL1:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hRil==NULL || hRil==INVALID_HANDLE_VALUE)
{
hRil= NULL;
return -1;
}
*/
if (!GetCommState(hCom, &dcb))
{
return -2;
}
dcb.BaudRate= CBR_115200;
dcb.ByteSize= 8;
dcb.fParity= false;
dcb.StopBits= ONESTOPBIT;
if (!SetCommState(hCom, &dcb))
{
return -3;
}
if (!EscapeCommFunction(hCom, SETDTR))
{
return -4;
}
if (!EscapeCommFunction(hCom, SETRTS))
{
return -5;
}
if (!GetCommTimeouts(hCom, &to))
{
return -6;
}
to.ReadIntervalTimeout= 0;
to.ReadTotalTimeoutConstant= 200;
to.ReadTotalTimeoutMultiplier= 0;
to.WriteTotalTimeoutConstant= 20000;
to.WriteTotalTimeoutMultiplier= 0;
if (!SetCommTimeouts(hCom, &to))
{
return -7;
}
if (!SetCommMask(hCom, EV_RXCHAR))
{
return -8;
}
DWORD rildevresult=0,nReturned=0;
// DeviceIoControl(hRil, 0x03000314L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0);
// HANDLE Ev=CreateEvent(NULL,TRUE,0,L"RILDrv_DataMode");
// SetEvent(Ev);
if (!DeviceIoControl (hCom,0xAAAA5679L, comdevcmd, sizeof(comdevcmd),0,0,0,0))
{
return -9;
}
bufpos = 0;
strcpy(outbuf,"AT+creg=2\r");
if (!WriteFile(hCom, outbuf, 10, &nWritten, NULL))
{
return -10;
}
if (nWritten != 10)
{
return -11;
}
if (!WaitCommEvent(hCom, &event, NULL))
{
return -12;
}
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -13;
}
if (nRead == 0)
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
strcpy(outbuf,"AT+creg?\r");
if (!WriteFile(hCom, outbuf, 9, &nWritten, NULL))
{
return -14;
}
if (nWritten != 9)
{
return -15;
}
if (!WaitCommEvent(hCom, &event, NULL))
{
return -16;
}
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -17;
}
if (nRead == 0)
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
puts(buf);
rildevresult = 0;
// DeviceIoControl(hRil, 0x03000318L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0);
// ResetEvent(Ev);
// CloseHandle(Ev);
// CloseHandle(hRil);
if (!EscapeCommFunction(hCom, CLRDTR))
{
return -4;
}
if (hCom!=NULL)
{
CloseHandle(hCom);
hCom= NULL;
}
return CellId;
}
the commented lines force RIL to shut up and not send its commands to modem.
To communicate with modem you should open COM2, set 115200/8/N/1, send ioctl 0xAAAA5679.
I had problems when reading data from modem. When it sends a huge block (for example an output to AT%VER command) some bytes are lost and other are changed to garbage. Maybe this is a hardware problem in my imate, because the same program worked on Rover S1 without bugs.
P.S. The code I've posted is taken from this forum.
Post subject: Re: GSM modem port
Thanks for information. I am using iMate too.
Indeed the returned data are very strange. I actually had failure for "EscapeCommFunction(hCom, SETRTS)".
Did you try to dial with a number?
I got "NO CARRIER" while issing a ATD command.
- David
Re: Post subject: Re: GSM modem port
davidchu2000 said:
Did you try to dial with a number?
I got "NO CARRIER" while issing a ATD command.
Click to expand...
Click to collapse
I use TAPI functions to establish a data call. I don't think that you can use COM1 for ATD commands and receive data after connection. Internally COM9 is used after data connection is established. But I've successfully used "ATDnumber;" to make a call. Though it is much easier to use SHMakeCall function.
Hi mamaich,
I have to port a modem application for data transfering.
I can make a call using ATD through com2. Are you saying that I cannot use the same port for data communication?
I have to use COM9 instead?
- David
I don't know. You should test this yourself. For some reason TAPI or RIL opens COM9 after data connection.
Are you able to answer a data call by listening to com2? (or thru TAPI)
- David
I answer call through TAPI without problems. You should kill cprog.exe application on the incoming data call so that it does not popup.
Is anyone experience with pick a call? I can make a call but my program couln't detect an incoming call (when dialing with DATAMODEM using TAPI).
Best regards,
A. Riazi
To receive data call you should terminate cprog.exe. Look into cryptophone source code for more information.
I didn't see any code for terminating cprog.exe, only I saw one line of code to hide "Incoming call..." window. Would you please say in which source of the CryptoPhone, they did this?
Best regards,
A. Riazi
I keep refering back to this topic, wishing I were clever enough to make the XDA modem visable under C# - but I have failed miserably!
Has anybody managed to this, either by talking to COM2: or by using TAPI? All I want is to establish a data call (NOT IP!) for a POS application.
I would worship the ground you walk on if you can help me over my blockage!
Can someone explain how TAPI is implemented to do data calls ??? I am programming in MFC / eVC++ ... Thanks for ur help guys !!!
Which TAPI function do u use to establish a data call ??? is there anywhere i can get the list of all of them ?? cheers guys

Changing mac address on a tytn

Hey,
I recently bought a TyTN, and was wondering.. is it possible to change the mac address on it (not physically, but in wm5)?
I know it can be done in windows 2k/xp, and I've read about others doing it in VM2003.. Haven't been able to figure anything out on VM5 tho.
Anyone who might be able to help out there?
Ps. The reasons for switching the mac address, if anyone is concerned, is that it's easier to switch it, rather then having to go around contacting the administrators of the 5 networks I use during a standard month and having it added everywhere... Might have to do it, but dont want to if it can be avoided
Guess it's not possible
Well... under Windows XP it's doable with a registry entry... so why not under WinCE?
Again, this is due to Opera:
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, "Lucida Grande", Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }
That's what I thought.. but unless the key is not supposed to be called "NetworkdAddress", I can't seem to figure it out :/
Tried it in every possible place I could think of placing the key in the registry without any changes (did a soft-reset after each try, hopefully enough)

Hard-SPL and SSPL

What is the difference between Hard-SPL and SSPL?
Thanks
Hard-SPL is flashed onto your device and accessible during cold-boot, SSPL is only loaded into RAM and started immediately.
Now the usual bashing: Do you actually READ THE WIKI? Use the search function? I mean, you know how to start a thread... why don't you try the other functions as well?
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }

WM6 - how to Query WLAN "connection" status

I am desperately trying to work around some unknown problem caused by our NDIS IM driver on WM6 and HTC TyTn ( TyTn at least, but most likely other devices as well ). I started some other threads regarding different facets of this problem, and no help is coming. Now I am just trying to work around it.
in short the problem is when power events happen the WLAN will never connect.
The work around is programmatically open the control panel with STControlPanel class and press the down button 1 time then the f1 key ( right dash ). This "presses connect" on the last configured access point. This works around my problem, however, I need to detect when the access point has connected. There is a "connecting" and "connected" message for the access point in this control panel dialog ( control panel # 17 ).
My Question: Is there some way to get this text "connecting" or "connected" from the control panel #17?
I have tried wzc, ndisuio, winsock, and other "non control panel" ways to detect connected state, but the IM problem fools all these methods. The only thing I have ever seen that successfully shows when the problem has occurred is the "connecting"/"connected" status in the control panel 17.
Please Help Someone.
p.s. If I can get this worked around, we sell a commercial grade ndis intermediate driver toolkit letting you easily write plugins without any of the hard driver details. We have redirectors, transparent proxy, tunnelers, virtual adapters, lots of good stuff. Also the same plugin will work on all windows desktop platforms vista - 98, WM5/6 and CE and also linux and solaris...
Hello skk
What about notification API?
Here is the solution (simple concept) for Your problem. Interesting parts are in bold.
SNapiTest.cpp
Code:
#include "stdafx.h"
#include "SNapiTest.h"
#include <windows.h>
#include <commctrl.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
[b]
const DWORD WM_WIFISTATUS = WM_USER + 1;
bool g_connecting;
bool g_connected;
HREGNOTIFY g_hNotify;
HREGNOTIFY g_hNotify2;
[/b]
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SNAPITEST));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SNAPITEST));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; // Store instance handle in our global variable
// SHInitExtraControls should be called once during your application's initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SNAPITEST, szWindowClass, MAX_LOADSTRING);
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
if (!MyRegisterClass(hInstance, szWindowClass))
{
return FALSE;
}
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
// When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// is created is not taken into account). So we resize the window after creating it
// if a menubar is present
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static SHACTIVATEINFO s_sai;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
[b]
g_connecting = false;
g_connected = false;
{HRESULT hr = RegistryNotifyWindow(SN_WIFISTATECONNECTING_ROOT,
SN_WIFISTATECONNECTING_PATH, SN_WIFISTATECONNECTING_VALUE,
hWnd, WM_WIFISTATUS, 0, NULL, &g_hNotify);}
{HRESULT hr2 = RegistryNotifyWindow(SN_WIFISTATECONNECTING_ROOT,
SN_WIFISTATECONNECTED_PATH, SN_WIFISTATECONNECTED_VALUE,
hWnd, WM_WIFISTATUS, 0, NULL, &g_hNotify2);}
[/b]
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
[b]
case WM_WIFISTATUS:
{
DWORD newValue = (DWORD) wParam;
WCHAR caption[] = L"Wifi Status";
if ((newValue & SN_WIFISTATECONNECTED_BITMASK) == SN_WIFISTATECONNECTED_BITMASK)
{
if (!g_connected)
{
g_connected = true;
g_connecting = false;
MessageBox(hWnd, L"Connected!!", caption, MB_OK);
}
break;
}
if ((newValue & SN_WIFISTATECONNECTING_BITMASK) == SN_WIFISTATECONNECTING_BITMASK)
{
if (!g_connecting)
{
g_connecting = true;
g_connected =false;
MessageBox(hWnd, L"Connecting...", caption, MB_OK);
}
}
break;
}
[/b]
case WM_DESTROY:
CommandBar_Destroy(g_hWndMenuBar);
[B]
RegistryCloseNotification(g_hNotify);
RegistryCloseNotification(g_hNotify2);
[/B]
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
}
return (INT_PTR)FALSE;
}
Needed includes:
// TODO: reference additional headers your program requires here
#include <snapi.h>
#include <regext.h>
snapi.h
Thank you so much for your post. I just found snapi.h, I assume this is snapitest.h?
IT WORKS!
It works! You are my hero RStein. You are a god among men.
Great. ) Thanks for sharing the results.

C++ WM5+ (6.1 in use) - Image colors are reduced when drawing

Hi folks,
i've got a problem while developing my "learning app". just developing it to learn how to solve things on windows mobile... blah.. to the problem.
When loading & drawing an image into my app it reduces the colors of at least one image so it looks kind of crap.
The used image is a jpeg file loaded into an IImage via IImagingFactory.
Screenshot: http://img22.yfrog.com/i/myappr.jpg/ (how it looks)
Background: http://img36.yfrog.com/i/backgroundwzu.jpg/ (how it should look lke)
Most interesting parts of the class i wrote for drawing all that stuff:
Code:
#include "stdafx.h"
#include <imaging.h>
#include <initguid.h>
#include <imgguids.h>
#include <aygshell.h>
class gfx
{
public:
gfx(void) {
CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&this->pImgFactory)))
{
// Initialize backbuffer
this->hdcBackbuffer = NULL;
this->hdcArtwork = NULL;
this->bmBackbuffer = CreateBitmap( 480, 536, 1, 16, NULL);
this->bmArtwork = CreateBitmap( 480, 536, 1, 16, NULL);
// Do some unrelated initialisation assignments ....
// Done! :D
// Load images
if (!SUCCEEDED(this->pImgFactory->CreateImageFromFile(TEXT("\\Program Files\\ForsakenToday\\Background.jpg"), &this->pImageBackground))) return;
// Load some more images
// Loading done, ready to draw.
this->bReady = true;
}
};
bool Draw(HDC hdc, RECT *rc_update) {
if (this->bReady) {
this->rgnUpdate = CreateRectRgn(rc_update->left, rc_update->top, rc_update->right, rc_update->bottom);
if (this->hdcArtwork == NULL) {
RECT rc_background = {0, 0, 480, 536};
RECT rc_clock = {80, 0, 400, 96};
this->hdcArtwork = CreateCompatibleDC(hdc);
SelectObject(this->hdcArtwork, this->bmArtwork);
this->gDrawImage(this->hdcArtwork, rc_background, this->pImageBackground);
this->gDrawImage(this->hdcArtwork, rc_clock, this->pImageClock);
}
if (this->hdcBackbuffer == NULL) {
this->hdcBackbuffer = CreateCompatibleDC(hdc);
SelectObject(this->hdcBackbuffer, this->bmBackbuffer);
}
SelectClipRgn(this->hdcBackbuffer, this->rgnUpdate);
BitBlt(this->hdcBackbuffer, rc_update->left, rc_update->top, (rc_update->right-rc_update->left), (rc_update->bottom-rc_update->top),
this->hdcArtwork, rc_update->left, rc_update->top, SRCCOPY);
// Painting all that overlaying stuff that changed ...
// Done! :D
BitBlt(hdc, rc_update->left, rc_update->top, (rc_update->right-rc_update->left), (rc_update->bottom-rc_update->top),
this->hdcBackbuffer, rc_update->left, rc_update->top, SRCCOPY);
return true;
}
return false;
};
void gDrawImage(HDC hdc, RECT rc, IImage *pImage) {
pImage->Draw(hdc, &rc, NULL);
};
}
If i forgot anything, tell me
I would be happy about to know where exactly the image's colors are reduced and/or how to prevent this.
Best regards
Jens
Ultimate answer to your problem lays in fact that Windows Mobile can display only 65536 colors. This is 16 bits per pixel, and pixel color is coded R5 G6 B5, meaning 5 bits for red and blue, and 6 for green, which gives 32 red levels, 64 green levels and 32 blue levels (this makes 32*64*32 = 65536 possible colors). Not bad, BUT... when comes to grayscale, there's a small problem - since "gray levels" are made in RGB using same level for R, G and B (for example, gray level 15 in RGB is 15-15-15). Because of that, you can have only 32 gray levels! And what you see in your app is approximation of each pixel to one of those 32 gray levels... So only thing you can do is to save this image with 16-bit color and use dithering to improve color representation, but I don't know app that can do so... If you find one, please tell me...
This is the best dithering I can get, but this is not 16-bit, it's dithering on 256 color Mac palette:
Ah okay that explains why all other (colored) images look fine...
thanks for your quick reply
Actually, any gradient image will look crappy because of this...
As for now, only solution is to dither it or avoid gradients...

Categories

Resources