Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RemoteServerCall

Posted on 1997-04-27
3
Medium Priority
?
271 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 300 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

Industry Leaders: 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline
Suggested Courses

885 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