Solved

RemoteServerCall

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 95
Dynamically Created Query 3 50
Delphi Ado Query To Converts Joined Columns Into Rows Based on Primary Key 4 39
update joined tables 2 31
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

16 Experts available now in Live!

Get 1:1 Help Now