Calling a MASM proc from C++ - how to get to the cstd lib?

Started by allynm, July 17, 2009, 07:54:42 PM

Previous topic - Next topic

MichaelW

Mark,

There should be no "myproc_" symbol. With the underscore added by ML the symbol should be "_myproc". If you are in doubt as to what symbol names are in an object module, library, exe, etc open it in a text editor and take a look. Most of it will not be readable, but the symbol names, strings, and similar will be.

I did everything from a single directory, and here is a listing:

07/17/2009  04:17p                 744 test_asm.asm
07/18/2009  12:56a                 322 makeit.bat
07/18/2009  12:54a                 110 test.c
07/18/2009  12:56a                 555 test.obj
07/18/2009  12:56a              28,149 test.map
07/18/2009  12:56a              40,960 test.exe
07/18/2009  12:56a                 332 test_asm.obj


Which C/C++ compiler are you using, or want to use, and where on your system is it?
eschew obfuscation

allynm

Hi Michael -

I neglected to mention that all my files are in the same directory.  I examined the obj file for the ml command and it shows _myproc listed in exactly this manner.  I checked the obj file for the c caller  after invoking cl and it shows myproc as myproc_. 

_printf is no longer the problem as far as linking is concerned.  That symbol appears to be defined satisfactorily.  Makes me think that there may be something wrong with the prototype in the calling function.  That prototype is currently:

external void myproc( );

I'd really like to solve this problem for the reason that there are many many standatd c functions I'd like to be able to call.  I know there are similar calls in the MASM macros (like "print" and "input") but I can find no documentation on them. 


hutch--

You will find the documentation for the masm32 macros in the high level help file that comes with masm32. You can use the C runtime functions if you need them but they are generally large and force the inclusion of other code that make your app much larger.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

allynm


jj2007

Quote from: hutch-- on July 19, 2009, 01:04:36 PMYou can use the C runtime functions if you need them but they are generally large and force the inclusion of other code that make your app much larger.

Can you give an example?

include \masm32\include\masm32rt.inc

.code
hw db "Hello World at 1024 bytes", 13, 10, 0 ; with polink.exe (2560 bytes with link.exe)

start:
invoke crt_printf, chr$("%s"), offset hw
exit ; short form of invoke ExitProcess, 0

end start

allynm

Hi Hutch -

Thank you for the code.  I will test it immediately.  I take your point as regards the size of the app.  This would certainly be disadvantageous under many circumstances if an alternative existed. In looking thru the Macros you to which you alerted me, it appears that for a lot of calls there would be no justification for using the c equivalents.


I am still working on the problem of calling from a c/c++ main caller, as you can see from my previous comment. 

Mark

MichaelW

We could provide better answers if we knew which C/C++ compiler you are using, or want to use, and where on your system it is.
eschew obfuscation

jj2007

Quote from: allynm on July 19, 2009, 10:56:13 PM
... as regards the size of the app.
Don't worry about the size. My example above calls printf and assembles at 1024 bytes, of which roughly 30 bytes are related to the crt call.

Quote
I am still working on the problem of calling from a c/c++ main caller, as you can see from my previous comment. 

As MichaelW wrote, it would be good to know what exactly you are using. Have you thought of assembling your code as a dll? In one of my apps, I call Win32 assembly code from a trusty 16-bit/Win 3.1 Basic dialect. I guess this should be even easier from a 32-bit C app...

allynm

Hello Hutch -

I did code your program using the masm32rt.inc include instruction.  Not surprisingly it ran just fine.  BUT, when I assembled it using ml /c /coff command the compiler sent back messages that I don't understand and was hoping you could clarify.  First, it gives the following warning:

warning a4011: multiple .model directives found; .model ignored

and it also identifies 5 different duplicate include files:

1.  windows.inc
2. masm32.inc
3. gdi32.inc
4. user32.inc
5. kernel132.inc

I tested what happens if these inc files are removed and the answer is that I get a blizzrd of error messages.

As I say, the code compiles and runs just fine, but I'd like to elliminate these warnings.

Regards,
Mark A.

hutch--

MArk,

Actually have a look at the masm32rt.inc file as it shows you what you need to have for a MASM source code. It does the normal include files with WINDOWS.INC first then the library files.

From your error messages you have duplicates in the .MODEL directive and the includes. If you are setting your own include files and libraries, don't them use the masm32rt.inc file as this will give you duplicates.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

allynm

Hutch -

Thanks as always for your help on this.  You folks are extraodinarily generous with your assistance.  Wish I could do something in return.  If fhere is, let me know.

Mark

dedndave


hutch--

Mark,

Have no fear, once you are up to speed we will get our pound of flesh with your support for other new members.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

allynm

Hutch -

I've been playing around with the include files trying to get rid of the duplicates that occur when I include masm32rt.inc in the code.  If I DON'T include masm32rt then I appear to be missing some basic defines like STDOUT, etc.  I don't know which other include files contain these defines but the little bit of code I am writing in the code section requires them....Also, if I DON't include explicitly the windows.inc file then I get a flurry of error messages, even though that file appears to be referenced in the masm32rt.inc file.  The other files previously mentioned besides windows.inc can be scrapped and nothing goes awry.  And, getting rid of them gets rid of the problem of duplicates and the code runs fine.  But, there is something special about the windows.inc file that is essential.  Doesn't make sense to me. 

Regards,
Mark Allyn

allynm

Hi Hutch again-

Back to this business of including masm32.rt.  If this is the ONLY include file I use then everything works like a clock.  I should have paid attention to what you and Michael and several others had done and included only this file (and also no .model and .486 directives either).  I thought in their code snippets they were assuming that the other includes were already present in my file and were suggesting that I ADD the additional masm32rt.inc file. 

I should have looked inside the masm32rt.inc in the first place.  i would have seen that the needed msvcrt.inc and lib files were already included.  Beginner's ignorance, I guess.

But, to your point about what i can contribute as far as helping other novices is concerned:  The first thing I would do is direct their attention to what is inside masm32rt.  And, I suppose that the next thing I would do is direct them to the Demos in the Tutorial folder and tell them to NOT include all the files they see there.....

Best regards,
Mark Allyn