Okay, I have found the answer. Actually two solutions exist. But first, the reason for the error is that changes were made to VS 2005 and later, changing how assemblies are put together, and that leads to technical information dealing with the underpinnings of VS. The "how to" is much more important here. First I will put up the sample code, and it is basically the same code regardless of which method is used.
The code:
;sh3.asm - test using c run-time library functions
.586
.model flat
EXTRN _printf:PROC
.data
msgHello DB 'Hello from C library!', 0ah, 00h
.code
_main PROC
push OFFSET msgHello
call _printf
add esp, 4
ret 0
_main ENDP
END
Okay, method 1:
Start with an empty project; add a source file with .asm extension and type in the code. Make sure you name the entry point of your code with _main. Method two with deal with using a different name.
Next, set the project for using MASM by right-clicking on the project name in the solution explorer and selecting custom build rules; check the Microsoft Macro Assembler box.
Next, go to the project -> properties -> linker -> additional dependencies and type in the C run-time library name. For example, msvcrt.lib for release code, or msvcrtd.lib for debug phase. Important note: do not make any entries for entry point or subsystem.
Assemble your code and run it.
Method 2:
Start with an empty project; add a source file with .asm extension and type in the code. Name the entry point of your code with a label of your choice. For example, start.
Next, set the project for using MASM by right-clicking on the project name in the solution explorer and selecting custom build rules; check the Microsoft Macro Assembler box.
Next, go to the project -> properties -> linker -> additional dependencies and type in the C run-time library name. For example, msvcrt.lib for release code, or msvcrtd.lib for debug phase.
Next, while in the Linker pages, select system and change to console, then go to advanced and in the entry point box type in your entry label, like start for example.
Next, while in the linker pages, select manifest files -> additional manifest dependencies and type in this: type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' all as one line.
Assemble and run your code.
You might be wondering where a person finds the stuff for the additional dependencies, as this information is most likely VS and Windows version dependent. Create a simple project using method 1, then find its manifest file and read it in a text editor. You will see the dependency line containing the information.
Personally, I find method 1 to be the easiest way to do the job. Being forced to name my entry point as _main is a very small price to pay for having the flexibility in using C run-time library code. It also has the advantages of not having to set the subsystem too. Now, as a special note - If you are not using C run-time libraries then use method 2 and leave out the step for adding additional manifest dependencies; it is not needed!
By the way, I also tested method 1 using calls to the Win32 API and the C run-time library and the code worked fine. In other words you can use both windows api calls and c run-time library calls in the same code.
I hope you find this information helpful in writing assembly code in Windows using Visual Studio.
Good Luck and have fun!
~jiangshi