Solved

RemoteServerCall

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now