Solved

RemoteServerCall

Posted on 1997-04-27
3
259 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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