Hi.


So, today I had the urge to try and use functions compiled in C/C++ in my assembly programs.

This is what I've come up with.

The C/C++ portion:
[PHP]
#include <iostream>


extern "C" void PrintString(char* string)
{
printf("%s",string);
}

extern "C" void WaitForEnter()
{
std::cin.get();
}
[/PHP]

Assembly portion:
[PHP]
.686

.model flat,stdcall


; externs

extrn PrintString:near
extrn WaitForEnter:near

.data

Message db 'Hello world',0

.code

main:

push offset Message
call PrintString
call WaitForEnter
ret

end main
[/PHP]

From here, I tried compiling them seperatly without linking them, so that I would have both object files. Then linked the object files.

The problem is that everytime I run the executable it gives me an error:
Code:
runtime error R6030
 -CRT not initialized
I googled a little and found out that there was no main function. I came up with using this command in VC's command line.

Code:
LINK /ENTRY:main CPP.cpp ASM.asm
Same thing happens. A little later I tried adding the main function in the C portion rather than the assembly portion and it seemed to stop giving me the error but the console was just empty and instantly closes.

I'm going to assume that when I use
Code:
/ENTRY:main
It looks at the C object file first? I don't know.. I'm completely lost and I can't find anything on google. I've been looking since this morning.

These are the commands I used to compile everything.

C portion:
Code:
cl /c CPP.cpp
Assembly portion:
Code:
ml /c ASM.asm
Link:
Code:
LINK /ENTRY:main ASM.obj CPP.obj
No compile errors at all.



Any help is greatly appreciated.
~Thanks.