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
Solved

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

Posted on 2008-10-16
4
501 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 53
DBGrid or StringGrid ? 6 105
difference between sorce folder and folder in eclipise 3 29
shape, triangle, dbctrlgrid 3 17
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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

828 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