Closed xander-m2k closed 2 years ago
What is your version of g++?
Mine is:
g++ (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 11.2.1 20210918
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.
I don't remember how I built my dlls, but building with your commands, with a few modifications to the suffix:
g++ Secret.cpp -o Secret64.dll --shared -static-libgcc -static-libstdc++
g++ SampleDll.cpp -o SampleDLL64.dll --shared -static-libgcc -static-libstdc++ Secret64.dll
(Note that I'm using the 64 suffix, as the demo app contains this code:
var asmBytes = File.ReadAllBytes($"SampleDLL{(Environment.Is64BitProcess ? "64" : "")}.dll");
as well as
string secretAsmName = $"Secret{(Environment.Is64BitProcess ? "64" : "")}.dll";
and my device is running Windows 11 x64)
And then:
dotnet run --framework net48
works well.
Hi, I'm a dummy initializer
Successfully loaded library.
Adding 17 and 12...
17+12=29
Address: 0x1b114c95338
Current global int: 0
Address: 0x1b114c95338
Current global int: 1
Address: 0x1b114c95338
Current global int: 2
On second thread...
Address: 0x1b114c954b8
Current global int: 0
Address: 0x1b114c954b8
Current global int: 1
Address: 0x1b114c954b8
Current global int: 2
Hello World!
Here is my secret: 30
Thanks for the quick reply,
when I execute g++ -v
I get the following output:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
Also, note that loading 32-bit dlls in 64-bit processes is not supported (both by MemoryModule.NET and the original MemoryModule).
Your code probably tripped here:
Good remark, I will try installing mingw64
Great, that worked! I installed mingw64 from here (GCC 12.1.0), and it worked right away. Also with these commands:
g++ Secret.cpp -o Secret64.dll --shared -static-libgcc -static-libstdc++
g++ SampleDll.cpp -o SampleDLL64.dll --shared -static-libgcc -static-libstdc++ Secret64.dll
Thanks for the help @trungnt2910!
Hi @trungnt2910
Could you provide the recipe for creating the following files in the form of a script or Makefile?
I want to make my own library for the DemoApp example.
I am getting as far as this:
However, when I try these dll files with the DemoApp, I get the following error:
Saying that what I compiled is
%1 is not a valid Win32 application
.Therefore, please provide a recipe for compilation of these .dll's.