Solved

Need to call a COM Method from a third party dll file in delphi

Posted on 2008-10-16
4
495 Views
Last Modified: 2013-11-23
I have a third party dll file that I need to use in order to access an api through. I have used DLL export viewer and the login function is a COM Method, with the name showing as IAPI::Login

Synopsis - Login(string companyname, int number, string username, string password) as string

I have registered the dll file (XYZApi.dll) on my computer and need to call the login function through a delphi app.

ANy ideas on how I would call this please?
0
Comment
Question by:ubernewb
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
developmentguru earned 500 total points
ID: 22744531
If it is a COM object DLL, and you have registered the DLL then go to the Delphi main menu
Component | Import Component
choose Import a Type Library (click Next)
choose your COM object's type library from the list (Click Next)
Set the Palette Page for any components, unit directory name, etc (Click Finish)

That should import any COM object that is registered in the system.  Then just create an instance of the COM object and use it's methods.
0
 

Author Comment

by:ubernewb
ID: 22753703
Thanks for that but I cant implement the interface.

The interface in the code library is:

   IAPI = interface(IDispatch)
    ['{GUID}']
   function Login(companyname: widestring; number : Integer; username : widestring; password: widestring) : widestring; safecall;
    procedure ......;
    function  ......;
    function  ......;
   end;

I try to create a class on the main form:

   TMyInterfaceClass = class(TInterfacedObject, IAPI
   function Login(companyname: widestring; number : Integer; username : widestring; password: widestring) : widestring; safecall;
   procedure ......;
   function  ......;
   function  ......;
end;

When I try to compile I get the error messages:

Undeclared identifier: 'GetTypeInfoCount'
Undeclared identifier: 'GetTypeInfo'
Undeclared identifier: 'GetIDsOfNames'

I have found a similar problem here:

http://www.experts-exchange.com/Programming/Editors_IDEs/Delphi/Q_22948763.html

but when I implement the accepted answer ...

"teh IVBSAXContentHandler is an IDispatch interface. You ust also implement the functions from that interface.

you need to find a class that already implements those functions in order to extend from it. A barebone class would be TAutoIntfObject from comobj.

The most used is TComponent :)

so replace
TSAXContentHandler = class(TInterfacedObject, IVBSAXContentHandler)
with
TSAXContentHandler = class(TComponent, IVBSAXContentHandler)"

...I get the error:

Unsatisified forward or external declaration TMyInterfaceClass.Login

Any help would be appreciated

Thanks
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 22754634
 The way you are going about it you are trying to write the code for the interface.  I thought you wanted to use an object that already exists.  If that is the case, follow the steps I gave in my first response.  Then you will not need to implement the interface, just use it.

  By declaring your own class (as using the interface) you are telling Delphi that you want to make your own class that supports the interface.  If this is what you want to do then you need to provide your own implementation of each of the interface methods.  The error you are getting tells you that:
A) You are trying to create a class that supports a specific interface
B) You have not defined the specific method (mentioned in the error) of the interface.
0
 

Author Closing Comment

by:ubernewb
ID: 31507055
Thanks for your help
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

823 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