Advertisement
obernardovieira

Get Struct in DLL Run-Time

Mar 9th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. //getlibrary.dll
  2.  
  3. struct casa {
  4.     int portas;
  5.     int janelas;
  6. };
  7.  
  8. extern "C" {
  9.     __declspec(dllexport) casa ObterCasa() {
  10.         casa Casa;
  11.         Casa.janelas = 5;
  12.         Casa.portas = 2;
  13.         return Casa;
  14.     }
  15. }
  16.  
  17.  
  18. //myexe.exe
  19.  
  20. #include <iostream>
  21. #include <windows.h>
  22.  
  23. struct casa {
  24.     int portas;
  25.     int janelas;
  26. };
  27.  
  28. int main () {
  29.  
  30.     HMODULE hMod = LoadLibrary(TEXT("getlibrary.dll"));
  31.  
  32.     typedef casa (*minhacasa)();
  33.     minhacasa MinhaCasa = (minhacasa)GetProcAddress(hMod,"ObterCasa");
  34.     casa Casa = (MinhaCasa)();
  35.     std::cout << "Janelas " << Casa.janelas << std::endl;
  36.    
  37.  
  38.     std::cin.get();
  39.     return 1;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement