Hello
I would like use a C++ static Library in masm32
Now is the problem to call a procedur from this lib
How i can call this?
BOOL MYLib::Init
I have try to use
Init PROTO C
Invoke Init
Have your an idea?
The simple answer is that all the functions must declared extern "C" and not class methods (or at least static ones). If you don't have the source for the static library, things get tricky.
r
Calling C++ functions from MASM (http://www.masm32.com/board/index.php?topic=5594.0)
Thanks for your answhere
I comming not further
I create a static Lib with Vc++ 6.0
and add this code
MY_Init()
{
MessageBox(0, "Messages", "info", 0);
return (FALSE);
}
Now compile it to a Lib and it works fine
But in my Asm source can i not call MY_Init from this lib
error LNK2001: unresolved external symbol MY_Init
fatal error LNK1120: 1 unresolved externals
Too lazy to read Vortex' post, ragdog?
Yes i have it
but now i use in my MY_Init() procedur more parameter
MY_Init(DWORD lpmess, DWORD lpinfo, DWORD lpmess2, DWORD lpinfo2,
LPTSTR filename)
{
MessageBox(0, lpmess, lpinfo, 0);
MessageBox(0, lpmess2, lpinfo2, 0);
MessageBox(0,filename, 0, 0);
return (FALSE);
}
And i have change the Proto
?MY_Init@@YAHKKKKPAD@Z PROTO SYSCALL
MY_Init EQU <pr5 PTR ?MY_Init@@YAHKKKKPAD@Z>
If i call this in my Masm source crash it
without parameter works this ::)
must i set here the number of parameter? pr5
Now have i make a Libary but i have by compiling this error
error LNK2001: unresolved external symbol WriteFile
Why ? I use in my masm32 source
include kernel32.inc
includelib kernel32.lib
How much can we win if we guess the right solution without seeing the code?
Write a C interface to that C++ library.
// C++ LIB
<?php // just for syntax hl :D
class AwesomeCPPLib
{
bool DoStuff(int abc)
{
}
}
?>
// C PROXY -- COMPILED AS C++!!
<?php // just for syntax hl :D
extern "C" void* __stdcall AwesomeCPPLib_Create()
{
AwesomeCPPLib *that = new AwesomeCPPLib();
return (void*)that;
}
extern "C" bool __stdcall AwesomeCPPLib_DoStuff(AwesomeCPPLib* that, int abc)
{
return that->DoStuff(abc);
}
extern "C" void __stdcall AwesomeCPPLib_Destroy(AwesomeCPPLib* that)
{
delete that;
}
?>
// MASM HEADER - SuperCPPLib_for_MASM.inc
AwesomeCPPLib_Create proto stdcall
AwesomeCPPLib_DoStuff proto stdcall :ptr, :sdword
AwesomeCPPLib_Destroy proto stdcall :ptr
// BATCH
REM --- Explode original library
polib /explode SuperCPPLib.lib
REM --- Copy compiled proxy obj
copy ../SuperCPPLib_proxy.obj ./SuperCPPLib_proxy.obj
REM --- Make new library
polib /out:SuperCPPLib_for_MASM.lib *.obj
// MASM program includes
include SuperCPPLib_for_MASM.inc
includelib SuperCPPLib_for_MASM.lib
// MASM CODE
invoke AwesomeCPPLib_Create
mov ebx,eax
invoke AwesomeCPPLib_DoStuff,ebx,123
invoke AwesomeCPPLib_Destroy,ebx
OR
you could stop converting everything to masm and just write c++ code (http://www.masm32.com/board/Smileys/mforum/icon_eek.gif)
Quoteyou could stop converting everything to masm and just write c++ code
:bg I write a c++ code but i make a lib and Test it in masm32
Thanks i try your soulution