whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

49 Visitors Online


 
... export a big const from a DLL?
Autor: Max Kleiner
Homepage: http://max.kleiner.com
[ Print tip ]  

Tip Rating (4):  
     


{
First you declare the type of the const and second you define a wrap function around the type:
}

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;


// http://www.softwareschule.ch/download/hexer2.zip


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners