Api call from Com

Posted on 2002-03-28
Last Modified: 2010-05-18
I want to refer an .ini file through an API. The API is called from the COM object. When the COM calls the API, the API should refer this ini file.
     In windows 2000 server environment, when i access this API through the dll, the API refers the ini file only if it available in winnt/system32 directory. It is not referring the ini file eventhough it is present in the directory where the APIs are.
     But i need to tell the COM to access the ini file from the directory where the APIs are and not the ini file from the winnt/system32 directory. Please give solution.
Question by:krishnaveni_a
  • 4
  • 2
  • 2
  • +1

Expert Comment

ID: 6902181
Which exactly API function do you use?
LVL 69

Accepted Solution

Éric Moreau earned 50 total points
ID: 6902197
use this API to read from any INI file:

Private Declare Function GetPrivateProfileString Lib "kernel32" _
                         Alias "GetPrivateProfileStringA" _
                         (ByVal lpApplicationName As String, _
                          ByVal lpKeyName As Any, _
                          ByVal lpDefault As String, _
                          ByVal lpReturnedString As String, _
                          ByVal nSize As Long, _
                          ByVal lpFileName As String _
                         ) As Long

Author Comment

ID: 6904380
Actually we are having the API which was created by somebody.
But we are having the sample API application. In this, we are using the "GetPrivateProfileString" function  to read ini file as you mentioned above. Here we are passing the value of the argument namely "Filename" as app.path & "/Readme.ini". And API is in separate location not in system directory. But we are having the ini file in both directories such as Direcotry where the API resides and System directory.

We are calling the function which is in API from our own COM. Now it reads the Readme.ini which is in only System directory not in the directory where our API resides.

We are doubted that is there any diffence while calling the API function from COM and calling from the normal application?.


Expert Comment

ID: 6904630
there is no difference between calling the API from COM or else where.

to access file other than the windows directory, you have to specify it with the full path name.


[in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory. "
LVL 69

Expert Comment

by:Éric Moreau
ID: 6904937
this is because the App.Path from the COM object is different from App.Path value of the EXE. Can you pass the full path from your EXE to your COM?
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.


Author Comment

ID: 6906415
is there any other way rather than passing the fullpath
from the COM to API.?
LVL 69

Expert Comment

by:Éric Moreau
ID: 6906828
run the DLL from the same folder as your application is another method (but I prefer passing the full path).

Expert Comment

ID: 6978588
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
LVL 69

Expert Comment

by:Éric Moreau
ID: 6979082
points to me!

Expert Comment

ID: 6979285

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

21 Experts available now in Live!

Get 1:1 Help Now