Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // LoadLibraryTest.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <cstdio>
  6. #include <shellapi.h>
  7. #include "LoadLibraryTest.h"
  8.  
  9. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  10.     _In_opt_ HINSTANCE hPrevInstance,
  11.     _In_ LPWSTR    lpCmdLine,
  12.     _In_ int       nCmdShow)
  13. {
  14.     LPWSTR *szArglist;
  15.     int nArgs;
  16.     int i;
  17.  
  18.     szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
  19.     if (NULL == szArglist)
  20.     {
  21.         return 0;
  22.     }
  23.     else
  24.     {
  25.         for (i = 0; i < nArgs; i++)
  26.         {
  27.             // skip executable name
  28.             if (i == 0) continue;
  29.  
  30.             SetLastError(0);
  31.  
  32.             HMODULE hMod = LoadLibraryW(szArglist[i]);
  33.             DWORD winError = GetLastError();
  34.  
  35.             wchar_t* error_msg = (wchar_t*)LocalAlloc(LMEM_ZEROINIT, MAX_PATH * sizeof(wchar_t));
  36.             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));
  37.             MessageBoxW(NULL, error_msg, L"Error", winError != 0 ? MB_ICONERROR : MB_ICONINFORMATION);
  38.             LocalFree(error_msg);
  39.         }
  40.  
  41.     }
  42.  
  43.     if (i == 1)
  44.         MessageBoxW(NULL, L"Drag&Drop DLL file over this executable!", L"LoadLibraryTest", MB_ICONINFORMATION);
  45.  
  46.     LocalFree(szArglist);
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement