Solved

RemoteServerCall

Posted on 1997-04-27
3
263 Views
Last Modified: 2010-04-04
 I don't get right results when using C++ made DLL in Delphi1 project.
Below you can see the vital parts of the program I am using. I can
successfully load the 16 bit DLL and use it. The first DLL call

         wsResult := RscCreateOptions(pulOptionsHandle);

should have a parameter 'a pointer to the variable that receives the
handle of the options structure'. After call I show the handle value
and it is  f. ex. 0045870000. Doesn't seem to be any handle value.

The second Dll call

         wsResult := RscGetOption(ulOptionsHandle,
                            pcHostInetAddress,
                            pvHostInetAddress);

confirms it saying that Options Structure is corrupted!
Why doesn't this work? Is the a different pointer structure in C++
compared to Delphi? How I must declare the pointer I pass to the C++
DLL?. If someone can help me I would be veru grateful!
These are the definations and preparations in order to use the C++
DLL.

type TRscCreateOptions = function(pulOptionsHandle: PLongint): Integer cdecl;
type TRscGetOption = function(ulOptionsHandle: LongInt;
                            pcOptionSelector: PChar;
                            pvValue: PChar): Integer cdecl;


      var RscCreateOptions: TRscCreateOptions;
      var RscGetOption: TRscGetOption;


      Var hRsc4d: THandle;

      Procedure LoadRsc4dDLL;           {Load dll & function pointers}
        Var FP: TFarProc;
        Begin
          If hRsc4d >= 32 Then FreeLibrary (hRsc4d);
          hRsc4d := LoadLibrary ('Rscw.DLL');
          If hRsc4d < 32 Then Exit;
          FP := GetProcAddress (hRsc4d, 'RSCOC');
          RscCreateOptions := TRscCreateOptions (FP);
          if (FP = NIL) then
          begin
            ShowMessage('RSCW.dll, function RscCreateOptions not found');
            Application.Terminate;
          end;
           FP := GetProcAddress (hRsc4d, 'RSCOG');
          RscGetOption := TRscGetOption (FP);
          if (FP = NIL) then
          begin
            ShowMessage('RSCW.dll, function RscGetOption not found');
           Application.Terminate;
         end;

        End;


This is the Delphi unit where C++ DLL is called.

      var
        ulOptionsHandle:      Longint;
        pulOptionsHandle:       PLongInt;
        const pcHostInetAddress: Pchar = 'HOST_INET_ADDRESS';
        pcOptionValue:    PChar;

      .
      .
      .  
      implementation

      {$R *.DFM}

      procedure TForm1.BitBtn1Click(Sender: TObject);
      begin
.
         pulOptionsHandle := Addr(ulOptionsHandle);
         wsResult := RscCreateOptions(pulOptionsHandle);
         if wsResult = 0 then
         begin
           ShowMessage('RscCreateOptions OK ');
           wsLuku := IntToHex(wsArvo, 10);
           ShowMessage('Options,handle='+ wsLuku);
         end
         else begin
           ShowMessage(StrPas(RSC4D_Error(wsResult)));
           Application.Terminate;
         end;

   {If successfully Options structure created,test  if it is OK}

         wsResult := RscGetOption(ulOptionsHandle,
                            pcHostInetAddress,
                            pcOptionValue);
         if wsResult = 0 then
         begin
           ShowMessage('RscGetOption Ok , address= ' +
StrPas(pvHostInetAddress));
         end
         else begin
           ShowMessage(StrPas(RSC4D_Error(wsResult)));
           Application.Terminate;
         end;
      end;
0
Comment
Question by:maurik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Expert Comment

by:sperling
ID: 1335756
Do you have the DLL export declarations? If so, post them and I'll have a look. I believe the problem lies either in calling conventions or parameter sizing, but it's hard to say exactly what without both C and Delphi declarations...

Regards,

Erik.

0
 

Author Comment

by:maurik
ID: 1335757
This is rsc.h C-hederfile for the functions in question. This are the original function reclarations and the delphi ones was already in my question.

#ifndef SHORT
#define SHORT             short     /* 16 bit signed integer,   prefix 'n' */
#endif

#ifndef USHORT
#define USHORT   unsigned short     /* 16 bit unsigned integer, prefix 'u' */
#endif

#ifndef LONG
#define LONG            long      /* 32 bit signed integer,   prefix 'l' */
#endif

#ifndef ULONG
#define ULONG  unsigned long      /* 32 bit unsigned integer, prefix 'ul'*/
#endif

#ifndef VOID
#define VOID            void      /* void or unknown type,    prefix 'v' */
#endif

#define RscCreateOptions        RSCOC
#define RscGetOption            RSCOG

USHORT  FTYPE RscCreateOptions      ( ULONG PTYPE  *ulOptionsHandle );

USHORT  FTYPE RscGetOption          ( ULONG         ulOptionsHandle
                                  , CHAR  PTYPE  *pcOptionSelector
                                  , VOID  PTYPE  *pvValue
                                  );


0
 
LVL 3

Accepted Solution

by:
sperling earned 100 total points
ID: 1335758
From the H/PAS files, I can find only one possible error.

Are you certain "cdecl" should be used? I'd try "pascal" instead. I'll know for sure if you've got the FTYPE declaration somewhere...

And, the handle seems very correct. A common way to create a handle, is to allocate some memory and then cast the pointer to a longint, which is used as the handle. The handle you get looks like this.

Regards,

Erik.


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question