You can use ld.exe or in the bin folder x86_64-win64-ld.exe
I have a dll called vbcode.dll (use 64 bits, slight difference with 32 bits)
(as in a recent post of mine)
ld.exe -r -b binary -o vbcode1.o vbcode.dll or
x86_64-win64-ld.exe -r -b binary -o vbcode1.o vbcode.dll
to get vbcode1.o
Then I use vbcode1.o to get the memory location of the dll.
I tried in pascal viz:
{$L vbcode1.o}
function memcpy(T:pointer;F:pointer;sz:integer):integer ; cdecl external 'msvcrt.dll' name 'memcpy';
var
vbcode_dll_start :byte external '_binary_vbcode_dll_start' ;
vbcode_dll_end :byte external '_binary_vbcode_dll_end';
ublength:int32;
s:ansistring;
procedure savefile(s:ansistring ;filename:ansistring);
var
fout:file;
begin
Assign(fout,filename);
Rewrite(fout,length(s));
blockwrite(fout,s[1],1);
close(fout);
end;
begin
ublength:=@vbcode_dll_end - @vbcode_dll_start;
writeln(ublength);
setlength(s,ublength);
memcpy(@s[1],@vbcode_dll_start,ublength);
savefile('libvbcodenew.a',s);
end.
comments
my dll = vbvcode.dll
ld.exe -r -b binary -o vbcode1.o vbcode.dll or
x86_64-win64-ld.exe -r -b binary -o vbcode1.o vbcode.dll
to get vbcode1.o
But I get errors in Pascal with the object file. (Error: Failed reading coff file, invalid section index while reading vbcode1.o)
This method works perfectly well in freebasic.
If you look at the object file with nm
nm vbcode1.o
0000000000047a00 D _binary_vbcode_dll_end
0000000000047a00 A _binary_vbcode_dll_size
0000000000000000 D _binary_vbcode_dll_start
If you get the object file loaded then fill the ansistring via memcpy (or the pascal equivalent).
Then save the string as a .a or .o file.
If you then use this .a or .o file, it will substitute the dll, in fact it will be a part of the resultant .exe file which will be portable on it's own.
You need to define the exports after loading the .a or .o file, and I don't know how to define exported functions from an object file or a static lib file in freepascal.
I can find no easy way from help files so far.
The only difference with 32 bits is the first underscore before
_binary_vbcode_dll_end
_binary_vbcode_dll_start
There is no underscore used in 32 bits.
i.e.
binary_vbcode_dll_end
binary_vbcode_dll_start
Sorry I couldn't get a working runner, but I always fail miserably when I try to use .o or .a library files in freepascal.
Maybe you can tweak the above code to get that ansistring filled and saved in a file and use the file in your main program.