Here is my code:

// File dllmain.d
module dllmain;

import core.runtime;
import std.c.stdlib;
import std.string;
import std.c.windows.windows;

import honmod;


private HINSTANCE g_hInst;


extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
{
        g_hInst = hInstance;
        
        switch (ulReason) {
                case DLL_PROCESS_ATTACH:
                        Runtime.initialize();
                        break;
                        
                case DLL_PROCESS_DETACH:
                        Runtime.terminate();
                        break;
                        
                default:
        }
        
        return true;
}


static this()
{
        honmod.initialize(g_hInst);
        MessageBoxA(null, "Dll Injection successful", "", MB_OK);
}


static ~this()
{
        MessageBoxA(null, "Dll ejected", "", MB_OK);
}




// File honmod
module honmod;

import std.concurrency;
import std.c.windows.windows;
import core.thread;


private HINSTANCE _hModule;



// The quit thread waits until F7 gets pressed and then frees the module
private void quitThread()
{
        while (true) {
                // KeyDown
                if (GetAsyncKeyState(VK_F7) & 0x0001) {
                        break;
                }
                
                Sleep(1);
        }
        
        FreeLibraryAndExitThread(_hModule, 0);
}


void initialize(HINSTANCE hModule)
{
        _hModule = hModule;
        
        // Spawn the quit thread
        new Thread(&quitThread).start();
}

Reply via email to