Advertisement
CasualGamer

Basic DLL

Nov 14th, 2019
2,983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. // dllmain.cpp : Defines the entry point for the DLL application.
  2. #include <Windows.h>
  3. #include<iostream>
  4.  
  5. HMODULE myhModule;
  6.  
  7. DWORD __stdcall EjectThread(LPVOID lpParameter) {
  8.     Sleep(100);
  9.     FreeLibraryAndExitThread(myhModule, 0);
  10. }
  11.  
  12. DWORD WINAPI Menue() {
  13.     AllocConsole();
  14.     FILE* fp;
  15.     freopen_s(&fp, "CONOUT$", "w", stdout); // output only
  16.     std::cout << "test" << std::endl;
  17.     while (1) {
  18.         Sleep(100);
  19.         if (GetAsyncKeyState(VK_NUMPAD0))
  20.             break;
  21.     }
  22.     fclose(fp);
  23.     FreeConsole();
  24.     CreateThread(0, 0, EjectThread, 0, 0, 0);
  25.     int i = 0;
  26.     return 0;
  27. }
  28.  
  29.  
  30. BOOL APIENTRY DllMain( HMODULE hModule,
  31.                        DWORD  ul_reason_for_call,
  32.                        LPVOID lpReserved
  33.                      )
  34. {
  35.     switch (ul_reason_for_call)
  36.     {
  37.     case DLL_PROCESS_ATTACH:
  38.         myhModule = hModule;
  39.         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Menue, NULL, 0, NULL);
  40.     case DLL_THREAD_ATTACH:
  41.     case DLL_THREAD_DETACH:
  42.     case DLL_PROCESS_DETACH:
  43.         break;
  44.     }
  45.     return TRUE;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement