Easyhook and unhandled exceptions

Oct 16, 2014 at 4:33 PM
Hello, maybe someone can explain the next behavior.
Consider next case.
There is two projects. First is a DLL with one file main.cpp with the next content:
#include <Windows.h>
#include <iostream>

extern "C" __declspec(dllexport) void __stdcall OriginalFunction() {
    std::cout << "OriginalFunction" << std::endl;
    RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, 0);
    //throw std::exception("Bad stuff in OriginalFunction");

extern "C" __declspec(dllexport) void __stdcall ParentFunction() {
    std::cout << "ParentFunction" << std::endl;

    __try {
        std::cout << "Error: " << std::endl;
Another project hooks OriginalFunction and calls ParentFunction. It consists also of one file
#include <iostream>
#include <tchar.h>
#include <Windows.h>
#include <release-2.7/Public/easyhook.h>

typedef void (__stdcall* OriginalFunctionFunc)();
typedef void (__stdcall* ParentFunctionFunc)();

OriginalFunctionFunc OriginalFunction;
ParentFunctionFunc ParentFunction;

void __stdcall OriginalFunctionHook() {
    std::cout << "No hello world available" << std::endl;
    /*try {
    } catch (std::exception& e) {
        std::cout << "Error in hook: " << e.what() << std::endl;

int main() {
    HMODULE hModule = LoadLibrary(_T("original.dll"));
    ParentFunction = (ParentFunctionFunc)GetProcAddress(hModule, "ParentFunction");
    OriginalFunction = (OriginalFunctionFunc)GetProcAddress(hModule, "OriginalFunction");
    std::cout << "Call ParentFunction with unhooked OriginalFunction" << std::endl;
    HOOK_TRACE_INFO handle;
    memset(&handle, 0, sizeof(handle));
    NTSTATUS status = LhInstallHook(OriginalFunction, OriginalFunctionHook, (void*)0, &handle);

    if (NT_ERROR(status)) {
        std::cout << "Can't install hook" << std::endl;

    ULONG p[] = {0};
    LhSetExclusiveACL(p, 0, &handle);
    std::cout << "Call ParentFunction with hooked OriginalFunction" << std::endl;
    return 0;
When hook is installed exception in OriginalFunction causes a crash and is not intercepted in the ParentFunction. For me it is a problem, because I have to hook a function that does right the same and the target application crashes. I don't want to consume unhandled exception from OriginalFunction in the hook cause in general this can alter the behavior of the target process.
Any suggestions how to solve this problem?