Solved

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

Posted on 2008-10-16
4
507 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Delphi: ForceDirectory plain function 7 80
JavaFX TableView not displaying correctly 3 149
import as existing maven project 3 76
Adjust the codes 3 61
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

739 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