How can I call a exported function using ordinal number
Asked Answered
R

1

17

If a dll exports some functions and the functions have only ordinal numbers, how can I call the functions?

Give me a short example please.

Rutter answered 30/8, 2010 at 5:37 Comment(0)
U
31

The documentation for GetProcAddress explains that you pass the integer ordinal in the low-order word of the lpProcName parameter. The MAKEINTRESOURCE macro can actually be used to make this a little easier:

int ordinal = 123;
HANDLE dll = LoadLibrary("MyDLL.dll");
FARPROC fn = GetProcAddress(dll, MAKEINTRESOURCE(ordinal));
Ultramicroscopic answered 30/8, 2010 at 5:42 Comment(3)
I don't know why this does not work in my case: #47283345Pangenesis
You need to call (PCSTR)ordinal in UNICODE projects.Threegaited
It's actually MAKEINTRESOURCEA(ordinal) to make it compatible with UNICODE projects.Cabretta

© 2022 - 2024 — McMap. All rights reserved.