Hi people. Newbie(ish) question.

I've got an EXE file and it compiles fine, but assembling brings up the following error:

Assembling: C:\ASM Stuff\ASM\EXE Export\Export.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

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

Make error(s) occured.


Here's the code:



.486
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

;
; Prototypes
;
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD


.data
szBuffer db 256 dup(0)

.code

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

invoke GetModuleFileName,0,ADDR szBuffer, 256
OR EAX, EAX
JZ Finish ; Leave if something went wrong

Add EAX, OFFSET szBuffer ; Get a pointer to the buffer string

Dec EAX
Cmp BYTE PTR [EAX], "\"
Jne Finish

Mov BYTE PTR [EAX], 0

invoke MessageBox,0,EAX,0,MB_OK

Finish:
invoke ExitProcess, 0

WinMain endp

End


It's just a test file I'm working on using code I found in a post today. Just wondering why I'm getting the linker error. I've checked the FAQ and found nothing. A search on this site brought up one post

http://www.asmcommunity.net/board/index.php?topic=2523&highlight=unresolved+external+symbol+WinMainCRTStartup

but I couldn't see precisely what the answer was to that question.

Cheers.
Posted on 2002-12-04 10:47:58 by MrClyfar
"_WinMainCRTStartup"

Are you linking in the standard C++ libraries (or some other .obj) in to the exe?
Posted on 2002-12-04 11:05:53 by scientica
You are missing "Foo" and "End foo".
Try this:


.486
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

;
; Prototypes
;
;WinMain proto :DWORD,:DWORD,:DWORD,:DWORD


.data
szBuffer db 256 dup(0)

.code

foo:
; WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

invoke GetModuleFileName,0,ADDR szBuffer, 256
OR EAX, EAX
JZ Finish ; Leave if something went wrong

Add EAX, OFFSET szBuffer ; Get a pointer to the buffer string

Dec EAX
Cmp BYTE PTR [EAX], "\"
Jne Finish

Mov BYTE PTR [EAX], 0

invoke MessageBox,0,EAX,0,MB_OK

Finish:
invoke ExitProcess, 0

;WinMain endp

End foo
Posted on 2002-12-04 11:06:51 by bazik
Hi again.

Cheers Bazik, that idea using a Foo label works. For rerference I wasn't linking to any C/C++ code, just using the default modules that came with the MASM setup.

Thanks. :)
Posted on 2002-12-04 11:19:54 by MrClyfar
You are missing "Foo" and "End foo".


:tongue: :grin: :)

Most people would use something like start instead of foo, but as you can see, it doesn't matter.

:)
Posted on 2002-12-04 13:54:16 by S/390
why are people always using foo? I don't understand. :)

foo:

foo PROC

void foo()

foo struct

foo MACRO

.....

???
Posted on 2002-12-04 14:01:17 by stryker

why are people always using foo? I don't understand. :)

foo:

foo PROC

void foo()

foo struct

foo MACRO

.....

???


http://www.tuxedo.org/~esr/jargon/html/entry/foo.html

and

http://www.tuxedo.org/~esr/jargon/html/entry/metasyntactic-variable.html
Posted on 2002-12-04 14:02:45 by bazik
I know, but why? is it a personal preference? or for formality sakes?

both? :)

anyway, doesn't matter... :)

never mind. :grin:
Posted on 2002-12-04 14:07:29 by stryker

I know, but why? is it a personal preference? or for formality sakes?

both? :)

anyway, doesn't matter... :)

never mind. :grin:


You are talking foo, stryker...
Posted on 2002-12-04 14:17:51 by bazik
LMAO!!! :grin:
Posted on 2002-12-04 14:26:45 by stryker
nah...

he just left out the most important thing of a program entry point :grin:



start:
...
...
...
end start


cheers :grin:
Posted on 2002-12-04 19:47:55 by roticv
It's probably tradition. My old boss used to use it for everything. He was MIT, old DEC computer programmer.
Posted on 2002-12-04 22:11:20 by drhowarddrfine
It's probably tradition. My old boss used to use it for everything. He was MIT, old DEC computer programmer.
oh I see :grin:

usually I just do like this

labelname:

nameoffunction PROC

macroname MACRO

....

still the same but foo is much shorter and saves us a few keystrokes and save us a couple of milliseconds of typing. :grin:
Posted on 2002-12-04 22:17:40 by stryker
It's probably tradition. My old boss used to use it for everything. He was MIT, old DEC computer programmer.
oh I see :grin:

usually I just do like this

labelname:

nameoffunction PROC

macroname MACRO

....

still the same but foo is much shorter and saves us a few keystrokes, saves us a couple of milliseconds of typing, saves a few processor cycles (long explanation snipped)... :grin:
Posted on 2002-12-04 22:18:46 by stryker
Since I dont use the simplified segments and stuff, I just found is easier to do this:


.686
.MMX

.model flat,stdcall
option casemap:none
option dotname

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

[COLOR=red]public WinMainCRTStartup[/COLOR]

_TEXT SEGMENT

[COLOR=red]WinMainCRTStartup label dword[/COLOR]
align 4
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke main,eax,NULL,SW_SHOWDEFAULT
invoke ExitProcess,eax
.
.
.

For some reason I have had problem even with the start directive, but this works every time.
Posted on 2002-12-04 22:42:38 by ThoughtCriminal
the start directive, don't you mean the end directive? (Isn't it the end that says where the code begins?)
Posted on 2002-12-04 23:22:03 by scientica

the start directive, don't you mean the end directive? (Isn't it the end that says where the code begins?)


Not really sure. I don't use start: and end start(?) anymore.
Posted on 2002-12-05 00:52:26 by ThoughtCriminal
IIRC one can use some option (I think: /entry:label ) to specify entry point.

What I ment was that it's the "END label" that tells ml.exe that the entry is at "label", if it's not wrong.

As I read it now I see it's hard (almost impossible) to understand what I ment, sorry. :o
Posted on 2002-12-05 10:35:37 by scientica