Solved

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

Posted on 2008-10-16
4
489 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
Comment Utility
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
Comment Utility
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
Comment Utility
 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
Comment Utility
Thanks for your help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 125
java ^ examples 8 57
mapBully challenge 6 88
How to define IfThen functions in one common unit? 4 34
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 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

10 Experts available now in Live!

Get 1:1 Help Now