DLL debuggen



  • Hallo,
    ich schreibe eine DLL und möchte gerne wisse, was dadrinnen so vor sich geht.
    Ich suche nun nach einer Möglichkeit, möglichst einfach Daten nach aussen zu geben.
    Auf die Konsole schreiben habe ich schon probiert:

    #define MAKE_DLL
    
    // INCLUDES //////////////////////////////////////////////////////////////
    #include <windows.h>
    #include <stdio.h>
    //#undef MessageBox;
    #include <fstream>
    
    #include "Hook.h"
    
    // DEFINES ///////////////////////////////////////////////////////////////
    
    // CONSTANTS /////////////////////////////////////////////////////////////
    
    // GLOBALS ///////////////////////////////////////////////////////////////
    
    #pragma data_seg ("shared")
    
    // iNumInstances = 0;
    HHOOK hMouseHook =0;
    int iKeystrokes[255] = {0};
    #pragma data_seg ()
    #pragma comment(linker,"/SECTION:shared,RWS")
    
    // PROTOTYPES ////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM);
    void OutputKeystrokes();
    
    // VARIABLES /////////////////////////////////////////////////////////////
    
    HINSTANCE	hDllInstance;
    
    // METHODS ///////////////////////////////////////////////////////////////
    
    // FUNCTIONS /////////////////////////////////////////////////////////////
    
    int APIENTRY DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
    {
    	hDllInstance = hInstance;
    
    	return TRUE;
    }
    
    BOOL CALLBACK InstallHooks(void)
    {
    	//MessageBox::Show("Test", "Überschrift", MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
    	HANDLE hConsoleOutput;
    	CHAR_INFO lpPuffer[2*2];
    	COORD dwPufferSize;
    	COORD dwPufferCoord;
    	SMALL_RECT lpWriteRegion;
    
    	//Init
    	hConsoleOutput= "GENERIC_WRITE";
    	lpPuffer[0].Char.AsciiChar='x';
    	lpPuffer[0].Attributes=BACKGROUND_BLUE | FOREGROUND_GREEN;
    	lpPuffer[1]=lpPuffer[0];
    	lpPuffer[2]=lpPuffer[0];
    	lpPuffer[3]=lpPuffer[0];
    	dwPufferSize.X=2;
    	dwPufferSize.Y=2;
    
    	dwPufferCoord.X=0;
    	dwPufferCoord.Y=0;
    
    	lpWriteRegion.Left=0;
    	lpWriteRegion.Top=0;
    	lpWriteRegion.Bottom=2;
    	lpWriteRegion.Right=2;
    	WriteConsoleOutput(hConsoleOutput, lpPuffer, dwPufferSize, dwPufferCoord, &lpWriteRegion);
    
    	if (hMouseHook  ==0) hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseHookProc, hDllInstance, NULL);
    
        if (hMouseHook == NULL)
        {
            return FALSE;
        }
    
        return TRUE;
    }
    
    BOOL CALLBACK UnInstallHooks(void)
    {
        OutputKeystrokes();
    
        return UnhookWindowsHookEx(hMouseHook);
    }
    
    LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam,LPARAM lParam)
    {
    	//std::ofstream out("c:\\mousehook.txt"); //create file to write
    	if(nCode < 0) return CallNextHookEx(hMouseHook, nCode, wParam, lParam); //validate if this hook is allowed to work
    	//else:start filtering...
    
        /*MOUSEHOOKSTRUCT * pMouseStruct = (MOUSEHOOKSTRUCT *)lParam;
    	int x = pMouseStruct->pt.x;
        int y = pMouseStruct->pt.y;
    
    	out << x << "\n";
    	out << y << "\n";*/
    
    	return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
    }
    
    void OutputKeystrokes()
    {
        /*
    
        for (int i='A'; i<='Z'; i++)
        {
            out << (char)i << " = " << iKeystrokes[i] << "\n";
        }*/
    }
    

    Leider kann ich in meinem Command Window nichts sehen!
    Ist das die Konsole, oder verbirgt sich die woanders?
    Gibt es vielleicht auch eine einfachere Möglichkeit?
    Vielleicht mit einer MessageBox?
    Hab ich, wie man sehen kann, auch schon probiert, leider auch ohne Erfolg.

    Würde mich über Hilfe sehr freuen!



  • Debuggen !?
    OutputDebugString und DebugView!?
    http://www.sysinternals.com/Utilities/DebugView.html



  • Danke, kannte ich nicht.
    Wie benutzt man das?
    Gibt es eine Anleitung?
    Was muss ich in den Quelltext schreiben?
    Ich kann auf der HP nichts finden...


Anmelden zum Antworten