News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How do i use a MASM-module in VC++ 6.0?

Started by Zap, July 21, 2010, 05:48:17 PM

Previous topic - Next topic

Zap

Hi!
I have a simple procedure in MASM32 – 1.zip
And i want to use this procedure in a VC++ 6.0 project,so i compile it & add the obj-file to Project - Settings - Link - Object/Library modules.
The VC-file – 2.zip
As a result i get this error message:
... unresolved external symbol __MyFunc.
Same thing happens when i compile/link from the command line in VC++ 6.0 like this:
cl 1.cpp /I..\Include /Fo1.obj /EHsc  /c
LINK 1.obj 2.obj  /out:1.exe /SUBSYSTEM:WINDOWS /LIBPATH:..\Lib kernel32.lib user32.lib gdi32.lib
Could u help me & tell what`s wrong as everything seems to be OK.
Thanx

Rockoon

Probably a name mangling issue.

Havent looked at your source, but the functions prototype should be declared as "C" in order to prevent the name mangling of C++ compilers.

For instance:

extern "C" void MyFunc(int foo, int bar);
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

dedndave

you may have to declare the function as PUBLIC
_MyFunc PROC public x:DWORD should do the job

or you could use the PUBLIC directive...
        PUBLIC  _MyFunc

Zap


baltoro

Zap,     
As you probably know, if you are getting the error:
... unresolved external symbol __MyFunc.   
It means that the Visual Studio compiler can't find your OBJ file, or the symbol is NOT exported, or the symbol name is incorrect.     
This article from Microsoft Support might help.   

When I use compiled assembly functions in Visual Studio (C++), I compile the code to a DLL that exports the function (this can be checked with DUMPBIN), and then I just link to the generated LIB file. Put everything in the same project directory, it should work. Also, the function signature that you declare in your C file should match the function prototype that has been exported. When I use a DWORD as parameter in my assembly functions, I have found that I have to explicitly cast that to whatever type (in your case, char *) you are using in your C file, otherwise the Visual Studio compiler sees a prototype signature mismatch. Calling conventions have to be compatible, too.

Baltoro

redskull

Note the extra underscore that is being added for you.  Here is what you get with each proc directive

_MyFunc PROTO :DWORD   ;  __MyFunc@4
_MyFunc PROTO C :DWORD   ;  __MyFunc

For the quick answer, use the second style in masm, and leave the C version unchanged
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Geryon

In the attachment, there is a more primitive(I mean without macros) version.
Maybe it would help.
"Some people have got a mental horizon of radius zero and call it their point of view." --D.Hilbert

hutch--

Zap,

Make sure the assembler proc is prototyped in C both as EXTERN and with the same calling convention, either STDCALL or C. As long as you build the object module in MASM and link it into a C program with the correct prototype and calling convention it should run OK.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php