locked
Unit3D中使用SDK DLL的问题 RRS feed

  • 问题

  • 想要在unity3D中使用SDK的dll,借鉴CMU的Wrapper包,修改其中的sensor初始化方式,采用NuiCreateSensorByIndex进行Sensor的初始化,如下所示,但是nuiStatus返回错误,为0x80070015,求指正,谢谢:

    在NativeMethords中加入以下调用:

    //INuiSensor **ppNuiSensor
    [DllImportAttribute(@"C:\Windows\System32\Kinect10.dll", EntryPoint = "NuiCreateSensorByIndex")]
    public static extern uint NuiCreateSensorByIndex(int index,ref IntPtr ppNuiSensor);

    [DllImportAttribute(@"C:\Windows\System32\Kinect10.dll", EntryPoint = "NuiGetSensorCount")]
    public static extern int NuiGetSensorCount(ref int pCount);

    初始化:
    int iSensorCount = 0;
    hr = NativeMethods.NuiGetSensorCount(ref iSensorCount);
    if(iSensorCount == 0)
    {
    Debug.Log("Warning:: There is no Sensor!");
    return;
    }

    Debug.Log("Info::iSensorCount = " + iSensorCount);
    if(hr != 0)
    {
    Debug.Log("Warning::Get SensorCount Fail!");
    return;
    }

    INuiSensor nuiSensor;

    uint kr =0;
    kr = NativeMethods.NuiCreateSensorByIndex(0, ref pNuiSensor);
    if(kr != 0)
    {
    Debug.Log("Warning::NuiCreateSensorByIndex Fail!");
    return;
    }
    nuiSensor  = (INuiSensor)Marshal.GetObjectForIUnknown(pNuiSensor);
    uint ret = nuiSensor.NuiStatus();
    if(ret != 0)
    {
    Debug.Log("Warnging:: the status of pNuiSensor is not right!!!! status = " + nuiSensor.NuiStatus());
    return;
    }

    接口定义:

    [Guid("d3d9ab7b-31ba-44ca-8cc0-d42525bbea43")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [ComImport()]
    public interface INuiSensor
    {
    [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
    [PreserveSig]
    uint NuiStatus();

    。。。。。。
    }

    2013年9月10日 1:46