News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Stupid questions on LINK, LIB and DLLs

Started by bf2, October 12, 2011, 04:22:32 PM

Previous topic - Next topic

dedndave

__imp__ExitProcess@4 is the one you want
however, i am not sure how to tell it how many parameters it has   :P
after that, you need a line something like this so that you don't have to use the mangled name

ExitProcess equ <__imp__ExitProcess@4>

bf2

Attempt 3:

kernel32.def contains

EXPORTS
_imp__ExitProcess@4


For user32.lib, I am using the MAMS32 library - just to keep the number of unknowns small.

Source code:

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDELIB \masm32\lib\user32.lib       ; MASM32 library
INCLUDELIB kernel32.lib              ; My library, created from kernel32.def

ExitProcess equ <_imp__ExitProcess>

ExitProcess PROTO :DWORD
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD

.CONST
MB_OK EQU 0h

.DATA
caption DB "Caption", 0
text DB "Text4", 0
hWindow DD ?

.CODE
start:

INVOKE MessageBoxA, hWindow, ADDR text, ADDR caption, MB_OK

INVOKE ExitProcess, 0

END start


Result: Assembles fine, links fine, but crashes at runtime with error 'The procedure entry point _imp__ExitProcess@4 could not be located in the dynamic link libary kernel32.dll'.

Vortex

Hi bf2,

Here is how to create your own module definition files and import libraries :

\masm32\tools\l2def\l2def.exe \masm32\lib\kernel32.lib
\masm32\tools\l2def\l2def.exe \masm32\lib\user32.lib


The commands above will extract the decorated .def files from import libraries. The following commands are creating the import libraries :

\masm32\bin\polib /OUT:kernel32.lib /DEF:kernel32.def /MACHINE:X86
\masm32\bin\polib /OUT:user32.lib /DEF:user32.def /MACHINE:X86



bf2

Quote from: Vortex on October 19, 2011, 05:52:00 PM
Hi bf2,

Here is how to create your own module definition files and import libraries :

\masm32\tools\l2def\l2def.exe \masm32\lib\kernel32.lib
\masm32\tools\l2def\l2def.exe \masm32\lib\user32.lib


The commands above will extract the decorated .def files from import libraries. The following commands are creating the import libraries :

\masm32\bin\polib /OUT:kernel32.lib /DEF:kernel32.def /MACHINE:X86
\masm32\bin\polib /OUT:user32.lib /DEF:user32.def /MACHINE:X86




Hi Vortex
I used the LIB command to create kernel32.lib from kernel32.def:
lib /def:kernel32.def /out:kernel32.lib

Vortex

Hi bf2,

lib.exe can create import libraries too but the sizes are much more large.

dedndave

i finally got it to work   :P
i used the masm32 LIB's, but if your LIB's are correct, they should work
        .386
        .MODEL  Flat,StdCall
        OPTION  CaseMap:None

;--------------------------------------------------------

MB_OK       EQU 0

;-------------------------------

pr1         TYPEDEF PROTO :DWORD
pr4         TYPEDEF PROTO :DWORD,:DWORD,:DWORD,:DWORD

;-------------------------------

            EXTERNDEF _imp__ExitProcess@4:PTR pr1
ExitProcess EQU <_imp__ExitProcess@4>

            EXTERNDEF _imp__MessageBoxA@16:PTR pr4
MessageBox  EQU <_imp__MessageBoxA@16>

;--------------------------------------------------------

        INCLUDELIB \masm32\lib\kernel32.lib
        INCLUDELIB \masm32\lib\user32.lib

;--------------------------------------------------------

        .DATA

caption1 db 'Caption',0
text1    db 'Text',0

;--------------------------------------------------------

        .CODE

_main   PROC

        INVOKE  MessageBox,0,offset text1,offset caption1,MB_OK
        INVOKE  ExitProcess,0

_main   ENDP

;--------------------------------------------------------

        END     _main

clive

test.asm
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDELIB \masm32\lib\user32.lib       ; MASM32 library
INCLUDELIB kernel32.lib              ; My library, created from kernel32.def

ExitProcess PROTO :DWORD
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD

.CONST
MB_OK EQU 0h

.DATA
caption DB "Caption", 0
text DB "Text4", 0
hWindow DD ?

.CODE
start:

INVOKE MessageBoxA, hWindow, ADDR text, ADDR caption, MB_OK

INVOKE ExitProcess, 0

END start


kernel32.def
LIBRARY kernel32
EXPORTS
_ExitProcess@4


\masm32\bin\polib /machine:ix86 /def:kernel32.def /out:kernel32.lib
ml -coff test.asm -link /SUBSYSTEM:WINDOWS


C:\MASM>\masm32\bin\polib /machine:ix86 /def:kernel32.def /out:kernel32.lib

C:\MASM>ml -coff test.asm -link /SUBSYSTEM:WINDOWS
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: test.asm
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS
"test.obj"
"/OUT:test.exe"


test.exe runs correctly.

LIB will not generate the correct linkage for this to work, use POLIB.
It could be a random act of randomness. Those happen a lot as well.

dedndave


clive

Quote from: dedndave on October 19, 2011, 06:53:31 PM
Clive's looks simpler than mine

It just reinforces what a half-assed job most vendors do with object files and linkers, which becomes painfully evident if you try to do things slightly outside the norm, but really should be achievable.

Even with something like ELF I had to build tools to get WATCOM ELF objects to be viable under Linux.

The linker really should be able to use a DLL as a template in the absence of a LIB, or at the very least be able to synthesize the LIB directly from the DLL or a DEF file properly.
It could be a random act of randomness. Those happen a lot as well.

bf2

Thanks very much gents! Much appreciate your patience and help.