Advertisement
obernardovieira

Export and Import Functions (Linking DLL)

Aug 18th, 2013
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. //sampleDLL.h
  2.  
  3. #ifndef sampleDLL_H_
  4. #define sampleDLL_H_
  5. #include <iostream>
  6.  
  7. #if defined DLL_EXPORT
  8. #define DECLDIR __declspec(dllexport)
  9. #else
  10. #define DECLDIR __declspec(dllimport)
  11. #endif
  12.  
  13. extern "C"
  14. {
  15.    DECLDIR int Add( int a, int b );
  16.    DECLDIR void Function( void );
  17. }
  18.  
  19. #endif
  20.  
  21. //sampleDLL.cpp
  22.  
  23. #define DLL_EXPORT
  24.  
  25. #include <iostream>
  26. #include "sampleDLL.h"
  27.  
  28.  
  29.  
  30. extern "C"
  31. {
  32.    DECLDIR int Add( int a, int b ) {
  33.       return( a + b );
  34.    }
  35.  
  36.    DECLDIR void Function( void ) {
  37.       std::cout << "DLL Called!" << std::endl;
  38.    }
  39. }
  40.  
  41. //sampleDLL.def
  42.  
  43. LIBRARY "sampleDLL"
  44.  
  45. EXPORTS
  46.     Add @1
  47.     Function @2
  48.  
  49. //sampleAPP.cpp
  50.  
  51. #pragma comment(lib, "sampleDLL.lib")
  52.  
  53. #include <iostream>
  54. #include "sampleDLL.h"
  55.  
  56. int main() {
  57.    Function();
  58.    std::cout << Add(22, 38) << std::endl;
  59.    system("pause");
  60.    return 1;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement