|
Hello, everyone!
I want to get the current bandwidth (input and output respectively) of a Windows system, for example, 20.2kB for input and 30.1kB for output.
Where can I find some sample codes?
Thanks in advance,
Geo
|
|
|
|
|
For Windows NT-based systems, look at the Performance Data Helper API. You'll be interested in the Bytes Received/sec and Bytes Sent/sec counters on the Network Interface object, I think.
|
|
|
|
|
Thanks, Mike buddy!
I have taken some time to read the API you introduced to me. They are really helpful. I am using the following source code to get in/out traffic bandwidth, but the output is always zero. Can you help?
Source Code:
----------
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <pdh.h>
#include "iphlpapi.h"
#include "Iptypes.h"
#include "Iprtrmib.h"
#pragma comment(lib,"iphlpapi.lib")
int main (int argc, char** argv)
{
unsigned long pOutBufLen = sizeof (IP_ADAPTER_INFO);
IP_ADAPTER_INFO AdapterInfo;
memset (&AdapterInfo, 0, sizeof (IP_ADAPTER_INFO));
MIB_IFROW ifrow;
DWORD last_sent, last_recv, current_sent, current_recv;
DWORD diftime, dlwinspeed, upwinspeed, dw_refreshtime;
if( GetAdaptersInfo(&AdapterInfo, &pOutBufLen) != ERROR_SUCCESS ){
printf("Could not open default interface!");
return ( 0 );
}
ifrow.dwIndex = AdapterInfo.Index;
if( GetIfEntry( &ifrow ) != NO_ERROR ) {
printf("Could not open default interface!");
return ( 0 );
}
while (1)
{
current_sent = ifrow.dwOutOctets - last_sent;
current_recv = ifrow.dwInOctets - last_recv;
last_sent = ifrow.dwOutOctets;
last_recv = ifrow.dwInOctets;
printf ("Octs out: %ld\n", ifrow.dwOutOctets);
printf ("Octs in: %ld\n", ifrow.dwInOctets);
diftime=(GetTickCount()-dw_refreshtime);
dlwinspeed = current_recv/diftime;
upwinspeed = current_sent/diftime;
dw_refreshtime=GetTickCount();
printf ("Band in: %ld\n", dlwinspeed);
printf ("Band out: %ld\n", upwinspeed);
Sleep (5000);
}
return 0;
}
----------
Best regards,
Geo
|
|
|
|
|
Hi, I'm having trouble adding a dialog to my mmc snap-in.
the problem occus when I create a dialog in response to a menu command. while the dialog works fine if the menu command is from the context of a top-level scope item, the actual dialog is offset within it's own frame if it comes from a second level menu item.
any help would be much appreciated
|
|
|
|
|
hi,
i using cdatetimectrl for registration form. for taking package need to add any dll for this control. i control not shown in the form. oninitdialog is failed i think this is due to the control. any one help to me.
thanks in advance.
Murali.M
|
|
|
|
|
Try using AfxOleInit()in the constructor of the dialog.
|
|
|
|
|
hi,
thanks for ur guide. actually my problem is after installing setup for the application and then the problem occurs. it's working fine on running source. i solved this problem. problem is mscomct2.ocx is not included while taking setup or package. after inserting the file. now working correctly.
once again thanks for guide.
Murali.M
|
|
|
|
|
From a different application, I tried to get other application handle using "HINSTANCT hInst = GetWindowLong(hWnd, GWL_HINSTANCE);" which I am using in the function "HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInst, GetWindowThreadProcessId(hWnd, NULL));".
But the handle returned by "SetWindowsHookEx()" is NULL (because of 'hInst').
Could someone help me to resolve this problem by suggesting a alternate solution for this?
Thanks in Advance,
Rajarajan V.
Rajarajan Veerichetty.
IBM Software Labs,
Bangalore
Mobile: +91-0-9845443206
|
|
|
|
|
The second parameter is NOT the HINSTANCE of the appliction you want to hook, but the HINSTANCE of the dll contaning the hook procedure.
so you can write a DllMain function, and store the HINSTANCE of the dll in a global viriable.when you call SetWindowsHookEx, use the global viriable as the second parameter.
|
|
|
|
|
Hi,
I am basically, C, VB, VB.NET programmer. I developed FTP client in vb.
But, I need to develop the FTP Client in VC++. Can anybody suggest me the ideas and links for developing the FTP client programme using vc++. and where to start with ?I have idea on vc++ and MFC. and I need to do it using sockets instead of wininet.
thanking you
Regards
Praveenp
|
|
|
|
|
There are many sites dedicated to Winsock all over the web...if you just type Winsock API into Yahoo Search you'll find. Also I have the book, Windows Sockets Network Programming, which is pretty thorough on the subject. You might want to give it a look see over at Amazon.com
|
|
|
|
|
I Create an application using SDI structure, I want to display the first screen as an HTML page, how could I do that ?
|
|
|
|
|
Derive your view class from CHTMLView!
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Can anyone tell me how to access/override/hook a rich edit control's select all (Ctrl + a). It throws up an error when trying to make any change to the selection or even select all a second time if there's more than one character for text.
For some reason, if there's only one character, then it works just dandy. It says there's an assertion error in "array_d.cpp" and so I assume it's doing something that doesn't mesh with my method of serializing the data (into DWordArrays). So, if anyone knows exactly what it IS doing (like what messages it's sending where, and how to get at them), that'd be great.
halblonious
|
|
|
|
|
I have no idea about your problems but I wait for ON_WM_KEYDOWN()
That's how I'm doing something on paste operation CTLT+V :
void MyEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ( (nChar == 0x56) )//VK_V
{
if ( GetKeyState(VK_CONTROL) & 0xff00 )
{//do something}
}
}
Mickey
|
|
|
|
|
Wouldn't be handling WM_PASTE (WM_COPY , WM_CUT , WM_CLEAR ) better?
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
That was only an example. AFAIK there's no special messages for CRTL+A or other non standard combinations. I must also say I didn't know messages you mentioned
Mickey
|
|
|
|
|
Thanks for the reply, and I may have to resort to that, but I'm trying not to have to subclass the rich edit if I can help it. There must be some other way, I'm hoping.
halblonious
|
|
|
|
|
Other than for repetitive strings.
Whats the advantage of this...
<br />
CString Str;<br />
Str.LoadString(IDS_STRING1);<br />
MessageBox(Str);<br />
Over this...
<br />
MessageBox("This is a string.");<br />
(BTW: IDS_STRING1 = "This is a string.")
??? I dont see the advantages.
Maybe somebody else can shed some light on the subject.
|
|
|
|
|
The advantage is it makes it easier for people to hack your code and make all the dialogs say stupid things.
Oh wait... that's a disadvantage
|
|
|
|
|
For some developers. They would like to pack their resource files into a DLL.
This is to allow different language version to be shipped easily by just changing the DLL instead of recompile the entire source code after changing the const String in the code line by line.
Some developers would like to have their const string to be placed into INI files instead.
Just some alternatives of doing the work.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Using string table, you can switch user interface between deferent languages.
Is this an advantage?
|
|
|
|
|
One word: translation. When you put all UI elements into resources, you can translate them without touching any of the C code. This is an incredibly meaningful fact since it reduces the amount of testing required on the translated version. If you touch any code, it has to be (or should be, at least) retested to make sure no typos happened while changing all the string literals.
It also lets a non-programmer translate the app. All they need is a resource editor.
If you never plan on translating, then... *shrug*
--Mike--
Ericahist [updated Oct 26] | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
Not to mention, if you ever have a need to change what a string says, it's easier to use the resource than search the code for the string definition. Every once in a while, I've wanted to modify a title or reword a message in one of my programs.
|
|
|
|
|
As people have said, for "easy" Internationalization and Localization of your strings.
It also makes it easier if you decide to support UNICODE.
I never hard-code strings, but if you're just writing some POS app then, maybe you don't want to use a string table.
The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices.
[Roger Wright on stupid people]
We're like private member functions
[John Theal on R&D]
We're figuring out the parent thing as we go though. Kinda like setting up Linux for the first time ya' know...
[Nitron]
|
|
|
|