#1
|
|||
|
|||
Static import by ordinal
Is there any way to import a function in a C program that is only exported by ordinal from a DLL (besides dynamically using LoadLibrary/GetProcAddress)?
For example the IsOS function is documented by MS (recently) and is exported by shlwapi.dll as ordinal 437, how can it be statically linked in a C program? |
#2
|
|||
|
|||
Simply use a *.DEF file and pass "import by ordinals" to your linker.
|
#3
|
|||
|
|||
Your answer was a bit cryptic but it put me on the way to the solution.
For other readers of this post I would recommend the following article on Microsoft's Knowledge Base: "How To Create 32-bit Import Libraries Without .OBJs or Source". As the title suggests the modifications are NOT to your application but are related to the DLL instead. Also the "import by ordinal" linker option is only relevant to Borland C/C++ products. Hope this helps... |
#4
|
|||
|
|||
The way Microsoft describes the problem is quite complex and I don't see how to use the document to import by ordinals (since "IsOS" is not exported by name, only by ordinal). I only know a far more simple way.
Create a *.DEF file with the following content: Code:
IMPORTS IsOS = SHLWAPI.437 This will then import all functions by name, expect the one you called "IsOS", which is imported by ordinal. If you don't use the "import by ordinal" switch, your program will try to load "IsOS" from SHLWAPI.DLL and (of course) fail. If you have to use the Microsoft linker for some reason, you should simply create yourself a program which parses your import table and replaces a given imported name with it's ordinal. Of course this will require manual input if the function isn't exported by name at all. |
#5
|
|||
|
|||
The IMPORT section is no longer valid in a .DEF file. So there is no way you could tell your C program how to import. Other compilers - including managed code in Visual C++ - do have the option to specify import attributes such as the ordinal for the import.
The article explains two alternatives: one with import by ordinals only for C functions and the other for general functions (but does not use import by ordinal). However, just combine the two solutions and you can get what you want. That is, create stubs for the functions you want to import and also create a DEF file with EXPORTS to specify the ordinal, then generate the dummy DLL and you get a LIB that allows you to import the desired function by ordinal. I did it and it worked. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CrackMes.de Static Mirror | SmilingWolf | General Discussion | 4 | 01-16-2019 19:07 |
How create Static Library (lib) in delphi? | Newbie_Cracker | General Discussion | 7 | 10-26-2011 22:33 |
Import Rebuilding Without Import Table | Kerlingen | General Discussion | 11 | 01-13-2005 10:24 |