Tech Support > Microsoft Windows > Development Resources > Help with Reading Registry Values
Help with Reading Registry Values
Posted by Radical NetSurfer on December 15th, 2004


I have yet to receive assistance on how to read some values
from the Windows 95/98SE registry, which will help me log
DUN-statistics. You can help by PLEASE sharing a URL
that might demonstrate how to do this using 'C',
and/or perhaps posting a snippet of code I can try out.
What specifically I am trying to do is shown below.
Thanks for the help.

If you can think of a better group to post this in, please let me
know, thanks.

I have C++Builder Code that does exactly what I want a
Console32 application to do under Windows 95 and 98SE,
and I am trying to port this to 'C' and simply display
the information in a dosbox...

/* C++Builder VCL Code

MyReg->RootKey = HKEY_DYN_DATA;
if(MyReg->OpenKey("PerfStats\\StatData", false))
{
try {
MyReg->ReadBinaryData("Dial-Up Adapter\\BytesXmit", &BytesSent,
sizeof(long));
MyReg->ReadBinaryData("Dial-Up Adapter\\BytesRecvd", &BytesRcvd,
sizeof(long));
MyReg->ReadBinaryData("Dial-Up Adapter\\ConnectSpeed", &BaudRate,
sizeof(long));
}
catch (...)
{ /* you'll probably never see this */
printf("\nException has been thrown: DUN_STATS\n\n");
exit(0);
}
MyReg->CloseKey();
}

MyReg->Free();
*/

My attempt to use simple WinAPI calls to do the same thing...
I would appreciate a little help here please. I just want to READ
these
values out of the Registry and display them out, nothing more.
If a person is using Dial-Up, these values are updated.

void DUNStats(void) {
FILE *outfile;
unsigned char buf[12];
unsigned char *pbuf=NULL;
long BytesSent = 0;
long BytesRcvd = 0;
long BaudRate = 0;

char szBuffer[256];
LPTSTR lpszBuffer;
HKEY hKeyResult = 0;
DWORD dwDisposition;
DWORD dwType;
DWORD dwBytes = 128;
LONG lResult;

pbuf = &buf[0];

lResult = RegOpenKeyEx( HKEY_DYN_DATA, "PerfStats\\StatData",
0, KEY_ALL_ACCESS, &hKeyResult );

RegQueryValueEx( hKeyResult, "Dial-Up Adapter\\BytesXmit",
0, &dwType, szBuffer, &dwBytes );


LONG RegGetValue( hKeyResult, "Dial-Up Adapter\\BytesXmit",
LPCTSTR lpValue,
DWORD dwFlags,
LPDWORD pdwType,
PVOID pvData,
LPDWORD pcbData
);

//...BytesSent=atol(szBuffer);

RegCloseKey( hKeyResult );

//Display data
printf("DUNstats Sent: %d Rcvd: %d Connect: %d\n",
BytesSent, BytesRcvd, BaudRate);

}

This is what I just threw together; I know it is not yet ready!

I hope someone can please help me with this simple routine...

Email: RadSurfer@yahoo.com


Similar Posts