Hello! I have a problem trying to call a MASM function from a C program. This is just a test program, so it is very small. I am using the free Borland C++ compiler, and MASM 6.14 * In my C code, I have:

extern int Test_Asm(int p1, int p2);
...
Test_Asm(arg1, arg2);
...
* In my ASM code, I have this:

.386
MODEL FLAT

_Test_Asm PROTO C p1:SWORD, p2:SWORD

.CODE

_Test_Asm PROC C p1:SWORD, p2:SWORD
 {Some code here. I put my return value in eax.}
_Test_Asm ENDP

END
I can compile the C file with BCC32, and the ASM file with ML, and I receive no errors or warnings. However, when I try to link them using ILINk32, I receive this: "Error: Unresolved external '_Test_Asm' referenced from TEST.OBJ" Another thing is if I remove the arguments from the Test_Asm function (simply "extern int Test_Asm(void)", and "_Test_Asm PROTO" and "_Test_Asm PROC"), I can compile, link and run it with no problems. Any help on this one? Thanx in advance. :-)
Posted on 2001-04-27 10:02:00 by Zir0
What command line do you use to assemble the file? BCC32 uses OMF formated object files, while the batch files that are standard with MASM32 assemble coff file .obj files. If you don't use the /coff switch with "ml", that should produce OMF files (I think). Mirno
Posted on 2001-04-27 10:43:00 by Mirno
I do not use the /coff switch, so I'm always using the OMF format. This message was edited by Zir0, on 4/27/2001 11:57:17 AM
Posted on 2001-04-27 11:56:00 by Zir0
Have you tried removing the _ from your asm declarations, I think that masm will add the necessary decorations to a function. Mirno
Posted on 2001-04-27 12:12:00 by Mirno
I just tried it, and I'm still getting the same error message. I also tried declaring the extern function in the C file with its arguments, and the ASM function without the arguments, and it compiles and links with no errors. Through this, is there any way that I can get the arguments into my ASM function? Should I be doing something like this? ... push ebp mov ebp, esp ... ;gets the first agument mov eax, ;gets the next argument pop ebp ret ... Here, I am trying to return the second argument. This message was edited by Zir0, on 4/27/2001 12:42:20 PM
Posted on 2001-04-27 12:40:00 by Zir0
Ziro, It is easy enough to use libraries made in MASM with Microsoft C and all you have to do is write the C prototypes for the functions in the library that you are going to use but I am not sure that it will work using Borland C as the object file format is different. If you own a copy of TASM 5.0, try making a library from the module in TASM and then call it from your Borland C program. It may be possible to use a module written in MASM from Borland C but I don't know how uts done. Regards, hutch@pbq.com.au
Posted on 2001-04-27 22:03:00 by hutch--
If the "C" compiler is actually a C++ compiler, you usually need to extern the function prototype with the "C" tag:

    extern "C" int Test_Asm(int p1, int p2);
Otherwise, the compiler will add extra characters that encode the argument types. You should run TDUMP to see what symbols are actually being created in the .obj files. (Maybe MASM is adding some characters, too.)
Posted on 2001-04-27 22:17:00 by tank
have you thought about making a DLL with MASM then use it in your C++ program? that to me would be easier... just a suggestion...
Posted on 2001-04-28 01:13:00 by Zcoder