3.12 Directive OPTION DLLIMPORT

Asmc Macro Assembler

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
<dll_name> must be enclosed in angle brackets. Argument NONE will switch back to the default mode.

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
code generation with OPTION DLLIMPORT:
 
        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
After the assembly step, file lnk.rsp will contain:
import '_ExitProcess@4' kernel32.ExitProcess
import '_GetModuleHandleA@4' kernel32.GetModuleHandleA
Both Open Watcom's Wlink and JWlink will be able to directly use this information and hence, as a result, no further Windows import libraries are needed in the link step:
Wlink format windows pe file sample.obj @lnk.rsp
JWlink may even go one step further - it's able to read import definitions contained in a COFF or ELF module's linker directive section ( named ".drectve" ). Therefore one can omit the filename argument for -Fd. Sample Win32_7 demonstrates the usage.

d) OPTION DLLIMPORT in Conjunction with -pe Switch

If output format PE is selected, using OPTION DLLIMPORT is the only way to resolve external references; see PE Output Format for more information.