HOW TO BUILD STATIC LIB FOR SPACEMOUSE?

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
Julian
Posts: 11
Joined: Thu Dec 18, 2008 5:20 am

HOW TO BUILD STATIC LIB FOR SPACEMOUSE?

Post by Julian »

now i am trying to build a static library for spacemouse so that i can simply use it when my application need to connect spacemouse and get data from it. I have two kind of input data A & B, here A means the data getting from spacemouse. if the system detect A is available, application will use A, otherwise it will use data B. I defined a Class named SpaceMouseController, within which I can startup spacemouse and also get data& update state etc.

I am using the old sdk for my spacemouse classic serial, the sdk code was written by C. I built the static lib using the basic code of 3DxTest32(.c), but it can not be linked by my testing application(.cpp). Does anyone have the C++ version(.cpp) for old sdk? I dont know how to solve this problem, please help! THANK YOU in advance!
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

You can call C from C++ or you can change the code to C++. To call
C from C++, enclose the declarations in an extern "C" {...} section.
Julian
Posts: 11
Joined: Thu Dec 18, 2008 5:20 am

Post by Julian »

jwick wrote:You can call C from C++ or you can change the code to C++. To call
C from C++, enclose the declarations in an extern "C" {...} section.
Hey jwick, thank you for the reply. I'v tried the extern "C", i can build the lib. but when i link it to my test.cpp, some link errors showed up, "error LNK2019:Unresolved External Symbol..." blablabla. i am sorry i really don't know how to change the code to C++.

can you provide a basic C++ code for old sdk? what i need is only to initialize the spacemouse, connect to and get data from it.
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

You are probably getting link errors because you are mangling the names in one place and not in another.

I don't know what code you are using. What are some of the names of the functions?

To change to C++, change the extension to .cpp, compile, and correct any compiler errors <G>.
Julian
Posts: 11
Joined: Thu Dec 18, 2008 5:20 am

Post by Julian »

jwick wrote:You are probably getting link errors because you are mangling the names in one place and not in another.

I don't know what code you are using. What are some of the names of the functions?

To change to C++, change the extension to .cpp, compile, and correct any compiler errors <G>.
I change the name of 3DxTest32.c into 3DxTest32.cpp, by using this code, I built the dSpaceMouseController.lib. In my test.cpp code, i link this lib file and got this link error:

dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiTerminate, referenced in function "int __cdecl SbInit(void)" (?SbInit@@YAHXZ)

dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiOpen, referenced in function "int __cdecl SbInit(void)" (?SbInit@@YAHXZ)
dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiSetUiMode, referenced in function "int __cdecl SbInit(void)" (?SbInit@@YAHXZ)
dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiOpenWinInit, referenced in function "int __cdecl SbInit(void)" (?SbInit@@YAHXZ)
dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiInitialize, referenced in function "int __cdecl SbInit(void)" (?SbInit@@YAHXZ)
dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiButtonReleased, referenced in function "int __cdecl DispatchLoopNT(void)" (?DispatchLoopNT@@YAHXZ) dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiButtonPressed, referenced in function "int __cdecl DispatchLoopNT(void)" (?DispatchLoopNT@@YAHXZ)
dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiGetEvent, referenced in function "int __cdecl DispatchLoopNT(void)" (?DispatchLoopNT@@YAHXZ)
dSpaceMouseController.lib(3DxTest32.obj) : error LNK2019: unresolved external symbol _SiGetEventWinInit, referenced in function "int __cdecl DispatchLoopNT(void)" (?DispatchLoopNT@@YAHXZ)
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

Are you linking to the siapp.lib library from the SDK?
Julian
Posts: 11
Joined: Thu Dec 18, 2008 5:20 am

Post by Julian »

jwick wrote:Are you linking to the siapp.lib library from the SDK?
oops, i forgot it. now it compiled! :)
thank you jwick!!!
Julian
Posts: 11
Joined: Thu Dec 18, 2008 5:20 am

Why can not hWndMain & devHdl get value?

Post by Julian »

SOrry jwick, I have got a new problem.
My test code can not initialize spaceball and connect to it. By debugging the code, i found that my hWndMain and devHdl was always 0x00000000 and didnt change ever. I also debugged demo code 3DxTest32, and found the value of hWndMain changed after execution of " ShowWindow ( hWndMain, SW_SHOW );" and devHdl could also get value after execution of "devHdl = SiOpen ("3DxTest32", SI_ANY_DEVICE, SI_NO_MASK,
SI_EVENT, &oData);".

This is my code. could you help me out?

int
SbInit()
{

int res; /* result of SiOpen, to be returned */
SiOpenData oData; /* OS Independent data to open ball */

WNDCLASS wndclass; /* our own instance of the window class */
HINSTANCE hInst; /* handle to our instance */

hInst = NULL; /* init handle */



/*init the SpaceWare input library */
if (SiInitialize() == SPW_DLL_LOAD_ERROR)
{
MessageBoxA(NULL,"Error: Could not load SiAppDll dll files",
NULL, MB_ICONEXCLAMATION);
}


/* Register display window class */
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = (WNDPROC)HandleNTEvent ;
wndclass.cbClsExtra = 8 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInst;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = LPCWSTR("3DxTest32");


if (RegisterClass(&wndclass) == 0)
{
MessageBoxA(NULL,"Error:SpaceMouse Could not register windowclass.",
NULL, MB_ICONEXCLAMATION);
}

/* create the window */
hWndMain = CreateWindowA( "3DxTest32", /*Window class name*/
NULL, /*Window caption*/
WS_OVERLAPPEDWINDOW, /*Window Style*/
0,0,215,280,
NULL, /*parent window handle*/
NULL, /*window menu handle*/
hInst, /*program instance handle*/
NULL); /*creation parameters*/

/* display the window */
ShowWindow ( hWndMain, SW_SHOW );

if (hWndMain == NULL)
{
MessageBoxA(NULL,"Error: SpaceMouse Could not create message-only window.",
NULL, MB_ICONEXCLAMATION);
}


SiOpenWinInit (&oData, hWndMain); /* init Win. platform specific data */
SiSetUiMode(devHdl, SI_UI_ALL_CONTROLS); /* Config SoftButton Win Display */

/* open data, which will check for device type and return the device handle
to be used by this function */
if ( (devHdl = SiOpen ("3DxTest32", SI_ANY_DEVICE, SI_NO_MASK,
SI_EVENT, &oData)) == SI_NO_HANDLE)
{
SiTerminate(); /* called to shut down the SpaceWare input library */
res = 0; /* could not open device */
return res;
}
else
{
res = 1; /* opened device succesfully */
return res;
}
}
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

If your hWndMain is NULL, your CreateWindow isn't working. A NULL hWnd will cause your SiOpen to fail.
Julian
Posts: 11
Joined: Thu Dec 18, 2008 5:20 am

Post by Julian »

jwick wrote:If your hWndMain is NULL, your CreateWindow isn't working. A NULL hWnd will cause your SiOpen to fail.
Jwick, thank you for the reply! I compared my code with the demo code and found that my code was compiled with Unicode. So I just changed it to default and made it compiled again, then my test code works! The reason is that CreateWindow has different meanings under different coding settings. I hope this feedback will help those who may have the same question. Thanks again, jwick. All the best!

Julian
Post Reply