Archived

This topic is now archived and is closed to further replies.

A J Oja

Importing C++ DLL into Delphi

Recommended Posts

A J Oja    122
Since there is a way to load DLLs into Delphi dynamically... could someone help me with this: How to load a C++ DLL into Delphi... I tried with several different options but only got errors... Delphi geeks, here is your time to prove Delphi is better than this! - A.J. - "Where is the KABOOM?! There was supposed to be an earth-shattering KABOOM!"

Share this post


Link to post
Share on other sites
Dak Lozar    122
I''m a long time C/C++ coder... but my last contract was working on a Oracle/Delphi solution

Here is some code that I used to load and run a function from a DLL dynamically.


procedure TFrmMain.LoadAndRunDLLProcedure(sDLL, sFunc : string );
type
// define the type of "function"
// we''re calling
TFunc_Start = procedure;
var
Func_Start : TFunc_Start;

hDll : THandle;
FuncPtr : TFarProc;
sMsg : string;
begin
// Result := False;
hDll := LoadLibrary( PChar( sDLL ) );
if(hDll > 32)then
begin
FuncPtr := GetProcAddress( hDll, PChar( sFunc ) );
@Func_Start := FuncPtr;
if(nil <> @Func_Start)then
begin
Func_Start;
//Result := True;
end else
begin
sMsg := ''DLL entry point '' + sFunc + '' not found'';
MessageBox( 0, PChar( sMsg ), ''Error'', MB_OK );
end;
FreeLibrary( hDll );
end else
begin
sMsg := ''File '' + sDLL + '' not found'';
MessageBox( 0, PChar( sMsg ), ''Error'', MB_OK );
end;

// MessageBox( 0, PChar( ''Bottom of LoadAndRunDLLProcedure'' ), ''Error'', MB_OK );

end;


You will most definately need to modify the code to work with functions that take params and this is just for functions not classes or functions within classes.




Dak Lozar
Elysian Productions, Inc.

Share this post


Link to post
Share on other sites