News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Unresolved external symbol

Started by Magnum, November 28, 2012, 12:14:48 PM

Previous topic - Next topic

Magnum

; LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
; except.exe : fatal error LNK1120: 1 unresolved externals


; Written by Jeremy Gordon 2002
; except.asm Conversion of except1.asm (Goasm) to masm code
;
;
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\advapi32.inc
include \masm32\include\shlwapi.inc
include \masm32\macros\macros.asm

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\advapi32.lib
includelib  \masm32\lib\shlwapi.lib

.DATA

HappyStr db "Except1,This is a very happy ending",0

Except   db "Except1,There was an exception - do you want me to swallow it?",0

Except1  db "Except1",0

Except2  db "Except1 - well it's all over for now.",0

Unwind   db "The system calling the handler again for more clearing up (unwinding)",0

FATALMESS DB "I thoroughly enjoyed it and I have already tidied everything up - "
          DB "you know, completed records, closed file handles, "
          DB "released memory, that sort of thing .."
          DB "Glad this was by design - bye, bye .."
          DB ".. but first, I expect the system will do an unwind ..",0
.CODE

assume fs: @data
;ASSUME fs:NOTHING ; This statement generates this
;


START:

; Lets make our final handler which would do all clearing up if the program has to close

PUSH offset FINAL_HANDLER
CALL SetUnhandledExceptionFilter
CALL PROTECTED_AREA
CALL CLEAR_UP           ;here the program clears up normally
PUSH 40h                ;exclamation sign + ok button only
push offset Except1
PUSH offset HappyStr
push 0
CALL MessageBoxA        ;wait till ok pressed
PUSH 0                  ;code meaning a succesful conclusion
CALL ExitProcess        ;and finish with aplomb!

; PROGRAM END

PROTECTED_AREA:

;PUSH EBP,0,0            ; )create the
push ebp
push 0
push 0
PUSH OFFSET SAFE_PLACE  ; )ERR structure
PUSH OFFSET HANDLER     ; )on the
;FS PUSH [0]             ; )stack

push dword ptr fs:[0]   ; line 71 error A2108: use of register assumed to ERROR

;FS MOV [0],ESP          ;point to structure just established on the stack
mov dword ptr fs:[0],esp ; line 74 error A2108: use of register assumed to ERROR

;*********************** and now lets cause the exception ..

XOR ECX,ECX             ;set ecx to zero
DIV ECX                 ;divide by zero, causing exception

;*********************** because of the exception the code never gets to here

SAFE_PLACE:             ;but the handler will jump to here ..

;FS POP [0]             ;restore original exception handler from stack
pop dword ptr fs:[0]    ; line 86 error A2108: use of register assumed to ERROR

ADD ESP,14h             ;throw away remainder of ERR structure made earlier
RET

;This simple handler is called by the system when the divide by zero
;occurs.In this handler the user is given a choice of swallowing the
;exception by jumping to the safe-place, or not dealing with it at all,
;in which case the system will send the exception to the FINAL_HANDLER

HANDLER:

;save registers as required by Windows

PUSH EBX
PUSH EDI
PUSH ESI
MOV EBX,[EBP+8]         ;get exception record in ebx
MOV EAX,[EBX+4]         ;get flag sent by the system
TEST AL,1h              ;see if its a non-continuable exception
JNE short nodeal

;JNZ >.nodeal           ;yes, so not allowed by system to touch it
TEST AL,2h              ;see if its the system unwinding
JNE  short unwind             ;yes
PUSH 24h                ;question mark + YES/NO buttons
PUSH offset Except1
push offset Except
CALL MessageBoxA        ;wait till button pressed
CMP EAX,6               ;see if yes clicked
JNE short nodeal             ;no -line 113 orig. jnz

; go to SAFE_PLACE

MOV ESI,[EBP+10h]       ;get register context record in esi
MOV EDI,[EBP+0Ch]       ;get pointer to ERR structure in edi
MOV [ESI+0C4h],EDI      ;insert new esp (happens to be pointer to ERR)
MOV EAX,[EDI+8]         ;get address of SAFE_PLACE given in ERR structure
MOV [ESI+0B8h],EAX      ;insert that as new eip in register context
MOV EAX,[EDI+14h]       ;get ebp at safe place given in ERR structure
MOV [ESI+0B4h],EAX      ;insert that as new ebp in register context
XOR EAX,EAX             ;eax=3D0 reload context and return to system

jmp short fin
;JMP > fin

unwind:

PUSH 40h                ;exclamation sign + ok button only
PUSH offset Except1
PUSH offset Unwind
PUSH 0
CALL MessageBoxA        ;wait till ok pressed, then return eax=3D1

nodeal:

MOV EAX,1               ;eax=3D1 system to go to next handler

fin:

POP ESI
POP EDI
POP EBX
RET

CLEAR_UP:               ;all clearing up would be done here


RET
;
FINAL_HANDLER:          ;system passes EXCEPTION_POINTERS

PUSH EBX
PUSH EDI
PUSH ESI        ;save registers as required by Windows
CALL CLEAR_UP
PUSH 40h                ;exclamation sign + ok button only
PUSH offset Except2
PUSH offset FATALMESS
CALL MessageBoxA        ;wait till ok pressed
MOV EAX,1               ;terminate process without showing system message box
POP ESI
pop EDI
pop EBX
RET

end
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

WinMainCRTStartup is a C compiler entry routine
maybe something Jeremy is using requires the OBJ to be linked with a C compiler
i am just spit-balling, here - lol

anta40

Using polink
Quote
polink /entry:START /subsystem:console except.obj

POLINK: error: Unresolved external symbol '_START'.
POLINK: fatal error: 1 unresolved external(s).

Using golink
Quote
golink /entry START /console except.obj kernel32.dll user32.dll

Warning!
Specified entry point (START) was not found.
Output file: except.exe
Format: win32 size: 2,048 bytes

Weird...

dedndave

ohhhhh
Andy, your code ends with...
end
for EXE source files, it should always reference the entry point
end     START

Magnum

I already tried that.

The program compiles, but doesn't run correctly.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm


error:
start:
end start ; The start here is missing in your source code


Fa is a musical note to play with CL

dedndave

i don't see the "CLEAR_UP" routine in your code

Magnum

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

i put a working version in the other thread

Magnum

I buggered up my bldall.bat and am trying to figure out where the mistake is.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org