PDA

View Full Version : LW SDK & C++ or i something not understand



Andrew Denison
01-13-2004, 11:29 PM
how link C activation function in (*.c)
with C++ function in (*.cpp)
----
other words:
how call C++ function from C (activation) function
===========================
hope not stupud question :confused:

fortress
01-13-2004, 11:29 PM
not really sure what the question is your asking

Lightwolf
01-14-2004, 03:23 AM
extern "C" it, that should work...
Cheers,
Mike

Andrew Denison
01-14-2004, 08:35 AM
If I am not mistaken extern "C" is for cases
when C function called from C++ function...

but i try this... not working.. msvc

----plugin.c----
#include <lwserver.h>
#include <lwcmdseq.h>
#include <lwxpanel.h>
#include "work.h"

XCALL_( int )
Activate( long version, GlobalFunc *global, LWModCommand *local,
void *serverData )
{
work();
return AFUNC_OK;
}

ServerRecord ServerDesc[] = {
{ LWMODCOMMAND_CLASS, "ADS3D Model export",Activate },
{ NULL }
};

-----work.h----
extern "C" void work();

-----work.cpp-----
#include "work.h"

void work()
{
// do somethis using c++ classes
}

MSVC
------------------------------------------------------------
y:\lw_plugins\plugin\work.h error C2059: syntax error : 'string'

Lightwolf
01-14-2004, 08:45 AM
Here you go, this works (MSVC 6):
--- file stl_import.cpp ---

#include <lwserver.h> // lw includes
#include <sstream> // STL include

extern "C" XCALL_( int )
stl_import( long version, GlobalFunc *global, LWObjectImport *local, void *serverData )
{
// object importer class
}

I guess you could even change XCALL_ to to an extern "C".
The point is, all functions called from LW need to be extern "C" ed...

Cheers,
Mike

Andrew Denison
01-14-2004, 11:35 PM
OK. Ill all understood!..

thanks alot for u help!

Lightwolf
01-15-2004, 01:17 AM
No problems, any time.
Just for safety, basically declare anything as extern "C" that gets called from LW, this would for example include callbacks as well...
Cheers,
Mike