Hi! WHo knows how to call a c++ member function out of a MASM32????????


Def file:
________________________________________________
LIBRARY nk.dll

EXPORTS
?n_printf@@YAXPBDZZ
_________________________________________________
"lib.exe /def:nk.def /MACHINE:IX86"---> O make a .LIB file

Now I try to use MASM to complile the disassembly



extrn ?n_printf@@YAXPBDZZ:dword
call ds:?n_printf@@YAXPBDZZ


Linker Error:
_____________________________________________________________________________________
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

memo_OUT.obj : error LNK2001: unresolved external symbol _?n_printf@@YAXPBDZZ
_____________________________________________________________________________________

I tried also:

extern _imp__?n_printf@@YAXPBDZZ:dword
?n_printf@@YAXPBDZZ equ _imp__?n_printf@@YAXPBDZZ

which make the Error:
memo_OUT.obj : error LNK2001: unresolved external symbol __imp__?n_printf@@YAXPBDZZ

It works with all standard functions but not with this ?...@@... c++ stuff(member functions,...)

Who knows the solution?

thx

Harry
Posted on 2002-10-10 08:50:13 by Otanium

Now I try to use MASM to complile the disassembly


Disassembly of what?
Posted on 2002-10-10 08:58:12 by bazik
I compile with MASM!
Posted on 2002-10-10 09:00:58 by Otanium

I compile with MASM!


That does not answer my question :rolleyes:
We have strict rules here and if I hear "disassembly", I am interested what
you disassembled there...
Posted on 2002-10-10 11:04:42 by bazik
C and MASM compilers automatically add a _ in front of the function, and sometimes append @4 (this is the total size of the variables pushed on stack, in bytes)
you'd best do the following:

LIBRARY nk.dll
EXPORTS
?n_printf@@YAXPBDZZ _printf

thus renaming the exported function name.
Try without the beginning _ if this does not work.

or in the C++ source make the function:
externdef "C" {
..
} or something like that, I do not remember.

then in the asm src you can use _printf or printf. Try these, I'm not sure which was the right one.
Posted on 2002-10-12 16:04:23 by Ultrano
This is what I do:




.686
model flat, stdcall

.code

; If its an exported function of a DLL then use "export" instead of "public"

myAsmProc proc public
ret
myAsmProc endp


end

Then in a C header




#ifdef __cplusplus
extern "C"{
#endif

void _stdcall myAsmProc();

#ifdef __cplusplus
"}"
#endif



Hope this helps

As of C++ functions, I advice against using them from assembly, because "name-mangling" its different between different C++ compilers or (sometimes) even different in different versions of the same compiler.
Posted on 2002-10-13 11:24:32 by dxantos