3.12 Directive OPTION DLLIMPORT
a) Using OPTION DLLIMPORT
This option makes the assembler assume that all PROTOs that follow this directive represent functions located in a dll. Syntax:- OPTION DLLIMPORT:<dll_name> | NONE
b) Code Generation Effects
The effects of setting this options are subtle and useful only for MS Windows applications: if the function described by the prototype is called via INVOKE, slightly more efficient code than normal is generated, because the function's address in the IAT is used. Example:- INVOKE GetModuleHandle, NULL
push NULL
call DWORD PTR [_imp__GetModuleHandle@4]
code generation without OPTION DLLIMPORT:
push NULL
call _GetModuleHandle@4
...
_GetModuleHandle@4:
jmp DWORD PTR [_imp__GetModuleHandle@4] ;stub added by the linker
c) OPTION DLLIMPORT in Conjunction with -Fd Switch
Optionally, by using cmdline option -Fd, JWasm will write the import information received through OPTION DLLIMPORT lines to either a file or directly into the object module (COFF and ELF only). Example:
.386
.model flat,stdcall
option dllimport:<kernel32>
GetModuleHandleA proto :dword
ExitProcess proto :dword
option dllimport:none
.code
invoke GetModuleHandleA, 0
invoke ExitProcess, 0
end
- JWasm -coff -Fd=lnk.rsp sample.asm
- import '_ExitProcess@4' kernel32.ExitProcess
- import '_GetModuleHandleA@4' kernel32.GetModuleHandleA
- Wlink format windows pe file sample.obj @lnk.rsp