On Monday, 14 May 2012 at 09:53:55 UTC, Kagamin wrote:
Try to make C dll, which loads D dll, and inject the C dll :)

I made a bootstrapper (a c DLL which loads the D Dll) and it works fine (the D entrypoint get called (a made a msgbox test) but then the Process freezes after it displayed the MsgBox.

C Dll:

#include <windows.h>

bool _stdcall DllMain(_In_ void * _HDllHandle, _In_ unsigned _Reason, _In_opt_ void * _Reserved)
{
    if(_Reason == DLL_PROCESS_ATTACH)
    {
        MessageBox(NULL,L"test",L"test",MB_OK);
        LPTHREAD_START_ROUTINE LoadLibAddy =
(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(L"kernel32.dll"),
            "LoadLibraryA");
CreateThread(NULL,0,LoadLibAddy,"C:\\Users\\Moritz\\Documents\\Visual Studio 11\\Projects\\D_Projects\\D_BootStrapper\\Debug\\DAstral.dll",0,NULL);
    }

    return true;
}

D Dll:
import std.c.windows.windows;
import core.sys.windows.dll;

__gshared HINSTANCE g_hInst;

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID
pvReserved)
{
    final switch (ulReason)
    {
        case DLL_PROCESS_ATTACH:
            g_hInst = hInstance;
            MessageBoxA(null,"test2","test2",MB_OK);
            dll_process_attach( hInstance, true );
            break;

        case DLL_PROCESS_DETACH:
            dll_process_detach( hInstance, true );
            break;

        case DLL_THREAD_ATTACH:
        MessageBoxA(null,"test","test",MB_OK);
            dll_thread_attach( true, true );
            break;

        case DLL_THREAD_DETACH:
            dll_thread_detach( true, true );
            break;
    }
    return true;
}

Any help ?

Reply via email to