Exemplo n.º 1
0
XERCES_CPP_NAMESPACE_USE

// ----------------------------------------------------------------------------
// WinMain
//
// Windows equivalent of main. 
// ----------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
				   LPSTR lpCmdLine, int nCmdShow)
{
	// the message thats collected and dispatched
	MSG   Msg;
	// the name of the class to build a window
	char *ClsName = "Main window class";
	// the name printed on an individual window
	char *WndName = "Mamoview";

	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	// Some code thats necessary to initialise gdi, don;t know how it
	// works must just call some things in the dll
    Gdiplus::GdiplusStartupInput gdiplusStartupInput; 
	ULONG_PTR gdiplusToken; 
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	try {
	 XMLPlatformUtils::Initialize();
	}
	catch (const XMLException& toCatch) {
    // Do your failure processing here
    return 1;
	}

  // Do your actual work with Xerces-C++ here.

  


	
	// Declare and initialize the application class, which contains data needed
	// to make a window in the first place
	WApplication WinApp(hInstance, ClsName, WndProc, IDR_MENU1);
	WinApp.Register();

	// // Declare a MainWnd object which represents what is seen graphically
	// and then create it
	MainWnd Wnd;
	/*HWND Create(HINSTANCE hinst,                        // application instance
		        LPCTSTR clsname,						// the name of the window class
     		    LPCTSTR wndname,						// the name of the window
	            HWND parent   = NULL,					// the parent window reference
	            DWORD dStyle  = WS_OVERLAPPEDWINDOW,	// the window style
	            DWORD dXStyle = 0,						// extended window style
		        int x         = 10,			// x position of the window
                int y         = 10,			// y position of the window
		        int width     = 300,			// width of the window
                int height    = 300);			// height of the window*/
	Wnd.Create(hInstance, ClsName, WndName, NULL, WS_OVERLAPPEDWINDOW | 
				WS_CLIPCHILDREN,WS_EX_LAYERED | WS_EX_OVERLAPPEDWINDOW );
	// Display the main window
	Wnd.Show();
	

	//prepareGraphics();
	// Process the main window's messages
	while( GetMessage(&Msg, NULL, 0, 0) )
	{
		// convert virtual key messages to character ones and put back into message queue
		TranslateMessage(&Msg);
		// send to window procedure, of which there might be a few in 1 app
		DispatchMessage(&Msg);
	}
	Gdiplus::GdiplusShutdown(gdiplusToken); 
	XMLPlatformUtils::Terminate();
	return 0;
} // --- WinMain --------------------------------------------------------------
Exemplo n.º 2
0
int
WINAPI
WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpCmdLine,
    int       nShowCmd
    )
{
    CHAR            ProgName[MAX_PATH];
    CHAR            Arguments[MAX_PATH*2];
    DWORD           i;
    OSVERSIONINFO   OsVersionInfo;


    //
    // see if we are running on NT
    // this is necessary because APIMON implements some
    // features that are NOT available on WIN95
    //
    OsVersionInfo.dwOSVersionInfoSize = sizeof(OsVersionInfo);
    GetVersionEx( &OsVersionInfo );
    RunningOnNT = OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;

    sym->SizeOfStruct  = sizeof(IMAGEHLP_SYMBOL);
    sym->MaxNameLength = MAX_SYMNAME_SIZE;

    //
    // jack up our priority class
    //
    SetPriorityClass(
        GetCurrentProcess(),
        HIGH_PRIORITY_CLASS
        );

    //
    // process the command line
    //
    LPSTR p = NULL;
    LPSTR CmdLine = GetCommandLine();
    DWORD GoImmediate = 0;
    ProgName[0] = 0;
    Arguments[0] = 0;
    //
    // skip the program name
    //
    while( *CmdLine && *CmdLine != ' ' ) {
        CmdLine += 1;
    }
    //
    // skip any white space
    //
    while( *CmdLine && *CmdLine == ' ' ) {
        CmdLine += 1;
    }
    //
    // get the command line options
    //
    while( *CmdLine && (*CmdLine == '-' || *CmdLine == '/') ) {
        CmdLine += 1;
        CHAR ch = tolower(*CmdLine);
        CmdLine += 1;
        switch( ch ) {
            case 'g':
                GoImmediate = TRUE;
                break;

            case 'b':
                BreakInNow = TRUE;
                break;

            case 'f':
                StopOnFirstChance = TRUE;
                break;

            case 't':
                do {
                    ch = *CmdLine++;
                } while (ch == ' ' || ch == '\t');
                i=0;
                while (ch >= '0' && ch <= '9') {
                    i = i * 10 + ch - '0';
                    ch = *CmdLine++;
                }
                UiRefreshRate = i;
                break;

            case '?':
                DialogBox( hInstance, MAKEINTRESOURCE( IDD_HELP ), NULL, HelpDialogProc );
                ExitProcess(0);
                break;

            default:
                printf( "unknown option\n" );
                return 1;
        }
        while( *CmdLine == ' ' ) {
            CmdLine += 1;
        }
    }

    if (*CmdLine) {
        //
        // skip any white space
        //
        while( *CmdLine && *CmdLine == ' ' ) {
            CmdLine += 1;
        }
        //
        // get the program name
        //
        p = ProgName;
        while( *CmdLine && *CmdLine != ' ' ) {
            *p++ = *CmdLine;
            CmdLine += 1;
        }
        *p = 0;
        if (*CmdLine) {
            //
            // skip any white space
            //
            while( *CmdLine && *CmdLine == ' ' ) {
                CmdLine += 1;
            }
            if (*CmdLine) {
                //
                // get the program arguments
                //
                p = Arguments;
                while( *CmdLine ) {
                    *p++ = *CmdLine;
                    CmdLine += 1;
                }
                *p = 0;
            }
        }
    }

    ReleaseDebugeeEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
    if (!ReleaseDebugeeEvent) {
        return FALSE;
    }

    ApiMonMutex = CreateMutex( NULL, FALSE, "ApiMonMutex" );
    if (!ApiMonMutex) {
        return FALSE;
    }

    if (GetLastError() == ERROR_ALREADY_EXISTS) {
        return FALSE;
    }

    //
    // create the shared memory region for the api counters
    //
    hMap = CreateFileMapping(
        (HANDLE)0xffffffff,
        NULL,
        PAGE_READWRITE | SEC_COMMIT,
        0,
        MAX_MEM_ALLOC,
        "ApiWatch"
        );
    if (!hMap) {
        return FALSE;
    }

    MemPtr = (PUCHAR)MapViewOfFile(
        hMap,
        FILE_MAP_WRITE,
        0,
        0,
        0
        );
    if (!MemPtr) {
        return FALSE;
    }

    ApiCounter       = (LPDWORD)   MemPtr + 0;
    ApiTraceEnabled  = (LPDWORD)   MemPtr + 1;
    ApiTimingEnabled = (LPDWORD)   MemPtr + 2;
    FastCounterAvail = (LPDWORD)   MemPtr + 3;
    ApiOffset        = (LPDWORD)   MemPtr + 4;
    ApiStrings       = (LPDWORD)   MemPtr + 5;
    ApiCount         = (LPDWORD)   MemPtr + 6;
    DllList          = (PDLL_INFO) MemPtr + 7;

    *ApiOffset       = (MAX_DLLS * sizeof(DLL_INFO)) + ((ULONG)DllList - (ULONG)MemPtr);
    *ApiStrings      = (MAX_APIS * sizeof(API_INFO)) + *ApiOffset;

    //
    // create the shared memory region for the api trace buffer
    //
    hMap = CreateFileMapping(
        (HANDLE)0xffffffff,
        NULL,
        PAGE_READWRITE | SEC_COMMIT,
        0,
        MAX_MEM_ALLOC,
        "ApiTrace"
        );
    if (!hMap) {
        return FALSE;
    }

    TraceBuffer = (PUCHAR)MapViewOfFile(
        hMap,
        FILE_MAP_WRITE,
        0,
        0,
        0
        );
    if (!TraceBuffer) {
        return FALSE;
    }

    TraceBufferHead = TraceBuffer;
    TraceCount = (PULONG) TraceBuffer;
    *TraceCount = MAX_MEM_ALLOC - (sizeof(ULONG)*2);
    TraceCount += 1;
    TraceBuffer = (PVOID) ((PUCHAR) TraceBuffer + (sizeof(ULONG)*2));

    ApiTraceMutex = CreateMutex( NULL, FALSE, "ApiTraceMutex" );
    if (!ApiTraceMutex) {
        return FALSE;
    }

    if (GetLastError() == ERROR_ALREADY_EXISTS) {
        return FALSE;
    }

    InitCommonControls();

    QueryPerformanceFrequency( (LARGE_INTEGER*)&PerfFreq );

    hModulePsApi = LoadLibrary( "psapi.dll" );
    if (hModulePsApi) {
        pInitializeProcessForWsWatch = (INITIALIZEPROCESSFORWSWATCH) GetProcAddress(
            hModulePsApi,
            "InitializeProcessForWsWatch"
            );
        pRecordProcessInfo = (RECORDPROCESSINFO) GetProcAddress(
            hModulePsApi,
            "RecordProcessInfo"
            );
        pGetWsChanges = (GETWSCHANGES) GetProcAddress(
            hModulePsApi,
            "GetWsChanges"
            );
    } else {
        PopUpMsg( "Page fault profiling is not available.\nPSAPI.DLL is missing." );
    }

    WinApp(
        hInstance,
        nShowCmd,
        ProgName,
        Arguments,
        GoImmediate
        );

    if (ProgName[0]) {
        SaveOptions();
    }

    return 0;
}