🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13572

Using Delphi Dll in BCB application

#13572
From: Seabass
Date: Sat, 04 Oct 2003 19:32
132 lines
4791 bytes
Hey all,
I have recently change my application (written with BCB) to be able to use
DLL as plug-ins. This works fine with DLLs written in BCB and VC++. My new
goal is to be able to support DLLs written in Delphi as well, but I have
come accross a problem. Basically what the DLL is supposed to do is manage
users on the server that I have written. Each user has a struct, which
contains infos on the user like name, password, ip etc.. It also contains
functions like Disconnect, SendChat, etc...
This is how it looks in the program:
struct TUser {
typedef  void (__stdcall TUser::*TSendMess)(const char*,const char*);
typedef void (__stdcall TUser::*TCommon)(void);
typedef void (__stdcall TUser::*TCommon2)(const char*);
typedef bool (__stdcall TUser::*TCommon3)(const char*);
public:
 char fip[16];
 char ssmartip[16];
char sname[30];
TUserType * UserType;
TSendMess pChat;
TSendMess pPM;
TCommon2 pData;
TCommon3 pPass;
TCommon pkick;
TCommon pdisconnect;
 //don't share with dlls
void __stdcall SendChat(const char * sFrom,const char * sMessage);
void __stdcall SendData(const char * sMessage);
void __stdcall SendPM(const char * sFrom,const char * sMessage);
bool __stdcall ChangePass(const char * sPass);
void __stdcall Kick();
void __stdcall Disconnect();
 TSBSocket *Socket;
};

Once I initialize the object, the function pointers all get a pointer to the
function.

And this is how it looks like in a C++ dll:

struct TUser {
typedef void (__stdcall TUser::*TSendMess)(const char*,const char*);
typedef void (__stdcall TUser::*TCommon)(void);
typedef void (__stdcall TUser::*TCommon2)(const char*);
typedef bool (__stdcall TUser::*TCommon3)(const char*);
public:
 char fip[16];
 char ssmartip[16];
char sname[30];
TSendMess pChat;
TSendMess pPM;
TCommon2 pData;
TCommon3 pPass;
TCommon pkick;
TCommon pdisconnect;
  void SendChat(const char* sFrom, const char* sMessage)
   {

      (this->*pChat)(sFrom,sMessage);
   }

  void SendPM(const char* sFrom, const char* sMessage)
   {

      (this->*pPM)(sFrom,sMessage);
   }
  void SendData(const char*sData) //does NOT automatically send a |
  {
   (this->*pData)(sData);
  }
 bool ChangePass(const char*sPass)
 {
  return ((this->*pPass)(sPass));
 }
 void Kick()
 {
  (this->*pkick)();
 }
 void Disonnect()
 {
  (this->*pdisconnect)();
}
};

Now, this works without a problem, but doing this in Delphi did not, here is
the code for delphi:

Type
  TSendMess = procedure (sb1:pchar;sb2:pchar);stdcall;
  TCommon = procedure();stdcall;
  TCommon2 = procedure (sb1:pchar) ;stdcall;
  TCommon3 = function (sb1:pchar):boolean ;stdcall;
type TUser = record
tag: integer;
fip: array[0..15] of char;
ssmartip: array[0..15] of char;
lock: array[0..99] of char;
key: array[0..99] of char;
smypass: array[0..29] of char;
bAXDC:boolean;
tag2: integer;
smyinfostring: array[0..249] of char;
bOperator: boolean;
breguser: boolean;
sname: array[0..29] of char;
UserType: ^TUserType;
pChat : TSendMess;
pPM : TSendMess;
pData: TCommon2;
pPass: TCommon3;
pSilc:TCommon ;
pUnSilc: TCommon ;
pbip: TCommon ;
pbname:TCommon ;
pkick:TCommon ;
pdisconnect:TCommon ;
end;

When I try to call pChat, the break point I set at the C++ end gets called,
but when looking at the parameters, I noticed that the first parameter
contained the data of the second parameter and the data in the second
parameter was just some random junk. Calling any other function just caused
an Access Violation. I tried changing the functions from stdcall to pascal,
which caused the first parameter to display correctly but the second one
still contained junk. I also tried switching the record to a packed record,
without success. It just caused an Access Violation.

Any suggestions

thank you for taking the time to look at my code =)

Seabass
Technical Details
Message-ID: <3f7f2049@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-05!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,c7642e4ad15381e3,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-10-04 12:39:48 PST
From: "Seabass" <sbsoftea@ww-ei.nl>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Using Delphi Dll in BCB application
Date: Sat, 4 Oct 2003 21:32:53 +0200
Lines: 134
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 80.145.189.3
Message-ID: <3f7f2049@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1065295945 80.145.189.3 (4 Oct 2003 12:32:25 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-05!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail