PDA

View Full Version : Can't compile first box plugin?



Knight Chat X
08-27-2005, 03:09 AM
In Visual Studio 2005 I get the following when trying to compile the simple sample box1 plugin in C++:

Warning 1 warning C4996: 'sprintf' was declared deprecated c:\development\lightwave plugin\box1\box1\box1.cpp 16

Error 2 error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(long,GlobalFunc (__cdecl *),LWModCommand *,void *)' to 'ActivateFunc (__cdecl *)' c:\development\lightwave plugin\box1\box1\box1.cpp 21

Lightwolf
08-27-2005, 04:31 AM
The first warning can be safely ignored. MSVC 2005 is picky about library functions that can cause a buffer overflow and warns you about using them.

You are compiling a C++ plugin? C++ is a lot pickier about types than C is, so you have to make sure that your function arguments match the ones expected by the SDK.

The Activate function for any plugin is actually:


Activate( long version, GlobalFunc *global, void *local, void *serverData);


and you have to cast the LWModCommand:


#include <lwserver.h>
#include <lwcmdseq.h>
#include <stdio.h>

XCALL_( int )
Activate( long version, GlobalFunc *global, void *l,
void *serverData)
{
LWModCommand *local = static_cast<LWModCommand *>(l);
char cmd[ 128 ];

if ( version != LWMODCOMMAND_VERSION ) return AFUNC_BADVERSION;
sprintf( cmd, "MAKEBOX <%g %g %g> <%g %g %g> <%d %d %d>",
-0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1, 1, 1 );
local->evaluate( local->data, cmd );
return AFUNC_OK;
}

ServerRecord ServerDesc[] = {
{ LWMODCOMMAND_CLASS, "Tutorial_Box1", Activate },
{ NULL }
};

I haven't checked this in the compiler though...

Cheers,
Mike

Knight Chat X
08-27-2005, 05:52 AM
Tried what you mentioned and got it compiled, now when I try and add it to lightwave modeler gives error "Cannot load external plug-in file."

Then another popup error says "0 plugins found in 1 file."

In Visual Studio I get this new warning:
Warning 2 warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators MSVCRT.lib

Lightwolf
08-27-2005, 06:02 AM
Have you followed all the other instructions in the SDK? I.e. compiled the library and linked that with your code? It seems that LW can't find the server record... Thisis quite hard to diagnose remotely since it depends on the compiler settings as well...

Cheers,
Mike

Knight Chat X
08-27-2005, 06:21 AM
Yes when I compiled the .lib there were no error's or warnings.

It's probably a configuration issue, I've uploaded the project attachment.

-UPDATE-

Ok, finally got plugin to install by adjusting the serv.def file from:
LIBRARY
EXPORTS
_mod_descrip

-TO-

LIBRARY "box1"
EXPORTS
_mod_descrip
Activate

Now let's see if it'll work.

Knight Chat X
08-27-2005, 07:33 AM
Ok, works like a charm, I'm makin that interface move left and right, thanks!

Lightwolf
08-27-2005, 07:34 AM
Weird but cool, good to see you got it working :)

Cheers,
Mike

leevun
05-28-2006, 08:00 AM
Hi,

i've tried to build my first plug-in with lightwave sdk 8. It's the first box plug-in from the tutorials i've found.

I use VS 2003 .NET, microsoft visual C++.

When I try to build my plugin everything is ok, now when I try and add it to lightwave modeler, the system gives an error "Cannot load external plug-in file."
afterwards i get the pop-up that zero plug-ins were found.

serv.def looks like:

LIBRARY
EXPORTS
_mod_descrip

box.c looks like
#include <lwserver.h>
#include <lwcmdseq.h>
#include <stdio.h>


XCALL_( int )
Activate( long version, GlobalFunc *global, LWModCommand *local,
void *serverData )
{
char cmd[ 128 ];

if ( version != LWMODCOMMAND_VERSION )
return AFUNC_BADVERSION;

sprintf( cmd, "MAKEBOX <%g %g %g> <%g %g %g> <%d %d %d>",
-0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1, 1, 1 );
local->evaluate( local->data, cmd );

return AFUNC_OK;
}


ServerRecord ServerDesc[] = {
{ LWMODCOMMAND_CLASS, "Tutorial_Box1", Activate },
{ NULL }
};


my build log gives following warning:
LINK : warning LNK4098: defaultlib 'LIBCD' conflicts with use of other libs; use /NODEFAULTLIB:library

i've tried to compile as a dll-extention but also as a 'p' extention (box1.p)
I've rebuilt my server.lib several times and added it to my current project.

Everything i tried didn't work.
Can anybody help? Please?

Regards,

Leevun

carllooper
06-21-2006, 03:20 AM
Try working without a precompiled lib.

Start a new DLL project.

Add the plugin code you want to compile, eg.

box.c

Then add:

servmain.c
startup.c
shutdown.c
serv.def

Compile (and link)

Notes. Ensure the sdk "include" directory is known to the project. If having trouble with sdk8 try sdk7 or sdk9. The headers in 8 reference other headers incorrectly (but fixable if you know what you're doing - see below).

Carl

sdk8 headers

Here is a typical reference in sdk8:

#include <lwsdk/lwimageio.h>
#include <lwsdk/lwhandler.h>

The header with this reference expects to find other headers, not in the "include" directory, but in an imaginary "lwsdk" directory. Of course you don't want to be going through each header and rewriting it as (eg):

#include <lwimageio.h>
#include <lwhandler.h>

One solution is to create a brand new directory inside the include directory and call it "lwsdk". Then just bulk copy all the headers to this new directory.