The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: oversight on October 31, 2005, 08:32:18 PM

Title: masm32 and c++ (ms) using test.cpp & test.asm in test.exe
Post by: oversight on October 31, 2005, 08:32:18 PM
Helo,

where can i find a sample or documentation about using :

functions.asm << some funcs like
proc my_msgbox

endp my_msgbox
end

main.cpp

extern "c" void  my_msgbox;

void main()
{
my_messagebox();

}



would this work, ? and is this linker safe?
Title: Re: masm32 and c++ (ms) using test.cpp & test.asm in test.exe
Post by: Vortex on October 31, 2005, 09:10:37 PM
Hi oversight,

Welcome to the forum.

Here is a simple example for you:

.386
.model flat,stdcall
option casemap:none

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

Msgbox PROTO :DWORD

.data
caption db 'assembly mixed with C++',0
.code

Msgbox PROC string:DWORD
invoke MessageBox,0,string,ADDR caption,MB_OK
ret
Msgbox ENDP

END


extern "C" void __stdcall Msgbox(char * );

int __stdcall WinMain(int hInstance, int hPrevInstance,char *lpCmdLine, int nCmdShow)
{
  Msgbox("This is a demo");
  return 0;
}


\masm32\bin\ml /c /coff Msgbox.asm
cl Test.cpp Msgbox.obj \masm32\lib\user32.lib


Example C++ source file compiled MS VC++ Toolkit 2003

[attachment deleted by admin]
Title: Re: masm32 and c++ (ms) using test.cpp & test.asm in test.exe
Post by: oversight on November 01, 2005, 09:52:07 AM
thanx man,

i am working on soldner project zero, and i was thinking about faster networking.
Then i got the idiea to call all networking code from assembler and expand/optimize that later.

it has been a while since i coded in asm.

www.project-zero.info
www.secretwars.net

currently we are not on any payroll, i hope that changes...
thanx again!
Title: Re: masm32 and c++ (ms) using test.cpp & test.asm in test.exe
Post by: l_d_allan on February 21, 2006, 05:14:34 PM
Vortex,

Thanks for providing these ....

Would it be possible for these files to be part of masm32\examples or masm32\tutorial?

Or is there already something equivalent available for newbies like myself who are, at this point, primarily interested in calling asm functions from C/C++?
Title: Re: masm32 and c++ (ms) using test.cpp & test.asm in test.exe
Post by: Vortex on February 21, 2006, 06:14:26 PM
Hi l_d_allan,

You are welcome. You can find various examples about using C with asm on the net. Please feel free to ask any kind of questions about C & asm. Would you like to see other examples? Maybe, at the week-end, I can send other demos.