Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LoadLibraryTest.cpp : Defines the entry point for the application.
- //
- #include "stdafx.h"
- #include <cstdio>
- #include <shellapi.h>
- #include "LoadLibraryTest.h"
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPWSTR lpCmdLine,
- _In_ int nCmdShow)
- {
- LPWSTR *szArglist;
- int nArgs;
- int i;
- szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
- if (NULL == szArglist)
- {
- return 0;
- }
- else
- {
- for (i = 0; i < nArgs; i++)
- {
- // skip executable name
- if (i == 0) continue;
- SetLastError(0);
- HMODULE hMod = LoadLibraryW(szArglist[i]);
- DWORD winError = GetLastError();
- wchar_t* error_msg = (wchar_t*)LocalAlloc(LMEM_ZEROINIT, MAX_PATH * sizeof(wchar_t));
- swprintf_s(error_msg, MAX_PATH, L"Library \"%s\" HMODULE 0x%08x %s GetLastError: 0x%08x", szArglist[i], hMod, hMod != 0 ? L"loaded" : L"not loaded", HRESULT_FROM_WIN32(winError));
- MessageBoxW(NULL, error_msg, L"Error", winError != 0 ? MB_ICONERROR : MB_ICONINFORMATION);
- LocalFree(error_msg);
- }
- }
- if (i == 1)
- MessageBoxW(NULL, L"Drag&Drop DLL file over this executable!", L"LoadLibraryTest", MB_ICONINFORMATION);
- LocalFree(szArglist);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement