fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Dll provided header.
  5. class Interface
  6. {
  7. public:
  8. virtual void test() = 0;
  9. };
  10.  
  11. Interface* GetProvidedByDLL()
  12. {
  13. // aligned with Interface layout.
  14. struct Local
  15. {
  16. virtual void foo()
  17. {
  18. cout<<data<<endl;
  19. }
  20. int data = 9487;
  21. };
  22. void* temp = (void*)new Local;
  23. // return (void*)new Local; // will fail compiling.
  24. return static_cast<Interface*>(temp);
  25. }
  26. int main() {
  27. // Assume GetProvidedByDLL is extracted by GetProcessAddress
  28. GetProvidedByDLL()->test();
  29. return 0;
  30. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
9487