RE: Accessing C++ DLL function from Delphi

<[email protected]>
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <[email protected]>
Felipe -

Thanks for your comment.  Originally that is how I coded it, but I couldn't
get the program to run.  It returns a Debugger Kernel Error, Error Code 1
within the Delphi Environment, and a "Missing Export Module" error when I
tried to run the executable directly.  Since I couldn't even get the program
to run, I changed the explicit external declaration to a dynamic load in an
effort to obtain more information.

There seems to be a problem with accessing the function ... perhaps as a
result of name mangling in C++ ???.  I have tried various permutations on
the listed function name without success.  I have had no problem writing and
accessing Delphi DLLs from within Delphi, but C++ DLLs seem to require a
different approach.  I have searched the net for information on this and the
results have ranged from "...it's easy" to "...it's possible, but not
simple".  My experience has been more like the latter.  There clearly are
some things I am overlooking here (or simply don't know).

  -----Original Message-----
  From: Felipe Rezek Mohallem [mailto:[email protected]]
  Sent: Saturday, July 05, 2003 10:26 AM
  To: [email protected]
  Subject: RES: [Delphi] Accessing C++ DLL function from Delphi


  Why don't u try external calls?
  Just like this:

  function get_delay_time : integer; stdcall; external 'Module1.DLL';
  var
    Form1: TForm1;

  implementation

  {$R *.dfm}

  procedure TForm1.Button1Click(Sender: TObject);
  begin
  showMessage ( intToSTr ( get_delay_time ) );
  end;

  []s
  Felipe

  -----Mensagem original-----
  De: quadtech100 [mailto:[email protected]]
  Enviada em: sexta-feira, 4 de julho de 2003 20:04
  Para: [email protected]
  Assunto: [Delphi] Accessing C++ DLL function from Delphi



  Hello -

  I have been trying to access a function in a C++ DLL without
  success.  The function is given as:

  int get_delay_time();

  My current approach is as outlined below.  I get a "function not
  supported on this system" message at the LoadLibrary step, and "The
  specified module could not be found" message at the GetProcAddress
  step.

  I seem to have this all fouled up.  Any suggestions would be most
  welcome.  Thanks.

  -----------------------

  var
    Form1: TForm1;
    DelayTime:  function (_get_delay_time:integer):integer cdecl;

  implementation

  {$R *.DFM}

  procedure TForm1.FormCreate(Sender: TObject);
  var
  theHandle:THandle;
  begin
  theHandle:=LoadLibrary('Module1.DLL');
  ShowMessage('LoadLibrary: '+SysErrorMessage(GetLastError));
  if theHandle <> 0 then
    try
     @DelayTime:=GetProcAddress(theHandle,'get_delay_time');
     ShowMessage('GetProcAddress: '+SysErrorMessage(GetLastError))
    except
     ShowMessage('Error 0.  theHandle <> 0 ')
    end
  else
    ShowMessage('Error 1.  theHandle=0 ');
  end;





  Yahoo! Groups Sponsor

  ADVERTISEMENT

  <http://rd.yahoo.com/M=244522.3512152.4794593.1261774/D=egroupweb/S=1705
  115362:HM/A=1595053/R=0/SIG=1245der9k/*http://ashnin.com/clk/muryutaitak
  enattogyo?YH=3512152&yhad=1595053> Click Here!

  <http://us.adserver.yahoo.com/l?M=244522.3512152.4794593.1261774/D=egrou
  pmail/S=:HM/A=1595053/rand=655251612>

  Delphi Tips & Tutorials...
  http://www.delphicollection.com
  ---------------------------------------------------------------
  Unsubscribe:[email protected]
  List owner:[email protected]
  ---------------------------------------------------------------

  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
  <http://docs.yahoo.com/info/terms/> .




  [Non-text portions of this message have been removed]



        Yahoo! Groups Sponsor
              ADVERTISEMENT




  Delphi Tips & Tutorials...
  http://www.delphicollection.com
  ---------------------------------------------------------------
  Unsubscribe:[email protected]
  List owner:[email protected]
  ---------------------------------------------------------------

  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Save up to 80% on top-quality inkjet cartridges and get your order fast!
FREE shipping on orders $50 or more to the US & Canada. Shop at Myinks.com!
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/v2G7ND/KfUGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->

Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.