Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. // g++ -O0 -shared -o unwind.dll unwind.cxx
  2. // OR
  3. // cl.exe /nologo /Od /MD /EHa /LD /Fe:unwind.dll unwind.cxx
  4. #include <iostream>
  5. #include <exception>
  6. #include <windows.h>
  7.  
  8. class Foo
  9. {
  10. public:
  11. ~Foo()
  12. {
  13. std::cerr << "Exiting C++" << std::endl;
  14. }
  15. };
  16.  
  17. typedef void(*func)(void*);
  18.  
  19. void throws_fn()
  20. {
  21. std::cerr << "C++ throws exception" << std::endl;
  22. throw std::exception();
  23. }
  24.  
  25. extern "C" __declspec(dllexport) void catches_fn(func fn)
  26. {
  27. Foo foo;
  28. try
  29. {
  30. fn(throws_fn);
  31. }
  32. catch(std::exception& e)
  33. {
  34. std::cerr << "C++ catches exception" << std::endl;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement