File: main.cpp

package info (click to toggle)
cpptrace 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,996 kB
  • sloc: cpp: 15,646; python: 962; ansic: 155; sh: 103; makefile: 86
file content (36 lines) | stat: -rw-r--r-- 777 bytes parent folder | download
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);
}