DLL 생성 및 로드

1409 단어 threadnulldll
testDLL:
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        MessageBoxW(NULL,TEXT("DLL         !"),TEXT("  "),0);
        break;

    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        MessageBoxW(NULL,TEXT("DLL          !"),TEXT("  "),0);
        break;
    }


    return TRUE;
}

testEXE:
#include <windows.h>

int main(int argc, _TCHAR* argv[])
{
    WCHAR wszLibFileName[400];
    GetModuleFileNameW(NULL,wszLibFileName,400);
    
    PWSTR begin = wcsrchr(wszLibFileName,L'\\');
    
    int len = lstrlenW(wszLibFileName);

    wszLibFileName[lstrlenW(wszLibFileName)-lstrlenW(wcsrchr(wszLibFileName,L'\\'))+1] = '\0';

    lstrcatW(wszLibFileName,L"testDll.dll");

    HINSTANCE hInstLib = LoadLibraryW(wszLibFileName);
    if (!hInstLib)
    {
        return -1;
    }

    FreeLibrary(hInstLib);

    return 0;
}

좋은 웹페이지 즐겨찾기