--- mstools/samples/deb/debmisc.c 2018/08/09 18:20:39 1.1 +++ mstools/samples/deb/debmisc.c 2018/08/09 18:21:30 1.1.1.2 @@ -1,33 +1,41 @@ // ************************************************************************ -// MODULE : DEBMisc.c +// +// Microsoft Developer Support +// Copyright (c) 1992 Microsoft Corporation +// +// ************************************************************************ +// MODULE : DEBMisc.C // PURPOSE : Miscellaneous support functions for the Debug Event Browser // FUNCTIONS : +// ErrorBox() - displays and error box when called // CreateTextButtonBar() - create a text button bar // OpenDebugee() - open a debugee application +// AttachToDebugee() - attach to a running process // ChooseNewFont() - choose a new font // ChooseNewBkColor() - choose a new background color // CopyListBoxToClipboard() - copies a listbox into the clipboard // ListBoxInsert() - insert a string into a listbox // ListBoxPrintF() - printf for listboxes // MakeDebugEventString() - creates standard event info string -// OrderFunc() - link list ordering function +// OrderFunc() - double linked list ordering function // EnumProcessListFunc() - enumeration func for active processes // GetPrivateProfileSettings() - gets stored profile settings // WritePrivateProfileSettings() - stores default settings in profile // UpdateMenuSettings() - update menu check marks // SubclassWindow() - generic window subclass func // WritePrivateProfileInt() - opposite of GetPrivateProfileInt() -// SendWmSizeMessage() - sends a WM_SIZE message with current size +// SendWmSizeMessage() - sends a WM_SIZE message with current +// size // GetPathFromFullPathName() - extracts path from a pathname // LongToCharUpper() - converts a long to upper-case string // COMMENTS : +// // ************************************************************************ +#define STRICT #include #include // GetOpenFileName(), ChooseFont(), etc. -#include // lstrlen(), lstrcpy(), lstrcat() -#include // ltoa() -#include // wsprintf(), vwsprintf() #include // va_list, va_start() +#include // ltoa(), abs() #include "LinkList.H" #include "ToolBar.H" @@ -42,6 +50,26 @@ TCHAR szInitialDir[256]; // ************************************************************************ +// FUNCTION : ErrorBox( LPCTSTR, LPCTSTR, LPCTSTR, int ) +// PURPOSE : +// COMMENTS : +// ************************************************************************ +int +ErrorBox( LPCTSTR lpszText, LPCTSTR lpszTitle, LPCTSTR lpszFile, int Line ) +{ + static char TextBuffer[512]; + + wsprintf( TextBuffer, "%s.\n\nFILE : %s\nLINE : %d\nGetLastError : %d\n\nPress Cancel to abort.", + lpszText, lpszFile, Line, GetLastError() ); + + if( MessageBox( GetDesktopWindow(), TextBuffer, lpszTitle, MB_OKCANCEL ) == IDCANCEL ) + ExitProcess( 0 ); + + return( 0 ); +} + + +// ************************************************************************ // FUNCTION : CreateTextButtonBar( HWND, LPINT ) // PURPOSE : Creates a Text Button Bar from the resource strings. // COMMENTS : Returns window handle to the created text button bar @@ -105,18 +133,17 @@ CreateTextButtonBar( HWND hWndParent, LP // ************************************************************************ -// FUNCTION : OpenDebugee( LPPROCESS_INFORMATION, LPSTARTUPINFO ) +// FUNCTION : OpenDebugee( ) // PURPOSE : Open a debugee and create a debug event processing thread // COMMENTS : Return TRUE on success else FALSE // ************************************************************************ BOOL -OpenDebugee( LPPROCESS_INFORMATION lpProcInfo, LPSTARTUPINFO lpStartInfo ) +OpenDebugee( ) { static BOOL fFirstTime = TRUE; static TCHAR szFilter[128]; static TCHAR szTitle[32]; - static TCHAR szDebugeeTitle[128]; static TCHAR szDirName[256]; static TCHAR szFile[256]; static TCHAR szFileTitle[256]; @@ -124,8 +151,8 @@ OpenDebugee( LPPROCESS_INFORMATION lpPro static OPENFILENAME OpenFileName; - HANDLE hDebugEventThread; - DWORD idDebugEventThread; + static HANDLE hDebugEventThread; + static DWORD idDebugEventThread; //-- Load resource strings and init the OpenFileName & lpProcInfo structs // (do this only one time) @@ -139,18 +166,6 @@ OpenDebugee( LPPROCESS_INFORMATION lpPro LoadString( hInstance, IDS_OFN_FILTER, &szFilter[FilterNameLen], (sizeof(szFilter)-(FilterNameLen))/sizeof(TCHAR) ); LoadString( hInstance, IDS_OFN_TITLE, szTitle, sizeof(szTitle)/sizeof(TCHAR) ); - LoadString( hInstance, IDS_OFN_DEBUGEE_TITLE, szDebugeeTitle, - sizeof(szDebugeeTitle)/sizeof(TCHAR) ); - - lpStartInfo->cb = sizeof( STARTUPINFO ); - lpStartInfo->lpDesktop = NULL; - lpStartInfo->lpTitle = szDebugeeTitle; - lpStartInfo->dwX = 0; - lpStartInfo->dwY = 0; - lpStartInfo->dwXSize = 0; - lpStartInfo->dwYSize = 0; - lpStartInfo->dwFlags = NULL; - lpStartInfo->wShowWindow = SW_SHOWDEFAULT; OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWndMain; @@ -182,19 +197,19 @@ OpenDebugee( LPPROCESS_INFORMATION lpPro sizeof(szInitialDir) ); //-- now start and detach the debug event processing thread - lpProcInfo->hProcess = NULL; - if( ( hDebugEventThread = CreateThread( + if( !(hDebugEventThread = CreateThread( (LPSECURITY_ATTRIBUTES) NULL, (DWORD) 0, (LPTHREAD_START_ROUTINE) DebugEventThread, (LPVOID) OpenFileName.lpstrFile, - (DWORD) NULL, + (DWORD) 0, (LPDWORD) &idDebugEventThread) ) ) { - - CloseHandle( hDebugEventThread ); - } - else + ErrorBox( "Failed", "CreateThread()", __FILE__, __LINE__ ); return( FALSE ); + } + CloseHandle( hDebugEventThread ); + + return( TRUE ); } @@ -535,7 +550,7 @@ EnumProcessListFunc( HWND hWnd, LPARAM l } } - return( !NULL ); + return( TRUE ); }