Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GetProcAddress

Posted on 2004-09-20
15
Medium Priority
?
689 Views
Last Modified: 2010-04-04
I'm trying to dynamically load a DLL. I call LoadLibrary to get my handle, then I typically use GetProcAddress to assign the function to a variable. However, I need to be able to do it using the known index number instead.

Statically I do it like this: function Myfunction(MyData:Integer):Integer; stdcall external 'MyDLL.dll' index 76;

How can I do this dynamically?
0
Comment
Question by:rbohac
[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
  • 3
  • 3
  • 2
  • +4
15 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 12106239
var
  sr: TSearchRec;
  h: Longint;
  GetStatMenu: function: Pchar; stdcall;
  GetStatSubMenu: function: Pchar; stdcall;
begin
        h := LoadLibrary(PChar(sr.Name));
        if h <> 0 then
          begin
          GetStatMenu := GetProcAddress(h,PChar('GetStatMenu'));
          GetStatSubMenu := GetProcAddress(h,PChar('GetStatSubMenu'));
          if Assigned(GetStatMenu) and Assigned(GetStatSubMenu) then
            begin
// functions available
0
 
LVL 6

Author Comment

by:rbohac
ID: 12106317
Right.. using the index number please. NOT the name
0
 
LVL 6

Author Comment

by:rbohac
ID: 12106342
Nevermind. I figured it out. You can pass the index as an ordinal parameter:

GetProcAddress(hDLL, PChar(Integer(76)));
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12106550
I was about to give the correct answer but noticed the question has been answered here. :-)
However, this happens to be useful information so I suggest to refund, close and PAQ it instead. For completeness, I'll add more information from the MSDN site. Keep in mind that if you use an ordinal number, the high-word must be 0.

The GetProcAddress function retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);

Parameters
hModule [in] Handle to the DLL module that contains the function or variable. The LoadLibrary or GetModuleHandle function returns this handle.
lpProcName [in] Pointer to a null-terminated string that specifies the function or variable name, or the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.

Return Values: If the function succeeds, the return value is the address of the exported function or variable. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12109849
--> so I suggest to refund, close and PAQ it instead...
I agree with Workshop_Alex also due for his good additions

F68 ;-)
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12109855
Nevermind, misreaded the -> PAQ-ing the question and refunding points
:)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 12110353
Just a side note: Using GetProcAddress with index numbers doesn't work for kernel32 APIs in win9x. Microsoft did this to prevent system hackers from accessing undocumented APIs. Of course there are ways to work around that limitation...   :-)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12110625
Win9x? Does that still exist? ;-)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 12111068
Oh yes. I still get even support requests about win95 now and then...   :-/
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12111105
Unfortunately it still exists :( I've about 30 customers using already Win95 and there's no way to convince them to upgrade their systems... :(((
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 12120825
Win95... urggh... well, at least I managed to persuade all my Win95 users to upgrade to at least IE4 to get some of the *not-so-new-anymore* new features...
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 12148862
Closed, 50 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12152455
@ee_ai_construct, it has been answered by the expert himself. We just added a few more comments to this question to complete the answer. My suggestion was to PAQ it and am glad it is PAQ'ed.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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