forked from jeremy-rifkin/cpptrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (27 loc) · 777 Bytes
/
main.cpp
File metadata and controls
36 lines (27 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "cpptrace/basic.hpp"
#include "cpptrace/utils.hpp"
#include "mydll.hpp"
#include <windows.h>
#include <iostream>
#include <cpptrace/from_current.hpp>
int main() {
// generate a trace before LoadLibraryA to initialize dbghelp
cpptrace::generate_trace().print();
HMODULE lib = LoadLibraryA("mydll.dll");
if (!lib) {
std::cerr << "Failed to load DLL\n";
return 1;
}
auto foo = reinterpret_cast<decltype(::foo)*>(GetProcAddress(lib, "foo"));
if (!foo) {
std::cerr << "Failed to get symbol\n";
return 1;
}
cpptrace::load_symbols_for_file("mydll.dll");
CPPTRACE_TRY {
foo();
} CPPTRACE_CATCH(...) {
cpptrace::from_current_exception().print();
}
FreeLibrary(lib);
}