WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 01-12-2006, 09:41 PM
Vygreif Vygreif is offline
Join Date: Sep 2005
Posts: 21
Extending Python With C++

I'm trying to make a new dll for Python using C++ and am having a lot of trouble with it.
Firstly, I've tried looking at Guido's guide to extending dll s, but I can't find the file example_nt he speaks of in 4.1 (Guido's guide is the one used in your help menu).

Here is the actual code:

// include guards?
#include <Python.h>
#include "stdafx.h"
#include "ImmDevice3.h"
#include "impulse.h"

using namespace std;

// device is set up at inithdjoy()
static ImmDevice3* device;

DWORD ul_reason_for_call,
LPVOID lpReserved)
return TRUE;

static PyObject* py_getPosition(PyObject *self)
ImmCoord3 pos;

return Py_BuildValue("[dd]", pos.x, pos.y);

//Set the force on the Impulse Engine
PyObject* py_setForce(PyObject *self, PyObject *args)
ImmCoord3 force;

//we don't have any force in the z direction
force.z = 0;
//Get two double arguments
if( !PyArg_ParseTuple(args, "dd", &force.x, &force.y) )
return NULL;
// What previous person did
//What I think should be done

return Py_None;

//This function will take an integer and return a list of numbers starting from 0 to that number
PyObject* py_calibrate(PyObject *self)

return Py_None;

//This will declare the functions that are available within python
//The first value is the name of the function within python.
//The second value is the name of the function within this file.
static PyMethodDef HDJoyMethods[] = {
{"getPosition", py_getPosition, METH_NOARGS},
{"setForce", py_setForce, METH_VARARGS},
{"calibrate", py_calibrate, METH_NOARGS},

//Initialize the hdjoy module
extern "C" __declspec(dllexport) void inithdjoy()
device = ImmDevice3Factory::AcquireImpulse( kImm_IE_DEVICE_N, DEVICE_IE2000 );
Py_InitModule("hdjoy", HDJoyMethods);

It gets the following errors before the compiler gives up:
std: a namespace with this name does not exist.

d:\Projects - current\hdjoy\hdjoy\hdjoy.cpp(20): error C2065: 'self' : undeclared identifier
d:\Projects - current\hdjoy\hdjoy\hdjoy.cpp(20): error C2143: syntax error : missing ';' before '*'
d:\Projects - current\hdjoy\hdjoy\hdjoy.cpp(20): error C2501: 'py_getPosition' : missing storage-class or type specifiers

If I move the #include <Python.h>
I get this error instead, as well as the std error
d:\Projects - current\hdjoy\hdjoy\hdjoy.cpp(63): error C2440: 'initializing' : cannot convert from 'PyObject *(__cdecl *)(PyObject *)' to 'PyCFunction'
None of the functions with this name in scope match the target type

Sorry that I can't be more specific about my problem. It might very well be that I don't know how to properly include the libraries. In the header files directory I put in ImmDevice3.h, impulse.h, and stdafx.h. in the Header Files folder.

Reply With Quote
Old 01-17-2006, 08:06 PM
vmonkey vmonkey is offline
Join Date: Sep 2004
Posts: 9
Never mind, I got it
Reply With Quote
Old 01-18-2006, 09:21 AM
tobin tobin is offline
WorldViz Team Member
Join Date: Feb 2003
Posts: 251
Sorry we didn't get back to you and thanks very much for letting us know you solved it.
Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 10:16 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC