Title: How to export a big const from a DLL
library hexerdll;
type
Tviergewinnt_exe = array[0..88598] of Byte;
const
viergewinnt_exe: TViergewinnt_exe =
($4D,$5A,$00,$01,$01,$00,$00,$00,$08,$00,$10,$00,$FF,$FF,$08,$00,$00,$01,$00,$00,
$00,$00,$00,$00,$40,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
.............,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00);
function getArrayofByte: Tviergewinnt_exe;
begin
Result := viergewinnt_exe;
end;
exports
getArrayofByte;
The call of the client has the following structure: the important thing is
to declare a local
var
of the
const in our case dllexe: Tviergewinnt_exe;
unit playmain;
// examples to call the embedded file in the unit or the dll
// some code ........
type
Tviergewinnt_exe = array[0..88598] of Byte;
function getArrayofByte: Tviergewinnt_exe; external 'hexerdll';
procedure TForm1.btnApploadClick(Sender: TObject);
var
bitStream: TMemoryStream;
dllexe: Tviergewinnt_exe;
begin
bitStream := TMemoryStream.Create;
dllexe := getArrayofByte;
try
//without a dll you call const name
//bitStream.Writebuffer(viergewinnt_exe, sizeof(viergewinnt_exe));
// import DLL const
bitStream.Writebuffer(dllexe, SizeOf(dllexe));
bitStream.Position := 0;
bitstream.LoadFromStream(bitstream);
bitstream.SaveToFile('viergewinnt.exe');
case WinExec(PChar('viergewinnt.exe'), SW_SHOWDEFAULT) of
0: ShowMessage('The system is out of memory or resources.');
ERROR_BAD_FORMAT: ShowMessage('The .EXE file is invalid (non-Win32.EXE or error in .EXE image).');
ERROR_FILE_NOT_FOUND: ShowMessage('The specified file was not found.');
ERROR_PATH_NOT_FOUND: ShowMessage('The specified path was not found.');
end;
finally
bitStream.Free;
end;
end;