Finding/terminating processes (VC6 applications) from a VS10 application?
Having a bit of a problem so thought by asking it should point me in the righ开发者_如何学Pythont direction. I have a .dll that I have moved from VC6 to Visual Studio 2010. The point of this application is to find the processes of two particular applications (which are custom C++ VC6) and terminate them - simple as that.
Upon moving to Visual Studio 2010, the only changes required were to change a method to return a reference of a stream when overloading and to slightly modify the boost smart pointer (so that it is created how it should be with new string() etc. That code appears to be correct.
However, now I am getting two errors when using this .dll.
a) One application that should be terminated gives an error: "This application has requested the Runtime to terminate it in an unusual way."
b) The second application doesn't terminate, but instead gives an error: "Pure Virtual Function Called".
Aside from the small code changes above (I won't paste any code just yet as there are about 8 classes worth) NOTHING else was changed. Surely the methods used to find and terminate/kill a process that worked in VC6 would be the same in Visual Studio 10 right?
There shouldn't be an issue with having a VC10 .dll killing a VC6 application (or causing those errors...)?
Or could this be unique to my computer (i.e. not caused by the .dll but by the fact I have different windows API on my computer - as I have installed VS10).
Bit confused on this one?!
The code that stops the process is:
HANDLE processHandle = ::OpenProcess( PROCESS_ALL_ACCESS, FALSE, processId_ );
if( processHandle != NULL )
{
::EnumWindows( (WNDENUMPROC)stopProcessWindowEnumerator, processId_ );
if( ::WaitForSingleObject( processHandle, 1000 ) != WAIT_OBJECT_0 )
{
::TerminateProcess( processHandle, 0 );
::WaitForSingleObject( processHandle, 1000 );
}
}
Code for stopProcessWindowEnumerator:
BOOL CALLBACK RunningProcess::stopProcessWindowEnumerator( HWND hWnd, LPARAM lParam )
{
DWORD processIdToStop = (DWORD)lParam;
DWORD enumeratedWindowsProcessId;
::GetWindowThreadProcessId(hWnd, &enumeratedWindowsProcessId);
if( processIdToStop == enumeratedWindowsProcessId )
{
::PostMessage( hWnd, remoteCloseMessage, 0, 0);
return FALSE;
}
return TRUE;
}
"Pure Virtual Function Called" is usually an indicator of a bug in the code. It happens usually when a virtual function is called from within the context of a ctor or dtor, or when being called on an already destructed object.
It is quite likely that this bug was lurking in your code all the time, but was not triggered (or had no consequences, VC6 is known to implement something that does not deserve to be called "standard C++").
To the other error, I have no idea, but are you sure that the way you ask it to terminate isn't an "unusual" way?
I doubt your interface definition. It's hard to guess without seeing the definitions. Please go through the following articles, which could help you to figure out what's wrong
- http://www.artima.com/cppsource
- http://support.microsoft.com/kb/125749
精彩评论