void Terminate()
{
	fClosing = TRUE;
	if( ghWorkerWindow && IsWindow( ghWorkerWindow ) )
		DestroyWindow( ghWorkerWindow );
	if( ghDiscoverWindow && IsWindow( ghDiscoverWindow ) )
		DestroyWindow( ghDiscoverWindow );
	else
		SignalFinish();
}
Exemple #2
0
int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) 
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    DWORD ChildRetCode = 0;
    DWORD ParentRetCode = 0;
    DWORD BytesRead;
    char DataBuffer[BUF_SIZE];
    
    
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    
    /* Load up the helper Process, and then Wait until it signals that it
       is finished locking.
    */
    if(!CreateProcess( NULL,Helper,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) 
    {
        Fail("ERROR: CreateProcess failed to load executable '%s'.",Helper);
    }

    SignalAndBusyWait(WaitFile);
   
    /* Now the child proccess has locked another section of the file, from
       bytes 11 through 20.  Let's check that the parent lock is still ignored
       by the parent proccess and that the child's lock is respected.
    */

    if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0)
    {
        Trace("ERROR: ReadFile failed when attempting to read a section of "
              "the file which was locked by the current process.  It should "
              "have been able to read this.  GetLastError() returned %d.",
              GetLastError());
        ParentRetCode = 1;
    }

    SetFilePointer(TheFile, 11, 0, FILE_BEGIN);

    if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0)
    {
        Trace("ERROR: ReadFile returned success when it should "
              "have failed.  Attempted to read 10 bytes of the file which "
              "were locked by the child.");
        ParentRetCode = 1;
    }

    /* We're finished testing.  Let the child proccess know so it can clean
       up, and the parent will wait until it is done.
    */
    SignalFinish(WaitFile);
    WaitForSingleObject(pi.hProcess,INFINITE);
  
    /* Get the return value from the helper process */
    if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0)
    {
        Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve "
             "the exit code of the child process.");
    }

    if(CloseHandle( pi.hProcess ) == 0) 
    {
        Fail("ERROR: CloseHandle failed to close the process.");
    }

    if(CloseHandle( pi.hThread ) == 0)
    {
        Fail("ERROR: CloseHandle failed to close the thread.");
    }

    return (ChildRetCode || ParentRetCode);
}
Exemple #3
0
int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) 
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    DWORD ChildRetCode = 0;
    DWORD ParentRetCode = 0;
        
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    
    /* Load up the helper Process, and then Wait until it signals that it
       is finished locking.
    */
    if(!CreateProcess( NULL, Helper, NULL,
                       NULL, FALSE, 0,
                       NULL, NULL, &si, &pi)) 
    {
        Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper);
    }

    SignalAndBusyWait(WaitFile);
    
    /* When the child proccess is finished setting its lock and testing the
       parent lock, then the parent can test the child's lock.
    */

    if(UnlockFile(TheFile, 10, 0, 10, 0) != 0)
    {
        Trace("ERROR: The parent proccess called Unlock on the child "
              "proccesses lock, and the function returned non-zero, when "
              "it should have failed.\n");
        ParentRetCode = 1;
    }
    
    /* Switch back to the child so that it can unlock its portion and 
       cleanup.
    */

    SignalFinish(WaitFile);
    WaitForSingleObject(pi.hProcess,INFINITE);
  
    /* Get the return value from the helper process */
    if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0)
    {
        Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve "
             "the exit code of the child process.\n");
    }

    if(CloseHandle( pi.hProcess ) == 0) 
    {
        Fail("ERROR: CloseHandle failed to close the process.\n");
    }

    if(CloseHandle( pi.hThread ) == 0)
    {
        Fail("ERROR: CloseHandle failed to close the thread.\n");
    }

    return (ChildRetCode || ParentRetCode);
}
LRESULT CALLBACK
GetMsgHookProc(
    INT hc,
    WPARAM wParam,
    LPARAM lParam
    )
{
    
	//WaitForSingleObject( ghMutex, INFINITE );
	PMSG pmsg;
	static int i = 1;
	pmsg = (PMSG)lParam;
	LRESULT lResult = 0;
	
	if( i==1 )
	{
		i++;
		if ( GetWindowHandles() ) // Get handles of all windows we are interested in
		{
			if ( InitSubclass() )		// Subclass window procedures
			{
				
				ghWorkerWindow = CreateWorkerWindow( ghDeveloperStudioWnd );
				ghDiscoverWindow = CreateDiscoverWindow( ghOutputWnd );
				if( !(ghDiscoverWindow && ghWorkerWindow) )
				{
					SignalFinish();
				}
				else
				{
					GetConfiguration();
					GetDDEClient()->CommandToServer( IDE_MSG_SPYSTARTED, gpszConfiguration );
          PostMessage( ghDiscoverWindow, WM_COMMAND, (WPARAM)ID_ACTIVBROWSER, 0L );
				}
			}
			else
				SignalFinish();
		}
		else
			SignalFinish();
	}
	else
	{
		switch( pmsg->message )
		{
		case WM_LBUTTONDBLCLK:
			if( pmsg->wParam == (MK_CONTROL|MK_LBUTTON) )
			{
				HWND hParent = GetParent( pmsg->hwnd );
				if( hParent )
					hParent = GetParent( hParent );
				if( hParent )
				{
					char buffer[TITLE_LENGTH];
					if( GetWindowTextLength( hParent ) )
						GetWindowText( hParent, buffer, sizeof( buffer ) - 1 );
					else
						buffer[0] = '\0';
					if(	(GetParent( hParent )==ghMDIClientWnd) &&
							_stricmp( buffer, "InfoViewer Topic" /*don't care about help windows*/ ) 
							&& ghWorkerWindow )
						//Send Double-Click Event
					{
						PostMessage( ghWorkerWindow, WM_USERSHIFTDBLCLK, 0L, 0L );
					}
				}
			}
			break;
		}


	}


  if( !fClosing)
		lResult = CallNextHookEx(NULL, hc, wParam, lParam);
	//ReleaseMutex( ghMutex );
	return lResult;
}