DLL的创建与加载

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;
}



你可能感兴趣的:(thread,null,dll)