Board index » delphi » How to Call a Visual C++ 4.0 DLL from Delphi 2.0

How to Call a Visual C++ 4.0 DLL from Delphi 2.0

Hello You,

please help if You can! I have to program a DLL with VisualC++ 4.0 and I
want use this DLL in a Delphi 2.0 program.
The DLL functions without paramter works allright. But the DLL functions
with paramter (GetTestXXX) doesnt works.
Whats wrong???

Thanks for Your help!!!

Alex <aneu...@pppns1.phy.tu-dresden.de>

DELPHI SOURCE FOR DLLTEST.EXE:
----------------------------------------------------------------------
// This is the DLLTEST.EXE source in Delphi 2.0. The program calls
   GetTestStr() and GetTestInt() from the VisualC DLL.
program dlltest;
uses WinTypes,  WinProcs, testunit;
begin
  GetTestStr('test');
  GetTestInt(111);
  messagebox(0,'Fertig','DLL-Test',mb_ok);
end.
----------------------------------------------------------------------
UNIT TestUnit;
INTERFACE
  function GetTestStr(lpMenuName : PChar):BOOLEAN;
  function GetTestInt(i:integer):BOOLEAN;
IMPLEMENTATION
  function GetTestStr(lpMenuName : PChar):BOOLEAN; external 'c_dll.dll'
name 'GetTestStr';
  function GetTestInt(i:integer):BOOLEAN; external 'c_dll.dll' name
'GetTestInt';
END.
----------------------------------------------------------------------

VISUAL C SOURCE FOR C_DLL.DLL:
----------------------------------------------------------------------
// This is the DLL source in VisualC++ 4.0, but it does not work!
// The windows messagebox shows not the right paramter.
// (What is a Wrapper of API?)

#include "StdAfx.h"

#define INTERFACE __declspec(dllexport)
//#define WINAPI  __stdcall

INTERFACE BOOL WINAPI GetTestStr(LPSTR p)
{
      MessageBox(0,p,"dll",MB_OK);    // p should be "test"
      return TRUE;

Quote
}

INTERFACE BOOL WINAPI GetTestInt(int i)
{
    char  sz[40];  

    wsprintf (sz, "int %i ", i);       // i should be 111
    MessageBox (0, sz, "DLL", MB_OK);
    return TRUE;

Quote
}

----------------------------------------------------------------------
; DEF file for the Visual C DLL
EXPORTS
        GetTestStr                                      @1
        GetTestInt                                      @2
 

Re:How to Call a Visual C++ 4.0 DLL from Delphi 2.0


Quote
Alex wrote:

> Hello You,

Hey you, out there in the cold, feeling lonely, feeling old...

Quote
> please help if You can! I have to program a DLL with VisualC++ 4.0 and I
> want use this DLL in a Delphi 2.0 program.
> The DLL functions without paramter works allright. But the DLL functions
> with paramter (GetTestXXX) doesnt works.
> Whats wrong???

stdcall.
Boolean is not BOOL. BOOL is a signed 32 bits integer. Use integer
instead.

Oh, and one newsgroup should be sufficient....

M.

--
Martin Larsson, author of several unknown utilities for DOS and Windows.
mailto:martin.lars...@delfi-data.msmail.telemax.no
http://www.delfidata.no/users/~martin
X.400:G=martin;S=larsson;O=delfi-data;P=msmail;A=telemax;C=no

Re:How to Call a Visual C++ 4.0 DLL from Delphi 2.0


Quote
Alex wrote:
> Hello You,
> please help if You can! I have to program a DLL with VisualC++ 4.0 and I
> want use this DLL in a Delphi 2.0 program.
> The DLL functions without paramter works allright. But the DLL functions
> with paramter (GetTestXXX) doesnt works.
> Whats wrong???
> Thanks for Your help!!!
> Alex <aneu...@pppns1.phy.tu-dresden.de>

Recently Ihad the same problem, Meik Weber advised me:

: You must/should add the "stdcall" to the procedure declaration
: as delphi by default uses registers to pass parameters and this is
: usually completely different in C compilers (everyone handles this
: different).

: Meik Weber
: m.we...@public.ndh.com or
: 100744.3...@compuserve.com

Alexey

Re:How to Call a Visual C++ 4.0 DLL from Delphi 2.0


Quote
Alex <aneu...@pppns1.phy.tu-dresden.de> wrote:
>Hello You,
>please help if You can! I have to program a DLL with VisualC++ 4.0 and I
>want use this DLL in a Delphi 2.0 program.
>The DLL functions without paramter works allright. But the DLL functions
>with paramter (GetTestXXX) doesnt works.
>Whats wrong???

dont' forget to use the STDCALL directive in delphi, too.

procedure GetText (Whatever : Integer); stdcall external...........

Hope this helps
Meik Weber
m.we...@public.ndh.com or
100744.3...@compuserve.com

Other Threads