RasEnumConnection don't work... - Windows Mobile Development and Hacking General

Hi!
I've create an application that detect Gprs Connection and check how much traffic is genereted on a Smartphone WM2003 and WM5.
On WM2003 it's all right, but in WM5 the RasEnumConnections() function always return 0 with 0 connection active...
The code for detect Connection is:
DWORD isConnection = false;
RASCONN rgrc[4];
DWORD dwSize = sizeof(rgrc);
DWORD dwConn = 0;
DWORD dwREC;
dwREC = RasEnumConnections(rgrc, &dwSize, &dwConn);
if (dwREC == ERROR_SUCCESS)
{
DWORD i;
RASENTRY rasEntry;
rasEntry.dwSize = sizeof(RASENTRY);
for (i = 0; i < dwConn; i++)
{
if(!RasGetEntryProperties(NULL,
rgrcIdea.szEntryName,
&rasEntry,
&rasEntry.dwSize,
NULL,
NULL))
{
if(wcsstr(rasEntry.szLocalPhoneNumber, L"~GPRS!") != NULL)
{
isConnected = true;
break;
}
}
else{
Debug(TEXT("Error RasGetEntryProperties"));
}
}
}
else {
Debug(TEXT("Error RasEnumConnections [%d]", dwREC));
}
return isConnected;
How can I detect the Gprs Connection in native code for this goal in WM5?
Can anyone help me?
Thanks!!!

I experience the same problem on the P3300, but on the P3600, there is an application in the windows folder named datadisconnect.exe .. And i looked into it with a dissasembler... And it uses RasEnumConnections and RasHangup to disconnect.. So my question to you is... What device are you using? This might be bug of some sort.. I also see that there is a difference between the datadisconnect.exe on the p3300 and on the p3600.. so i'll look into them and see if i can find anything there...
SaSHje

Follow up
Hi .. i've looked into what the P3300 does.. and it seems like RAS isn't used at all.. When you are connected with i.e. GPRS, the connection adapter and connection name is stored in the registry under HKLM\System\State\Connection\Cellular.. The datadisconnect.exe on this device use these and the GetAdaptersInfo function from Iphlpapi.h. Based on the information from both... They call IpReleaseAddress from Iphlpapi.h .. So .. I'm gonna try to make my own datadisconnect where i do not use the info in the registry, but instead use GetInterfaceInfo from Iphlpapi.h, where i'll fill a PIP_INTERFACE_INFO structure, and based on the adapterindexmap in this structure, release the IP adress assigned to the adapter.
Hope this helps you a bit.. But .. strangely.. on the P3600, the RasHangup works.. I know we are trying to do different things here.. but the problems a similar... Ras doesn't function well ..

Hi!
Sorry to interupt this tread, but this may explane why the standard Spb GPRS Monitor does not work on the P3300. On the CD shipped with the device there is a spesial version of Spb GPRS monitor that works.
Regards
PK

No problem PK.. Thanks for letting me know.. i'll take a look at it when i have time.. FYI, using the GetInterfaceInfo and IpReleaseAddress works like a charm..
azatoth: I do not know how we can use the Iphlp API to find statistics regarding traffic etc... If you manage to solve this, please let me know.. I will do the same if i stumble over something which could resolve this issue..

Hello,
I have the same problem and try to disconnect an active GPRS connection
with IpReleaseAddress(). I have found the adapter with GetInterfaceInfo()
but IpReleaseAddress() always fails with an unknown error code.
Can you give me an example how you got this working?
Thanks.
Houser

This worked for me..
I used this link http://msdn2.microsoft.com/en-us/library/aa366056.aspx .. and f.ex this worked:
PIP_INTERFACE_INFO pInfo;
pInfo = (IP_INTERFACE_INFO *) malloc( sizeof(IP_INTERFACE_INFO) );
ULONG ulOutBufLen = sizeof(IP_INTERFACE_INFO);
DWORD dwRetVal = 0;
// Make an initial call to GetInterfaceInfo to get
// the necessary size in the ulOutBufLen variable
if ( GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
{
free(pInfo);
pInfo = (IP_INTERFACE_INFO *) malloc (ulOutBufLen);
}
// Make a second call to GetInterfaceInfo to get
// the actual data we need
if ((dwRetVal = GetInterfaceInfo(pInfo, &ulOutBufLen)) == NO_ERROR )
{
for (int i=0; i<pInfo->NumAdapters; i++)
{
IpReleaseAddress(&pInfo->Adapter);
}
}
free(pInfo);

Thanks. Now it works. My mistake was that I call IpReleaseAddress()
for PPP connection. For ethernet connections it works well.
Houser

Related

TAPI Problem

Hi!
I am new to tapi programming and also to c++. so i have my troubles. but it is very important for me to solve these problems, and i know the only experts who can help me are you! So please help me...
I want to get a serial connection between 2 modems (MDAII PPC Phone Edition and MDAI PPC Phone Edition with WM2003).
I built up on the sample of the dialer sample of the pocket pc sdk.
After they are connected i want to create a comm handle with the createComHandle function listet at the bottom. I think there is no error. then i try to send some char bytes by the serial functions sendto and receive these bytes on the other mobile phone. but no dataflow. what could be the problems?
if u know anything, please help me, otherwise i am getting crazy...
thanks a lot,
joachim
Code:
//**************************************************************************
BOOL CreateComHandle()
{
LPVARSTRING lpDeviceID;
LONG lgiRet;
unsigned short* err;
lpDeviceID =(VARSTRING*) malloc(sizeof(VARSTRING));
lpDeviceID->dwTotalSize = sizeof(VARSTRING);
lgiRet = lineGetID(g_CurrentLineInfo.hLine, g_dwAddID, g_hCall, LINECALLSELECT_CALL, lpDeviceID, TEXT("comm/datamodem"));
err = NULL;
switch (lgiRet)
{
case LINEERR_INVALLINEHANDLE:
err=TEXT("Invalid line handle");
break;
case LINEERR_INVALCALLSELECT:
err=TEXT("Invalid call selected");
break;
case LINEERR_NOMEM:
err=TEXT("No memory available");
break;
case LINEERR_RESOURCEUNAVAIL:
err=TEXT("The resource is unavailable");
break;
case LINEERR_INVALADDRESSID:
err=TEXT("Invalid address id");
break;
case LINEERR_INVALPOINTER:
err=TEXT("Invalid pointer");
break;
case LINEERR_OPERATIONUNAVAIL:
err=TEXT("The operation is unavailable");
break;
case LINEERR_STRUCTURETOOSMALL:
err=TEXT("The structure is too small");
break;
case LINEERR_INVALCALLHANDLE:
err=TEXT("Invalid call handle");
break;
case LINEERR_NODEVICE:
err=TEXT("No device found");
break;
case LINEERR_OPERATIONFAILED:
err=TEXT("The operation failed");
break;
case LINEERR_UNINITIALIZED:
err=TEXT("The parameter is uninitialized");
break;
}
if (err != NULL)
MessageBox(NULL,err,TEXT("Joe Error"),MB_OK);
// get the comm handle
g_hComm = *((LPHANDLE)((LPBYTE)lpDeviceID + lpDeviceID->dwStringOffset));
if (g_hComm == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,TEXT("Handle Error"),TEXT("Joe Dlg"),MB_OK);
return FALSE;
}
return TRUE;
}
//**************************************************************************
[/code]
ok
thanks a lot, i solved the problems, there where a few things that weren't right.
but the most important thing which i didn't understand before was to reallocate the varstring structure (lpDeviceID), because it had to less memory allocated.
CSD Line Types
Hi.
Now that i solved these problems i have got new ones:
I want to change the CSD Line settings (v32, v34, v110,...transparent, nontransparent) out of my evc++ code.
I found another posting here with the same problem - sorry for the reposting - but does anybody have a solution for this problem now?
I thought that it would be some keys in the registry, searched for it, but couldn't find anything...
so please help me, it's very important for me....
Thanks for your help.
Joachim
What is the purpose of the linegetId function ? I'm getting confused on how to use it ... I would like to receive data from a TAPI connection but i am not too sure which port to Use.
thnks for all ur help
I guess the comm port handle is stored in the ID structure by calling
// get the comm handle
g_hComm = *((LPHANDLE)((LPBYTE)lpDeviceID + lpDeviceID->dwStringOffset));
I have seen sveral way to retrieve the comm port handle. This is one of them. It is actually very tricky. don't ask me why...
- David
By the way,
Is anyone able to use CSD transparent mode setting to send data?
How to do it?
Thanks,
- David
Indeed retrieving the Handle seems to be the hardest things to do, what other methods have you seen around??
all i heard was lineGetId but i have seen some poeple use createFile() so to tell the truth i'm even more confused
Cheers

Turn ON/OFF BT/Widcomm on BA with eVc

Does anyone know how to turn on and off the Widcomm bluetooth on a Blue Angel from within C/eVc? :?:
tia
The only official way to turn off the radio is to destroy the last of the BT objects using the stack (the stack is object orientated, creating an object turns it on, destroying the lst object turns it off, this assumes you have the widcomm SDK). The problem is that the BT app that runs in the system tray (and shows you that bluetooth icon in the bottom left) owns a stack object that you cant properly destroy, hence you can't turn the radio off.
hrm...
If the tray app wasn't running, theres a function in the wbtapiCE.dll called UnloadStack ([email protected]@@[email protected]@[email protected]) which should force the stack to unload and probably turn off the radio.
So we might be able to turn it OFF this way. And how do we turn in ON again ;-)
Theres a corrasponding LoadStack ([email protected]@@[email protected]@[email protected]) which would do the job.
Each of these accept two parameters, the first appears to be a pointer to a class, the second a numeric value.
For the class pointer, it appears that you can define an 8 byte array and call the constructor ( [email protected]@[email protected] ) on it, remember to call the destructor ( [email protected]@[email protected] ) when your done. The hex value appears to be 0x123456 for LoadStack and 0x654321 for UnloadStack.
I really don't know how successfull you would be starting the stack yourself, spinning up the BT tray app, then killing it and shutting down the stack, you may find you have to replace all the functionality of the tray app yourself.
Complicated stuff. I might be easier off doing FindWindow on the BtApp and find the ON and OFF buttons and programatically press them.
Hello All.
I call wbtapiCE.dll functions for on/off BT on dell axim x30.
I use, two dll metods
[email protected]@@[email protected]@[email protected] == public: enum WBtRc __cdecl CWBtAPI::UnloadStack(unsigned int)
and
>> [email protected]@@[email protected]@[email protected] == public: enum WBtRc __cdecl CWBtAPI::LoadStack(unsigned int)
But no positive effect.
Anybody know what i doing wrong?
Sample code below:
{
CString szDllPath = _T("wbtapiCE.dll");
HMODULE hMod = LoadLibrary(szDllPath);
if(hMod==NULL)
{
AfxMessageBox(_T("LoadLibrary Failed !!!"));
}
//__cdecl CWBtAPI::CWBtAPI(void)
typedef void (CWBtAPI::*PFNCreateCWBt)();
typedef void (CWBtAPI::*PFNDestructorOfCWBt)();
typedef int (CWBtAPI::*PFNLoadCWBt)(unsigned int);
typedef int (CWBtAPI::*PFNUnLoadCWBt)(unsigned int);
//>> >> [email protected]@@[email protected]@[email protected] == public: enum WBtRc __cdecl CWBtAPI::UnloadStack(unsigned int)
CWBtAPI* a1 = (CWBtAPI*)_alloca(sizeof(CWBtAPI));
PFNCreateCWBt pfnCreateWBt = force_cast<PFNCreateCWBt>(GetProcAddress(hMod, TEXT("[email protected]@[email protected]")));
(a1->*pfnCreateWBt)();
//////////////////////////////////////////////////////////////////////////
PFNUnLoadCWBt pfnUnLoadA = force_cast<PFNUnLoadCWBt>(GetProcAddress(hMod, TEXT("[email protected]@@[email protected]@[email protected]")));
AfxMessageBox(_T("Started pfnUnLoadA"));
int result = (a1->*pfnUnLoadA)( 0x654321);
CString err = _T("Done pfnUnLoadA");
AfxMessageBox(err );
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
PFNLoadCWBt pfnLoadA = force_cast<PFNLoadCWBt>(GetProcAddress(hMod, TEXT("[email protected]@@[email protected]@[email protected]")));
AfxMessageBox(_T("Started pfnLoadA"));
result = (a1->*pfnLoadA)(0x123456);
AfxMessageBox(_T("Done pfnLoadA"));
//////////////////////////////////////////////////////////////////////////
PFNDestructorOfCWBt pfnDestA = force_cast<PFNDestructorOfCWBt>(GetProcAddress(hMod, TEXT("[email protected]@[email protected]")));
(a1->*pfnDestA)();
/*************************************************************************/
FreeLibrary(hMod);
}
could some kind soul maybe write a script to do someth like that...
I make it BT on/off
Jn dell axim X30 exist btpwr.dll.
This dll export some interesting methods.
1 0 0000128C PowerDeInit
2 1 00001284 PowerInit
3 2 00001258 PowerOff
4 3 0000121C PowerOn
I call this methods directly from dll, and i turn on turn off bt !!
Sample code below:
void DoTrayOn()
{
CString szDllPath = _T("btpwr.dll");
HMODULE hMod = LoadLibrary(szDllPath);
if(hMod==NULL)
{
AfxMessageBox(_T("LoadLibrary Failed !!!"));
}
typedef int (*BTPowerOn)();
BTPowerOn bton = (BTPowerOn) GetProcAddress(hMod, TEXT("PowerOn"));
if (NULL != bton)
{
// AfxMessageBox(_T("Start DoTrayOn"));
(bton) ();
}else
{
// AfxMessageBox(_T("Error NULL DoTrayOn pointer"));
}
FreeLibrary(hMod);
}
void DoTrayOff()
{
CString szDllPath = _T("btpwr.dll");
HMODULE hMod = LoadLibrary(szDllPath);
if(hMod==NULL)
{
AfxMessageBox(_T("LoadLibrary Failed !!!"));
}
typedef int (*BTPowerOff)();
BTPowerOff bton = (BTPowerOff) GetProcAddress(hMod, TEXT("PowerOff"));
if (NULL != bton)
{
// AfxMessageBox(_T("Start DoTrayOn"));
(bton) ();
}else
{
// AfxMessageBox(_T("Error NULL DoTrayOn pointer"));
}
FreeLibrary(hMod);
}
Bluetooth turn on/turn off
Hello
Have you a solution for turn on and turn off bluetooth by code?
I have a widcomm stack and I use c# .net
i'm searching for a solution for my Touch Pro 2 with Widcomm BT Stack.
i can turn on BT by creating an object of CBtIf, but can't turn of BT by deleting the object.
someone has an idea?
regards
IceFire

GPS Settings

I am wrting an app that needs to take the NMEA 183 GPS sentences from the GPS to process. I have set my serial port connection to port COM4 with a baud rate of 4800, 8 data bits, no parity, and one stopbit. Althougth a get a connection to the comm port I do not get any NMEA messages from the port.
Please could somebody advise on the settings for the internal GPS device.
Thanks in advance.
COM 4, 57600, 8, None, 1.
Sorry for the offtopic, is it possible to communicate with the internal GPS using .Net framework? What language are you working with?
Still no luck reading the GPS
I,ve tried the settings, but I still do not get and data.
I have looked in the registry, but could not see any of the settings as described in http://msdn.microsoft.com/en-us/library/bb202016.aspx
does anybody else have any ideas. The rom version on the device is 1.14.405.3, and I know the GPS works using another app. Or does anybody have a bit of c# code that I could use.
The code I am using looks like this
using (SerialPort sp = new SerialPort())
{
sp.PortName = "COM" + Port.ToString();
sp.BaudRate = BaudRate;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
sp.ReadTimeout = 1000;
try
{
sp.Open();
}
catch (Exception)
{
}
while(true)
{
string data = "";
bool gotLine = false;
while (!stopping && !gotLine)
{
try
{
data = sp.ReadLine();
gotLine = true;
}
catch (TimeoutException)
{
}
}
// Process the data line
}
The code throws due to the timeout, I never get a line of data.
Thanks.

Call Log coding problem (C++)

hi everybody,
i've got a strange problem using the edb functions in windbase_edb.h. i create a new c++ smartdevice project in vs2008, targeting Windows Mobile 6.1 Pro.
although CeMountDBVolEx returns true [ie successfully mounted], GetError() shows that some ERROR_INVALID_PARAMETER happened inside.
then, CeOpenDatabaseInSession returns an INVALID_HANDLE_VALUE handle, ie the call log didn't open, and GetError() shows that some ERROR_INVALID_PARAMETER happened inside again.
please help, what am i doing wrong?
thank you very much.
code as follows:
Code:
HWND hWnd;
CEGUID guidVol;
bool isVolMounted;
HANDLE aDbHandlers[EDB_MAX];
DWORD aDbUsers[EDB_MAX];
CENOTIFYREQUEST aNotifyReqs[EDB_MAX];
CEGUID m_ceguidInitDB;
CEOID oidDB=0;
HANDLE m_hDBCLog = INVALID_HANDLE_VALUE;
CEVOLUMEOPTIONS moPim = { 0 };
DWORD err= 0;
//CREATE_INVALIDEDBGUID(&m_ceguidInitDB);
moPim.wVersion = CEVOLUMEOPTIONS_VERSION;
moPim.dwFlags = CEDB_BUFFERPOOL;
moPim.cbBufferPool = EDBDATA_PIM_VOL_BUFFER;
err = GetLastError(); // if we see an error already... @#[email protected]#[email protected]# !!!
err=0; // clear the error variable so we can see it flip
BOOL MountResult = CeMountDBVolEx(&guidVol, L"\\pim.vol", &moPim, OPEN_EXISTING | EDB_MOUNT_FLAG);
err=GetLastError(); // even though MountResult returns true, err sees 87, ERROR_INVALID_PARAMETER
if(MountResult != TRUE)
{
return;
}
err=0; // clear the error variable so we can see it flip
m_hDBCLog =CeOpenDatabaseInSession( NULL,&m_ceguidInitDB, &oidDB, L"clog.db", 0, CEDB_AUTOINCREMENT, NULL);
err=GetLastError(); // err sees 87, ERROR_INVALID_PARAMETER
if (m_hDBCLog != INVALID_HANDLE_VALUE)
{
// todo: read the log entries, do some stuff, etc
// for some reason, m_hDBCLog does have an INVALID_HANDLE_VALUE... why?
err = 0;
}
CeUnmountDBVol(&m_ceguidInitDB);
Problem
Hi...
Have you seen the FileDB sample on whe Windows Mobile 6 SDK? I created my software using that example and it works fine.
RonaldoR9 said:
hi everybody,
i've got a strange problem using the edb functions in windbase_edb.h. i create a new c++ smartdevice project in vs2008, targeting Windows Mobile 6.1 Pro.
although CeMountDBVolEx returns true [ie successfully mounted], GetError() shows that some ERROR_INVALID_PARAMETER happened inside.
then, CeOpenDatabaseInSession returns an INVALID_HANDLE_VALUE handle, ie the call log didn't open, and GetError() shows that some ERROR_INVALID_PARAMETER happened inside again.
please help, what am i doing wrong?
thank you very much.
code as follows:
Code:
HWND hWnd;
CEGUID guidVol;
bool isVolMounted;
HANDLE aDbHandlers[EDB_MAX];
DWORD aDbUsers[EDB_MAX];
CENOTIFYREQUEST aNotifyReqs[EDB_MAX];
CEGUID m_ceguidInitDB;
CEOID oidDB=0;
HANDLE m_hDBCLog = INVALID_HANDLE_VALUE;
CEVOLUMEOPTIONS moPim = { 0 };
DWORD err= 0;
//CREATE_INVALIDEDBGUID(&m_ceguidInitDB);
moPim.wVersion = CEVOLUMEOPTIONS_VERSION;
moPim.dwFlags = CEDB_BUFFERPOOL;
moPim.cbBufferPool = EDBDATA_PIM_VOL_BUFFER;
err = GetLastError(); // if we see an error already... @#[email protected]#[email protected]# !!!
err=0; // clear the error variable so we can see it flip
BOOL MountResult = CeMountDBVolEx(&guidVol, L"\\pim.vol", &moPim, OPEN_EXISTING | EDB_MOUNT_FLAG);
err=GetLastError(); // even though MountResult returns true, err sees 87, ERROR_INVALID_PARAMETER
if(MountResult != TRUE)
{
return;
}
err=0; // clear the error variable so we can see it flip
m_hDBCLog =CeOpenDatabaseInSession( NULL,&m_ceguidInitDB, &oidDB, L"clog.db", 0, CEDB_AUTOINCREMENT, NULL);
err=GetLastError(); // err sees 87, ERROR_INVALID_PARAMETER
if (m_hDBCLog != INVALID_HANDLE_VALUE)
{
// todo: read the log entries, do some stuff, etc
// for some reason, m_hDBCLog does have an INVALID_HANDLE_VALUE... why?
err = 0;
}
CeUnmountDBVol(&m_ceguidInitDB);
Click to expand...
Click to collapse
rogeriodeluca said:
Hi...
Have you seen the FileDB sample on whe Windows Mobile 6 SDK? I created my software using that example and it works fine.
Click to expand...
Click to collapse
hi rogeriodeluca,
first of all, thank you for your suggestion. next, sorry it's taken so long for me to get back to you [life... don't talk to me about life!]
the filedb example you suggested creates a new database for the program to play with, and when run as is, works fine. unfortunately, when i fiddle the filedb code to try to open the pim.vol's contact database, i get exactly the same errors. running on the emulator, it returns the error code mentioned in my original post. running on the phone itself, it just craps out and goes back to the today screen.
i'm at my wit's end... anything else i can try?
RonaldoR9 said:
hi rogeriodeluca,
first of all, thank you for your suggestion. next, sorry it's taken so long for me to get back to you [life... don't talk to me about life!]
the filedb example you suggested creates a new database for the program to play with, and when run as is, works fine. unfortunately, when i fiddle the filedb code to try to open the pim.vol's contact database, i get exactly the same errors. running on the emulator, it returns the error code mentioned in my original post. running on the phone itself, it just craps out and goes back to the today screen.
i'm at my wit's end... anything else i can try?
Click to expand...
Click to collapse
Take a look at this link:
http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/d0caf390-cce6-4bef-ad0e-e9c05e63f050/
sorry, i forgot to return and say thank you!
thank you, your help was invaluable in figuring out this goofy problem!

ConnMgrEstablishConnectionSync is not good?

Hello,
I'm trying to establish connection to the internet using the following code, but not sure that this code is good.
I want to keep my connection for hours (it's a voip program), but the tcp sockets in my application are dropped every one hour or two. Although there is a disconnection, the device still has IP and still shows that it's connected to internet in the status bar on the top. I tried on lots of HTC devices (HD2, Pro2, Pro, etc...)
Can somebody tell if there is something wrong in the code?
Thanks,
Emil.
Code:
void Connect()
{
CONNMGR_CONNECTIONINFO ConnectionInfo;
ZeroMemory (&ConnectionInfo, sizeof (ConnectionInfo));
ConnectionInfo.cbSize = sizeof (ConnectionInfo);
ConnectionInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ConnectionInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
ConnectionInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ConnectionInfo.bExclusive = TRUE;
ConnectionInfo.guidDestNet = GetNetworkForURL (L"http://www.msn.com");
return ConnMgrEstablishConnectionSync (&ConnectionInfo, &m_hConnection, 30000, dwStatus);
}
void Disconnect()
{
HRESULT hr = ConnMgrReleaseConnection(m_hConnection, TRUE);
m_hConnection = NULL;
}
GUID ConnectionsManager::GetNetworkForURL (LPCTSTR url)
{
DWORD dwIndex = 0;
GUID rv;
if (!SUCCEEDED (ConnMgrMapURL (url, &rv, &dwIndex)))
rv = GUID_NULL;
return rv;
}

Categories

Resources