1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
   | #include "main.h"
 
extern "C"
 
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
 
            MessageBox(0, "Loaded", "Dll message", MB_OK);
            MyProc();
            return TRUE;
            break;
 
        case DLL_PROCESS_DETACH:
            // detach from process
            break;
 
        case DLL_THREAD_ATTACH:
            // attach to thread
            break;
 
        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}
 
void DLL_EXPORT MyProc()
{
 
    MessageBox(0, "In MyProc", "Dll message", MB_OK);
    // Si je mets le code suivant en commantaire, la DLL est correctement executée
    HWND hHostWnd;
    hHostWnd = GetTopWindow(0 );  // On récupère la 1ere fenettre
            DWORD pid;                    // Variable pour les tests
            while ( hHostWnd )
            {
                GetWindowThreadProcessId( hHostWnd,&pid);     // On obtient le pid de la fenettre
                if ( pid == GetCurrentProcessId() )           // Si celui ci est celui de notre processus
                    {
                        MessageBox(0, "Found host HWND !", "Info", 0);
                        SetForegroundWindow(hHostWnd);
                }
                hHostWnd = GetNextWindow( hHostWnd , GW_HWNDNEXT);  // Sinon on prend la fenettre suivante
            }
} | 
Partager