Hello everybody,

This simple MSVC application is loading a MinGW dll and calling a
function which raises an exception.
The 32-bit version of application is catching the exception as expected,
but 64-bit version of application is crashing. 

So far my research of the problem goes with no success. I could only
prevent it from crash by removing SEH functions, adding
-fomit-frame-pointer to mingw command-line for dll, and use catch(...)
to catch the exception.

Can anyone advise which options to use, or maybe it's not implemented
yet?


---------------------------
32-bit version of the dll compiled using mingw32 with gcc 3.4.5. This
one I got by running the installer: MinGW-5.1.3.exe.
Compile options:
gcc -o mingw_32_library.dll -shared -pipe -mrtd mingw_xx_library.cpp
-mms-bitfields -Wl,--kill-at,-s

---------------------------
64-bit version of the dll compiled using latest mingw-w64 from sf.net,
that is mingw-w64-bin_x86_64-mingw_20080920.
Compile options:
gcc -o mingw_64_library.dll -shared -Wl,-s -pipe -m64
mingw_xx_library.cpp -mms-bitfields 

---------------------------
mingw_xx_library.cpp

#include <stdio.h>

extern "C" __declspec(dllexport) void __stdcall
simple_proc_which_throws()
{
        printf("simple_proc_which_throws \n");
        
        int* p_int = 0;
        *p_int = 1234;  
}

---------------------------
Simpletest.cpp  - 

// compiled using MSVC, console application. Create empty project of
console type, add simpletest.cpp, 
// and change Project Properties - C/C++ - Code Generation - Enable C++
Exceptions to /EHa
// leave all other setting with their default values

#include <stdio.h>
#include <windows.h> 
#include <eh.h>

void __cdecl SEH_translator_function( unsigned int u,
EXCEPTION_POINTERS* ep )
{
        printf("SEH Exception\n\n");
        throw 0;
}

int main()
{
        #ifdef _WIN64
                HMODULE hLibrary = LoadLibrary("mingw_64_library.dll");
        #else
                HMODULE hLibrary = LoadLibrary("mingw_32_library.dll");
        #endif
        if(hLibrary == NULL) return 1;

        typedef  void (__stdcall *simple_proc_t)();

        simple_proc_t simple_proc =
(simple_proc_t)GetProcAddress(hLibrary, "simple_proc_which_throws");
        if(simple_proc == NULL) return 1;

        _se_translator_function old_stf =
_set_se_translator(SEH_translator_function);

        try
        {
                simple_proc();  
        }
        catch(int i)
        {
                printf("---%d---\n", i);
        }
        catch(...)
        {
                printf("---...---\n");
        }

        _set_se_translator(old_stf);

        return 0;
}




Thanks,

Seyran



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to