You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<iostream>extern"C"
{
__declspec(dllexport) __cdecl void Greet()
{
std::cout << "Hello World!" << std::endl;
}
__declspec(dllexport) __cdecl int addNumbers(int a, int b)
{
std::cout << "Adding " << a << " and " << b << "..." << std::endl;
return a + b;
}
}
I compiled this using g++, downloadable from here.
This is my g++ version
g++ (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This is the command I used:
g++ SampleDll.cpp -o SampleDLL.dll --shared
I. Attempt to load from file.
I have a C source file (always compiled using g++ Test.c MemoryModule.c -o Test.exe -D_WIN64)
and copied the whole LoadFromFile function from the demo to my source file:
The access violation happened right after calling the dll entry point, and not because of a null pointer.
TL;DR
I have a C++ dll, 64-bit, compiled using G++ on MinGW-w64, which is perfectly valid (P/Invoke-able, and LoadLibrary-able).
Loading it using MemoryModule gives an Access Violation error when trying to call the dll entry point.
Any other dll's (Compiled using MSVC (64-bit, or 32-bit), or using the lesser-known Orange C compiler (32-bit only)) works normally on MemoryModule.
I do not have any experience with such low level programming, please help me explain why MemoryModule crashed when calling this entry point. Thanks in advance.
The text was updated successfully, but these errors were encountered:
It magically loaded when using --static-libgcc and --static-libstdc++, but the question remains:
Why doesn't your code throw a module not found exception, but crash mysteriously?
I have a 64-bit DLL, with this source code:
I compiled this using g++, downloadable from here.
This is my g++ version
g++ (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.1.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.This is the command I used:
I. Attempt to load from file.
I have a C source file (always compiled using
g++ Test.c MemoryModule.c -o Test.exe -D_WIN64
)and copied the whole
LoadFromFile
function from the demo to my source file:The source
It loads properly:
II. Attempt to load from Memory
I also copied the
LoadFromMemory
and theReadLibrary
function:The source
This time, the test program failed, with an access violation.
III. Attempt to use C#'s P/Invoke:
It just works, using a basic
DllImport
attribute.IV. Attempt to use a translated MemoryModule version, from a managed executable:
Fails, for the same reason.
V. Some more stuff.
After using a C# debugger on the translated version, and various
printf
debugging on the original library, I found this line of code's the culprit:The access violation happened right after calling the dll entry point, and not because of a null pointer.
TL;DR
P/Invoke
-able, andLoadLibrary
-able).I do not have any experience with such low level programming, please help me explain why MemoryModule crashed when calling this entry point. Thanks in advance.
The text was updated successfully, but these errors were encountered: