Hi -
I am a novice programmer although I have successfully implemented a few dll plugins with Unity. However, this one is revealing some issues I don’t know how to deal with - which I think is specific to C++ conventions vs C#.
I am trying to use a dll for the 5DT data glove. “fglove.dll” can be downloaded from the 5DT website and I have successfully used in some other c++ applications. The function reference is available as a PDF (http://www.5dt.com/downloads/dataglove/old/5DTDataGloveDriverManual.pdf) Examples, including the first one that opens the glove device in which I can’t figure out, are like this:
fdGlove *fdOpen(char *pPort)
Initializes the glove device on the specified port.
Return value
Returns a pointer to the glove device (fdGlove *). NULL is returned if an error occurred.
Remarks
Do not attempt to alter the contents of the returned pointer directly, use the functions provided
instead.
So it returns data in the pointer, and this is what I don’t know how to deal with in the C# script in Unity.
public class fGloveUnity : MonoBehaviour {
[DllImport ("fglove")]
private static extern fdGlove *fdOpen(char pPort) ;
That of course results in an error, “the type or namespace ‘fdGlove’ cannot be found”.
So I was guessing I need to create a structure for it, based on looking at other examples including the midiplugin example on the unity site.
The fglove.h file included with the dll shows this:
typedef struct
{
// The contents of this struct are platform-dependent and subject to
// change. You should not manipulate the contents of this struct directly.
void *m_pStuff;
} fdGlove;
So if I try something like:
public struct fdGlove
{
void *m_pStuff;
}
I get the error “Pointers and fixed size buffers may only be used in an unsafe context”.
So that is where I am stuck. I’ve seen other threads that talk about setting the unity preferences to allow unsafe, and also Marshaling which I know nothing about, and don’t know that either of those are a step towards solving how the data returned from the device can be accessed.
If anyone can start me in the right direction for this I would appreciate it very much.
thanks