|
mikey_eff wrote: How can I programmatically get this connection speed for a specific interface? I am constrained to using C and the Windows API.
You can use the Performance API (aka, Performance Data Helper) for this. The Object name is Network Interface. The Instance name is machine specific (eg, Intel[R] PRO_100 VE Network Connection - Packet Scheduler Miniport). The Counter name is Current Bandwidth.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Having a bit of trouble. Getting PDH_NO_DATA when calling PdhCollectQueryData. Here is my code:
#define COUNTER "\\Network Interface(Intel(R) 82566DM-2 Gigabit Network Connection - Packet Scheduler Miniport)\\Current Bandwidth"
HQUERY query;
HCOUNTER counter;
PDH_FMT_COUNTERVALUE value;
DWORD counterType;
PDH_STATUS status;
if((status = PdhOpenQuery((LPCSTR)NULL,(DWORD_PTR)NULL,&query)) == ERROR_SUCCESS){
if((status = PdhAddCounter(query,COUNTER,(DWORD_PTR)NULL,&counter)) == ERROR_SUCCESS){
if((status = PdhCollectQueryData(query)) == ERROR_SUCCESS){
if((status = PdhGetFormattedCounterValue(counter,PDH_FMT_DOUBLE|PDH_FMT_NOSCALE,&counterType,&value)) == ERROR_SUCCESS){
printf("Counter = %f\n",value.doubleValue);
}else{
printf("ERROR: PdhGetFormattedCounterValue() failed. Error Code: %X\n",status);
}
}else{
printf("ERROR: PdhCollectQueryData() failed. Error Code: %X\n",status);
}
}else{
printf("ERROR: PdhAddCounter() failed. Error Code: %X\n",status);
}
PdhCloseQuery(query);
}else{
printf("ERROR: PdhOpenQuery() failed. Error Code: %X\n",status);
}
|
|
|
|
|
mikey_eff wrote: #define COUNTER "\\Network Interface(Intel(R) 82566DM-2 Gigabit Network Connection - Packet Scheduler Miniport)\\Current Bandwidth"
You are missing the name of your machine:
#define COUNTER "\\\\machine\\Network Interface(Intel(R) 82566DM-2 Gigabit Network Connection - Packet Scheduler Miniport)\\Current Bandwidth"
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks. That got things working.
Note: I struggled for a bit until I discovered that the name of my adaptor -- "Intel(R) 82566DM-2..." -- was causing me grief because of the "(R)". Had to change the round brackets to square brackets -- "[R]" -- to get it to work.
Mike.
|
|
|
|
|
Hi Mikey,
If you use the IP Helper library[^] then you can do this:
#include "Iphlpapi.h"
#pragma comment(lib, "iphlpapi.lib")
VOID PrintEthernetSpeeds()
{
BYTE *pBuf=NULL;
DWORD dwSize=0;
DWORD dwResult=0;
BOOL bConnected=FALSE;
PMIB_IFTABLE pMIBTable;
CString str;
GetIfTable(NULL,&dwSize,FALSE);
pBuf=new BYTE[dwSize];
pMIBTable=reinterpret_cast<PMIB_IFTABLE>(pBuf);
if(NO_ERROR == GetIfTable(pMIBTable,&dwSize,FALSE))
{
for(UINT i=0; i < pMIBTable->dwNumEntries; ++i)
{
if(MIB_IF_TYPE_ETHERNET == pMIBTable->table[i].dwType)
{
char szBuf[MAX_PATH];
sprintf(szBuf,"%s is %ld\n",pMIBTable->table[i].bDescr,pMIBTable->table[i].dwSpeed);
TRACE(szBuf);
}
}
}
delete []pBuf;
}
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks! Works great. Modified code slightly for ANSI C. See below ...
Mike.
BYTE *pBuf=NULL;
DWORD dwSize=0;
DWORD dwResult=0;
BOOL bConnected=FALSE;
PMIB_IFTABLE pMIBTable;
UINT i;
GetIfTable(NULL,&dwSize,FALSE);
pBuf=(BYTE *)malloc(dwSize);
pMIBTable=(PMIB_IFTABLE)pBuf;
if(NO_ERROR == GetIfTable(pMIBTable,&dwSize,FALSE))
{
for(i=0; i < pMIBTable->dwNumEntries; ++i)
{
if(MIB_IF_TYPE_ETHERNET == pMIBTable->table[i].dwType)
{
printf("%s is %ld\n",pMIBTable->table[i].bDescr,pMIBTable->table[i].dwSpeed);
}
}
}
free(pBuf);
|
|
|
|
|
It's a Win32 FAQ
see on Win32 ng http://tinyurl.com/cmhb5g
(from Windows+Wine source code, net apis...)
|
|
|
|
|
plz help me.This is my code
CFile cTestFile;
cTestFile.Open(_T("D:\\Jitu.txt"),CFile::modeCreate | CFile::modeReadWrite);
CArchive ar(&cTestFile,CArchive::store);
m_pRecordSet = new CDaoRecordset(m_pDatabase);
CString strQuery = _T("SELECT * FROM pdpstate ORDER BY pdpstate.setid");
m_pRecordSet->Open(dbOpenDynaset,strQuery,0);
int nRecordCnt = m_pRecordSet->GetRecordCount();
int nFieldCnt = m_pRecordSet->GetFieldCount();
int ntemp = 8;
COleVariant variantTemp;
for(int nCnt = 0; nCnt < nRecordCnt; nCnt++)
{
for(int nfCnt = 0; nfCnt < nFieldCnt; nfCnt ++)
{
variantTemp.Clear();
variantTemp = m_pRecordSet->GetFieldValue(nfCnt );
CString csSetID;
csSetID.Format(_T("%d"),variantTemp.intVal);
cTestFile.Write(csSetID,sizeof(csSetID));
cTestFile.Write(_T(","),1);
}
}
cTestFile.Close();
Raj
modified on Thursday, September 10, 2009 11:23 PM
|
|
|
|
|
Actually if you want remove all spaces, then one solution is :-
1. Just open the file in write mode and read all the content of the file in a CStringArray line by line using CArchive.
2. Before setting the content to CStringArray, just use the CString ::Remove function to remove the space.
3. Delete the current file.
4. Create a new file and write the CStringArray content to the new file.
Величие не Бога может быть недооценена.
|
|
|
|
|
jadhavjitendrar wrote: cTestFile.Write(csSetID,sizeof(csSetID));
What is the purpose of the above line?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for reply..
Actually this line is used for writing data to text file.bcoz i m reading data from mdb file and writing it into text file so that purpose this line is used..So plz give me solution ,it's urgent..
|
|
|
|
|
The line is wrong: you should replace it with
cTestFile.Write(csSetID, csSetID.GetLength() * sizeof(TCHAR));
Anyway, I doubt this is what you really want to do (i.e. Are you trying to write a wide-char text file?)?
jadhavjitendrar wrote: So plz give me solution ,it's urgent..
I recall you one of the implicit mechanism of this forum: "urgentz requests go directly inside the recycle bin".
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
jadhavjitendrar wrote: for(int nCnt = 0; nCnt < nRecordCnt; nCnt++)
{
for(int nCnt = 0; nCnt < nFieldCnt; nCnt++)
The inner and outer loop should use different variables.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I have a doubt whether Microsoft Excel will support data of unicode big endian encoded type...
I tried manually pasting unicoded big endian encoded data.. it was showing junk characters...
I have a doubt whether MS Excel 2007 will support Unicode Big Endian type for saving and opening..
Thanks,
Rakesh.
|
|
|
|
|
Hi,
How to delete a folder along with the files inside it...
|
|
|
|
|
|
just refer [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
RemoveDirectory() only deletes empty directories. To delete files and folders simultaneously, use SHFileOperation() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi All
How to read Image's RGB value (only block and white)
kindly give me your solution
Regards
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
You may use CBitmap::GetBitmapBits [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi Pal
thanks for replay ..
it can possible load jpeg images and it can possible to render the images w.r.t RGB
regards
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
|
rajugis wrote: it can possible load jpeg images
You may use CImage class for the purpose, see CImage::Load [^] and, for instance, CImage::GetPixel [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Just in addition to CPallini's post.
If you decide to use CImage class you will notice that the GetPixel and SetPixel methods are slow. So if you need a fast pixel access you can use this[^] class with combination of CImage class.
Using CxImage[^] library could also be an option.
Regards
Nuri Ismail
|
|
|
|
|
Nuri Ismail wrote: Just in addition to CPallini's post.
If you decide to use CImage class you will notice that the GetPixel and SetPixel methods are slow.
That was the reason of 'for instance'.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|