lineSetAppPriority doesn't seem to work... - Windows Mobile Development and Hacking General

For the program I posted here, I want to handle incoming calls before the default popup appears (to replace the ringtone).
Currently, my tool seems to be quick enough without lineSetAppPriority in most cases, but sadly not in all...
I was using the following code: (currently removed again, because it didn't work and even caused some troubles...)
Initialization:
Code:
if ( lineInitialize( &LineApp, theApp.m_hInstance, LineCallback,
theApp.m_pszAppName, &LineHandleCount ) == 0 )
{
LineHandles = new HLINE[LineHandleCount];
for(DWORD i = 0; i < LineHandleCount; i++)
{
if ( lineNegotiateAPIVersion( LineApp, i, 0x00010000, 0x00020000,
&ver, &extensionID ) == 0 )
{
rc = lineOpen( LineApp, i, &LineHandles[i], ver, 0, (DWORD)this,
LINECALLPRIVILEGE_MONITOR|LINECALLPRIVILEGE_OWNER,
LINEMEDIAMODE_INTERACTIVEVOICE, NULL );
if ( rc < 0 )
LineHandles[i] = NULL;
else
if ( LineHandleSignal == NULL )
LineHandleSignal = LineHandles[i];
}
}
HRESULT res = lineSetAppPriority( theApp.m_pszAppName,
LINEMEDIAMODE_INTERACTIVEVOICE,
NULL,
LINEREQUESTMODE_MAKECALL,
NULL, 1 );
}
Callback:
Code:
VOID FAR PASCAL LineCallback( DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3
)
{
if ( dwMsg == LINE_CALLSTATE )
{
LINECALLINFO *callInfo = (LINECALLINFO *)calloc(sizeof(LINECALLINFO)
+1024, 1);
callInfo->dwTotalSize = sizeof(LINECALLINFO)+1024;
lineGetCallInfo( (HCALL)hDevice, callInfo );
// different stuff...
HRESULT res;
// Remove from priority list, so lineHandoff will run the default
// call window
res = lineSetAppPriority( theApp.m_pszAppName,
LINEMEDIAMODE_INTERACTIVEVOICE, NULL,
LINEREQUESTMODE_MEDIACALL, NULL, 0 );
// Forward event to next instance (usually Windows' phone app)
lineHandoff( (HCALL)hDevice, NULL, callInfo->dwMediaMode );
// Set to top priority again
res = lineSetAppPriority( theApp.m_pszAppName,
LINEMEDIAMODE_INTERACTIVEVOICE, NULL,
LINEREQUESTMODE_MEDIACALL, NULL, 1 );
}
lineSetAppPriorty returns OK in all cases. But when a call comes in, the
default bubble applears simultaneously with the callback function. I
wanted it to be shown when I do the lineHandoff...
What am I doing wrong?
TIA,
Mirko

I used lineSetAppPriority too, with same result....
I think there is one way.....kill cprog

Related

Bluetooth Programming...

This is for the C/C++ developers out here...
i need to connect a PocketPC to a PC via Bluetooth. Looking at various samples from the Windows Platform SDK and the Windows Mobile SDKs, i came up with the following server (PC) and client (PDA) codes:
Server Code (WinXP):
Code:
WSAData wsaData;
SOCKADDR_BTH sa;
int namelen;
SOCKET sock;
SOCKADDR_BTH sockaddr;
int size = sizeof(sockaddr);
if (WSAStartup(MAKEWORD(2, 2), &wsaData) == SOCKET_ERROR)
return false;
BluetoothHost_Socket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if (BluetoothHost_Socket == INVALID_SOCKET)
return false;
memset (&sa, 0, sizeof(sa));
sa.addressFamily = AF_BTH;
sa.port = 0;
if (bind(BluetoothHost_Socket, (SOCKADDR *) &sa, sizeof(sa)))
{
closesocket(BluetoothHost_Socket);
return false;
namelen = sizeof(sa);
if (getsockname(BluetoothHost_Socket, (SOCKADDR *)&sa, &namelen))
{
closesocket (BluetoothHost_Socket);
return false;
}
BluetoothHost_ClientListCount = 0;
if (listen(BluetoothHost_Socket, 5))
return false;
sock = accept(BluetoothHost_Socket, (SOCKADDR *) &sockaddr, &size);
}
Client Code (WinCE):
Code:
WSAQUERYSET querySet;
HANDLE hLookup;
char buffer[1000];
DWORD bufferlength;
WSAQUERYSET *results;
SOCKADDR_BTH *btaddr;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) == SOCKET_ERROR)
return false;
memset(&querySet, 0, sizeof(querySet));
querySet.dwSize = sizeof(querySet);
querySet.dwNameSpace = NS_BTH;
BluetoothQuery_DeviceCount = 0;
if (WSALookupServiceBegin(&querySet, LUP_CONTAINERS, &hLookup) == SOCKET_ERROR)
return false;
while (BluetoothQuery_DeviceCount < BLUETOOTHQUERY_MAXDEVICES && !BluetoothQuery_Cancel)
{
bufferlength = sizeof(buffer);
memset(buffer, 0, sizeof(buffer));
results = (WSAQUERYSET *) &buffer;
if (WSALookupServiceNext(hLookup, LUP_RETURN_NAME|LUP_RETURN_ADDR, &bufferlength, results) == SOCKET_ERROR)
{
int result = WSAGetLastError();
break;
}
btaddr = (SOCKADDR_BTH*)results->lpcsaBuffer->RemoteAddr.lpSockaddr;
BluetoothQuery_DeviceAddrList[BluetoothQuery_DeviceCount]=btaddr->btAddr;
if (results->lpszServiceInstanceName != NULL)
wcscpy((TCHAR *)BluetoothQuery_DeviceNameList[BluetoothQuery_DeviceCount],results->lpszServiceInstanceName);
else
wcscpy((TCHAR *)BluetoothQuery_DeviceNameList[BluetoothQuery_DeviceCount],L"<unnamed>");
BluetoothQuery_DeviceCount++;
}
WSALookupServiceEnd(hLookup);
BluetoothClient_Socket = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM);
if (BluetoothClient_Socket == INVALID_SOCKET)
return false;
SOCKADDR_BTH sa;
memset (&sa, 0, sizeof(sa));
sa.addressFamily = AF_BT;
sa.btAddr = *btaddr;
for (i = 0; i < 30; i++)
{
sa.port = i; //channel & 0xff;
if (connect(BluetoothClient_Socket, (SOCKADDR *) &sa, sizeof(sa)) == 0)
break;
}
if (i >= 30)
{
closesocket(BluetoothClient_Socket);
return false;
}
All calls seems to work out. Sockets are created, all return values look ok. Yet, the client does not connect to the server, so the server never goes beyong that accept() call.
Any comments would be greatly appreciated!
thanks,
Daniel

connect GPRS using RAS on Pocket PC 2005

Hi,
I 'm not able to establish GPRS connection using RasDial on PPC 2005 . It returns always error 633. That means:
"The port is already in use or is not configured for Remote Access dialout.� (See related Microsoft article: ErrMsg: Error 633: The Modem Is Not Installed or Configured...) "
But it works fine in PPC 2003. Does anyone gets RAS API run successfull on WM 5.0 ?
here is my code:
Code:
void ConnectGPRSDlg::connectViaRAS()
{
RASDIALPARAMS rasDialParam;
BOOL bPasswd,bRasEntryFound;
DWORD dwRes, dwSize, dwEntries, dw;
short n_attempts = 5;
HRASCONN g_rasConn = NULL;
CString szError,msg,szResult;
LPRASENTRYNAME lpRasEntry = NULL;
// structure init.
memset(&rasDialParam, 0, sizeof(RASDIALPARAMS));
rasDialParam.dwSize = sizeof (RASDIALPARAMS);
lpRasEntry = new RASENTRYNAME[20];
if(lpRasEntry == NULL)
{
szError.Format( _T("Out of memory") );
msg += szError;
m_editbox.SetWindowTextW(msg);
return;
}
lpRasEntry[0].dwSize = sizeof(RASENTRYNAME);
dwSize = sizeof(RASENTRYNAME) * 20;
dwRes = RasEnumEntries(NULL, NULL, lpRasEntry,
&dwSize, &dwEntries);
if (dwRes != 0)
{
szError.Format( _T("Error getting RAS entries %d"),dwRes );
msg += szError;
}
else
{
szError.Format( _T("got RAS %d entries\r\n "),dwEntries );
msg += szError;
for(dw = 0; dw < dwEntries; dw++)
{
if( 0 == _tcscmp( lpRasEntry[dw].szEntryName, L"T-Mobile Internet" ) )
{
bRasEntryFound = TRUE;
_tcscpy( rasDialParam.szEntryName, lpRasEntry[dw].szEntryName );
szError.Format( _T("found entry: %s\r\n "),lpRasEntry[dw].szEntryName );
msg += szError;
}
}
}
if (!bRasEntryFound) return;
//// connection name
//wcscpy(rasDialParam.szEntryName, _T("T-Mobile Internet") );
//
// parameters from connection structure
dwRes = RasGetEntryDialParams(NULL, &rasDialParam, &bPasswd);
if(dwRes != 0)
{
szResult.Format( _T("getting Dial Params error: %D \r\n") , dwRes );
szResult += szError;
}
else
{
szResult.Format(L"entryname: %s, number: %s \r\n", rasDialParam.szEntryName,rasDialParam.szPhoneNumber);
msg += szResult;
}
// szError.Format( _T("creat new Dial Params...\r\n"));
//msg += szError;
// // Copy in the user credetials.
//_tcscpy( rasDialParam.szEntryName, _T("T-Mobile Internet") );
//_tcscpy( rasDialParam.szUserName, _T("t-mobile") );
//_tcscpy( rasDialParam.szPassword, _T("pwd") );
//_tcscpy( rasDialParam.szPhoneNumber, _T("*99#") );
//_tcscpy( rasDialParam.szCallbackNumber, _T("") );
szResult.Format(L"entryname: %s, number: %s \r\n", rasDialParam.szEntryName,rasDialParam.szPhoneNumber);
msg += szResult;
m_editbox.SetWindowTextW(msg);
do{
// if connection fails, hangup and retry... for 5 attemps
DWORD dwResult = RasDial(NULL,NULL,&rasDialParam,0,NULL,&g_rasConn);
Sleep(2000);
if ( dwResult != 0)
{
szError.Format(L"RAS error: %d \r\n", dwResult);
msg += szError;
m_editbox.SetWindowTextW(msg);
RasHangUp(g_rasConn);
g_rasConn = NULL;
n_attempts--;
}
else {
break;
}
}
while(n_attempts);
if(n_attempts == 0)
{
//AddDebugInfo( L"Can't connect GPRS" );
}
else
{
RASCONNSTATUS rasConStatus;
memset(&rasConStatus, 0, sizeof(RASCONNSTATUS));
rasConStatus.dwSize = sizeof(RASCONNSTATUS);
RasGetConnectStatus(g_rasConn, &rasConStatus);
if(rasConStatus.dwError == 0) {
szResult.Format( L"GPRS connected \r\n" );
msg += szResult;
}
else
{
szResult.Format(L"Ras connect status: %s \r\n", rasConStatus.dwError);
msg += szResult;
}
}
m_editbox.SetWindowTextW(msg);
return;
}

EDB notification

Hi All,
Is anyone familiar with the EDB notification mechanism? I have some code that has opened the appointments database to get change notifications, all well and good. The trouble is I am unable to delete the CENOTIFICATION structure, meaning I get a memory leak after every change.
if anyone has seen this or knows the solution, I'd be grateful.
Code:
CEOID apps_oid;
request= new CENOTIFYREQUEST; // or (CENOTIFYREQUEST *) LocalAlloc (LPTR,
// sizeof (CENOTIFYREQUEST));
if (request) {
request->dwSize = sizeof (CENOTIFYREQUEST);
request->hwnd = hwnd;
request->hHeap = NULL;
request->dwFlags = CEDB_EXNOTIFICATION;
request->dwParam = param;
database = CeOpenDatabaseInSession ( NULL,
&pim_guid,
&apps_oid,
L"Appointments Database",
0,
0, // or CEDB_AUTOINCREMENT,
request);
}
. . .
case WM_DBNOTIFICATION:
{
CENOTIFICATION * notification = (CENOTIFICATION *)lParam;
// Always returns FALSE
BOOL hr = CeFreeNotification(request, notification);
// Always returns 5 - access denied
DWORD dw = GetLastError();
}
break;

[Q] Why does this code not work in CE 6.0?

I want to add to HKLM\init an all purpose application launcher (CE 6.0 device has persistent registry):
Code:
[HKEY_LOCAL_MACHINE\Init]
"Depend199"=hex:00,14,00,1e,00,60
[HKEY_LOCAL_MACHINE\Init]
"Launch199"="\NandFlash\CeLaunchAppsAtBootTime.exe"
[HKEY_CURRENT_USER\Startup]
"Process1"="\NandFlash\SetBackLight.exe"
"Process1Delay"=dword:0
The launcher's code is
Code:
#include <Windows.h>
#if defined(OutputDebugString)
#undef OutputDebugString
void OutputDebugString(LPTSTR lpText)
{}
#endif
BOOL IsAPIReady(DWORD hAPI);
void WalkStartupKeys(void);
DWORD WINAPI ProcessThread(LPVOID lpParameter);
#define MAX_APPSTART_KEYNAME 256
typedef struct _ProcessStruct {
WCHAR szName[MAX_APPSTART_KEYNAME];
DWORD dwDelay;
} PROCESS_STRUCT,*LPPROCESS_STRUCT;
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
int nLaunchCode = -1;
// Quick check to see whether we were called from within HKLM\init -> by default HKLM\init passes the lauch code
if(lpCmdLine && *lpCmdLine)
{
// MessageBox(NULL, lpCmdLine ,NULL,MB_OK);
nLaunchCode = _ttoi( (const TCHAR *) lpCmdLine);
}
else
{
// MessageBox(NULL, _T("No argumets passed"),NULL,MB_OK);
}
//Wait for system has completely initialized
BOOL success = FALSE;
int i = 0;
while((!IsAPIReady(SH_FILESYS_APIS)) && (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_DEVMGR_APIS))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_SHELL))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_WMGR))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_GDI))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
}
}
}
}
if(nLaunchCode != -1)
{
// Since this is application is launched through the registry HKLM\Init we need to call SignalStarted passing in the command line parameter
SignalStarted((DWORD) nLaunchCode);
}
//If system has completely initialized
if( success)
{
WalkStartupKeys();
}
return (0);
}
void WalkStartupKeys(void)
{
HKEY hKey;
WCHAR szName[MAX_APPSTART_KEYNAME];
WCHAR szVal[MAX_APPSTART_KEYNAME];
WCHAR szDelay[MAX_APPSTART_KEYNAME];
DWORD dwType, dwNameSize, dwValSize, i,dwDelay;
DWORD dwMaxTimeout=0;
HANDLE hWaitThread=NULL;
HANDLE ThreadHandles[100];
int iThreadCount=0;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Startup"), 0, KEY_READ, &hKey) != ERROR_SUCCESS) {
return;
}
dwNameSize = MAX_APPSTART_KEYNAME;
dwValSize = MAX_APPSTART_KEYNAME * sizeof(WCHAR);
i = 0;
while (RegEnumValue(hKey, i, szName, &dwNameSize, 0, &dwType,(LPBYTE)szVal, &dwValSize) == ERROR_SUCCESS) {
if ((dwType == REG_SZ) && !wcsncmp(szName, TEXT("Process"), 7)) { // 7 for "Process"
// szval
wsprintf(szDelay,L"%sDelay",szName);
dwValSize=sizeof(dwDelay);
if (ERROR_SUCCESS == RegQueryValueEx(hKey,szDelay,0,&dwType,(LPBYTE)&dwDelay,&dwValSize)) {
// we now have the process name and the process delay - spawn a thread to "Sleep" and then create the process.
LPPROCESS_STRUCT ps=(LPPROCESS_STRUCT) LocalAlloc( LMEM_FIXED , sizeof( PROCESS_STRUCT));
ps->dwDelay=dwDelay;
wcscpy(ps->szName,szVal);
DWORD dwThreadID;
OutputDebugString(L"Creating Thread...\n");
HANDLE hThread=CreateThread(NULL,0,ProcessThread,(LPVOID)ps,0,&dwThreadID);
ThreadHandles[iThreadCount++]=hThread;
if (dwDelay > dwMaxTimeout) {
hWaitThread=hThread;
dwMaxTimeout=dwDelay;
}
LocalFree((HLOCAL) ps);
}
}
dwNameSize = MAX_APPSTART_KEYNAME;
dwValSize = MAX_APPSTART_KEYNAME * sizeof(WCHAR);
i++;
}
// wait on the thread with the longest delay.
DWORD dwWait=WaitForSingleObject(hWaitThread,INFINITE);
if (WAIT_FAILED == dwWait) {
OutputDebugString(L"Wait Failed!\n");
}
for(int x=0;x < iThreadCount;x++) {
CloseHandle(ThreadHandles[x]);
}
RegCloseKey(hKey);
}
DWORD WINAPI ProcessThread(LPVOID lpParameter)
{
TCHAR tcModuleName[MAX_APPSTART_KEYNAME];
OutputDebugString(L"Thread Created... Sleeping\n");
LPPROCESS_STRUCT ps=(LPPROCESS_STRUCT)lpParameter;
Sleep(ps->dwDelay); // Wait for delay period
OutputDebugString(L"Done Sleeping...\n");
PROCESS_INFORMATION pi;
STARTUPINFO si;
si.cb=sizeof(si);
OutputDebugString(L"Creating Process ");
OutputDebugString(ps->szName);
OutputDebugString(L"\n");
wcscpy(tcModuleName,ps->szName);
TCHAR *tcPtrSpace=wcsrchr(ps->szName,L' '); // Launch command has a space, assume command line.
if (NULL != tcPtrSpace) {
tcModuleName[lstrlen(ps->szName)-lstrlen(tcPtrSpace)]=0x00; // overwrite the space with null, break the app and cmd line.
tcPtrSpace++; // move past space character.
}
CreateProcess( tcModuleName, // Module Name
tcPtrSpace, // Command line -- NULL or PTR to command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ); // Pointer to PROCESS_INFORMATION structure
OutputDebugString(L"Thread Exiting...\n");
return 0;
}
which compiled errorfree
Added the registry entries as shown above, copied the launcher's exe in default location, rebootet device. Nothing happened, means executable defined as
Code:
[HKEY_CURRENT_USER\Startup]
"Process1"="\NandFlash\SetBackLight.exe"
wasn't run at all.
Does anybody have an idea, where the error is? Any help appreciated. Thanks for reading.

My JSONArray keeps appending the last object on loop

Here is my code:
Code:
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject jObject = new JSONObject(jsonObj.toString().trim());
Iterator<?> keys = jObject.keys();
JSONArray temp_json_arr = null;
JSONObject temp_json_obj = null;
String temp_string = "";
int index_count = 0;
LinearLayout ll = (LinearLayout)findViewById(R.id.test_layout);
//temp_json_obj = jsonObj.getJSONObject("identification");
//Log.d("TEST: ", "ARRAY LENGTH> "+temp_json_arr.length());
while( keys.hasNext() ){
String key = (String)keys.next();
Log.d("TEST: ", "KEYS> " + key);
// Getting JSON Array node
temp_json_arr = jsonObj.getJSONArray(key);
// looping through All Questions
for (int i = 0; i < temp_json_arr.length(); i++) {
JSONObject q = temp_json_arr.getJSONObject(i);
if( key.equals("identification") ) {
tv[tv_ctr] = new TextView(getApplicationContext());
tv[tv_ctr] = (TextView)findViewById(id);
id++;
et[identification_question] = new EditText(getApplicationContext());
et[identification_question] = (EditText)findViewById(id);
id++;
//json manipulation
try {
jsonOb.put("question-id", tv[tv_ctr].getText().toString());
jsonOb.put("answer", et[identification_question].getText().toString());
} catch(Exception e) {
}
Log.d("TEST: ", "jsonOb> " + jsonOb.toString());
//answer += et[identification_question].getText().toString() + "-" + tv[tv_ctr].getText().toString() + "/";
tv_ctr++;
identification_question++;
jsonArr.put(test,jsonOb);
test++;
Log.d("TEST: ", "jsonArr> " + jsonArr.toString());
}
Everytime I use .put of the JSONArray, it appends the last object on all indexes for example:
I have 3 input namely answer 1 , answer 2 and answer 3
The expected json data will be this:
Code:
[{"answer":"answer1","question-id":"question1"},{"answer":"answer2","question-id":"question2"},{"answer":"answer3","question-id":"question3"}]
But this is the current output:
Code:
[{"answer":"answer3","question-id":"question3"},{"answer":"answer3","question-id":"question3"},{"answer":"answer3","question-id":"question3"}]
As you can see the last index get appended multiple times.
Nevermind I've already solved my own problem.

Categories

Resources