|
Hello,
sometimes I got a network cable disconnect or network cable unplugged event, and I would like to develop a small app to check when it happens and to log it, what api should I use??
Thanks in advance
Paolo
|
|
|
|
|
Check out the ISensNetwork interface.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
It is the code from MSDN
It complies and links but does not executes giving the following error
File:i386\chkesp.c
line:48
The value of ESP was not properly saved across a fuction call.This is usually a result of calling function decleared with one calling convention with a funciton pointer decleared with a different calling convention.
#include <windows.h>
#include <setupapi.h>
#include <stdio.h>
DWORD Err;
HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid)
/*
Routine Description:
Retrieves the device information set that contains that contains
the devices of the specified class.
Parameters:
InterfaceClassGuid - The interface class GUID.
Return Value:
If the function succeeds, the return value is a handle to the
device information set.
If the function fails, the return value is zero.
*/
{
HDEVINFO DeviceInfoSet;
HDEVINFO NewDeviceInfoSet;
// Create a device information set that will be the container for
// the device interfaces.
DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);
if(DeviceInfoSet == INVALID_HANDLE_VALUE) {
Err = GetLastError();
printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err );
return 0;
}
// Retrieve the device information set for the interface class.
NewDeviceInfoSet = SetupDiGetClassDevsEx(
&InterfaceClassGuid, // address of guid required
NULL, // no enumerator
NULL, // no parent window handle (might not be a good idea…)
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, // flags
//DeviceInfoSet, // do not pass this in, not in function prototype
NULL, // NULL implies local machine
NULL // Reserved’ must be null
);
if(NewDeviceInfoSet == INVALID_HANDLE_VALUE)
{
Err = GetLastError();
printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err );
return 0;
}
return NewDeviceInfoSet;
}
int main(int argc, TCHAR* argv[])
{
GUID var;
DoDeviceEnum(var);
return 0;
}
|
|
|
|
|
Put a breakpoint on the SetupDiCreateDeviceInfoList() statement and single-step through the code until you get to the statement that causes the error.
I cleaned up your code a bit to look like:
HDEVINFO DoDeviceEnum( void )
{
GUID InterfaceClassGuid;
HDEVINFO DeviceInfoSet,
NewDeviceInfoSet;
DeviceInfoSet = SetupDiCreateDeviceInfoList(&InterfaceClassGuid, NULL);
if (DeviceInfoSet != INVALID_HANDLE_VALUE)
{
NewDeviceInfoSet = SetupDiGetClassDevsEx(&InterfaceClassGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE,
DeviceInfoSet,
NULL,
NULL);
if (NewDeviceInfoSet != INVALID_HANDLE_VALUE)
;
else
printf("SetupDiGetClassDevsEx failed: %lu.\n", GetLastError());
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
}
else
printf("SetupDiCreateDeviceInfoList failed: %lu.\n", GetLastError());
return NewDeviceInfoSet;
}
void main( void )
{
DoDeviceEnum();
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I had created a structure with six members of type CString.
I am trying to send this structure using the 'Send' command.
A Pointer object is created for the structure.
At the receiving end i had created the same structure. But when i was trying to display the data , I got only a blank message box.
Can anyone solve this problem?
source prg
..........
Struct message
{
CString name;
...
};
message *obj=new message();
Send(obj,sizeof(struct message));
dest prog
........
Struct message
{
CString name;
...
};
message *obj=new message();
Receive(obj,sizeof(struct message));
MessageBox(obj->name); //blank message box was displayed ?
vinsankar
|
|
|
|
|
The problem with your code is that sizeof(struct message) is going to return the same number no matter what the size of the string. That is because the CString class has a pointer to a buffer which contains the actual string. You have just stumbled upon a problem that occurs very often. There are many ways around this, but the simpliest one I can think of would be to change your struct to:
<br />
struct message<br />
{<br />
char name[256];<br />
};<br />
sizeof(struct message) would then return 256. This method is inefficient, as the whole buffer would be transferred, and it would be tougher to work with the char arrays instead of the CString's.
Greba,
My lack of content on my home page should be entertaining.
|
|
|
|
|
why can't we use CString instead of character arrays ?
I am in need of CString values at the receving end.Because I
have to perform some trimming operations at the receiving side.
What is the real problem while displaying the values stored in structure?
Is there any other way to send a structure through the 'Send' command?
vinsankar
|
|
|
|
|
Hi,
I'm having trouble with using a particular COM object in an MFC application. Here's what happens. I create a brand new MFC application put some code in the message handler to initialize COM, create object, set some properties on the object etc. That works fine. However when I try the exact same code inside another, bigger application the code doesn't work.
First CoInitialize() returns RPC_E_CHANGED_MODE. I have no idea why because this is the first time I call it in the code. I use many other libraries it may be possible that some other library has initialize it. I can either ignore this returned value or put CoInitialize and other code into a thread, in either case problem 2 occurs.
Second, the program doesn't behave as it should. I try to debug it by stepping through the code. CoCreateInstance() works fine, then I set some options on this created instance, that works fine. Then I call another function and MSVC++ displays "First-chance exception...(NTDLL.DLL): Invalid Handle" and I can't debug any further.
How can I debug this? This particular code is identical between the two applications. Both applications seem to have the same project settings. I'm just out of ideas.
|
|
|
|
|
Does anybody know how many symbols maximum, a CString object can contain ?
Thanks in advance
Giorgi Moniava
|
|
|
|
|
The amount of memory your program gets should be the limit of CString size.
|
|
|
|
|
Take a look at CString::AllocBuffer() . You'll notice that it is INT_MAX .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
the index of a CString object is an int . could you find the size now ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
The theoretical limit is INT_MAX , or 2GB. But since the buffer has to be contiguous block of memory, and you won't be able to allocate a 2GB block in your process space, the practical limit is much less.
--Mike--
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
I wonder how to send and catch events in MFC. I’m well known how a CWnd is catching an “regular” winows envent but if I like to catch an event from:
class A { … }
to
class B { … }
?
_____________________________
...and justice for all
APe
|
|
|
|
|
Have you searched MSDN for TRY , CATCH() , and THROW() ?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
For me that is about Exception handling...
_____________________________
...and justice for all
APe
|
|
|
|
|
My bad. What exactly do you mean by "events?"
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
depending on the relation between A and B there are numerous ways of "catching" events ...
if A and B know each other ( i.e. A includes a pointer/reference to B, or vice-versa ), you can directly call methods from A to B ( or vice-versa )
if A and B do not know each other ( or you don't want to make them know each other ), you can make them inherit from CCmdTarget and use SendMessage/PostMessage and handle your user message in each class
if you don't want to have a dependency on MFC/Win32, you could use one form of the Observer Pattern to register each class as either observer or observable to send message between them.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
if A and B do not know each other ( or you don't want to make them know each other ), you can make them inherit from CCmdTarget and use SendMessage/PostMessage and handle your user message in each class
-> Thats what I want!
I've successfuly "cached" a SendMessage(...) in a CWnd derived class but I don't get it to work between two generic (my own created classes). Really glad for an Articel in this subject, but have not found any here at CP...
_____________________________
...and justice for all
APe
|
|
|
|
|
d00_ape wrote:
Really glad for an Articel in this subject, but have not found any here at CP...
Once you get it figured out, why don't you write up an article on it?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Fore sure I will.
_____________________________
...and justice for all
APe
|
|
|
|
|
When I attempt to print a CView, the size of the output is way to big. Where/how do I scale down? I suspect it will be somewhere in virtual overrridables like OnPreparePrinting/OnBeginPrinting.
Do I need to reset the Map Mode? Basically I need to reduce the horizontal/vertical display to about a 25% of the size. The whole area to be displayed is correct, just the scale is not.
|
|
|
|
|
The last time I did something like this, it required several things. See this article for an example. I think I left some code commented out in the GDITestView.cpp file that prepares the DC for printing.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hi all,
what i want to do is add an extra popup-menu to the "workspace" in visual studio.
currently you have menus options such as "New Folder", "Compile", "Settings ..." etc.
i want to add another that when chosen will fire my code.
the reason for this? well we use command line pvcs and its a real hassle to keep going back to a command prompt and cd-ing all over the place just to lock/unlock a file.
my life would be much easier if i could just have another popup-menu in the workspace area from which i could fire the pvcs commands!
so any of you gurus have a suggestion?
cheers
|
|
|
|
|
in the undocumented part in codeproject you will find examples on how to hook into the visual studio components. (it usually involved *.PKG file or a COM-Addin).
look at wndtabs project also posted here at codeproject....
hope this helps ya
cheers
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|