本帖最后由 CSDNMicrosoftCSDN 于 2014-05-08 12:30:10 编辑

解决方案 »

  1.   

    Access Violation可能相关:
    1. stdcall cdecl fastcall等函数调用约定不匹配。
    2. dllimport转换时,C#和C++对应的类型不匹配
    实在不行把api贴出来看看
      

  2.   


    #ifndef UNITYINTERFACE_API
    #define UNITYINTERFACE_API extern "C" __declspec(dllexport)
    #endif//DEFINE INTERFACE METHODS//Nui Context Management
    UNITYINTERFACE_API bool NuiContextInit(bool twoPlayer);
    UNITYINTERFACE_API void NuiUpdate();
    UNITYINTERFACE_API void NuiContextUnInit();
    //Get Methods
    UNITYINTERFACE_API void GetSkeletonTransform(int player, int joint, OUT KUVector4* SkeletonTransform);
    UNITYINTERFACE_API byte* GetTextureImage(OUT int* size);
    UNITYINTERFACE_API byte* GetDepthImage(OUT int* size);
    UNITYINTERFACE_API void GetCameraAngle(OUT float* angle);
    //Set Methods
    UNITYINTERFACE_API bool SetCameraAngle(int angle);还需要cpp文件吗?
      

  3.   


    C#脚本
    //NUI Context Management
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern bool NuiContextInit(bool twoPlayer);
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern void NuiUpdate();
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern void NuiContextUnInit();
    //Get Methods
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern void GetSkeletonTransform(int player, int joint, ref SkeletonTransform trans);
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern IntPtr GetTextureImage(ref int size);
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern IntPtr GetDepthImage(ref int size);
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern void GetCameraAngle(ref float angle);
    //Set Methods
    [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")]
    public static extern bool SetCameraAngle(int angle);
      

  4.   

    是所有的函数调用都有问题,还是其中一部分?贴个以前做过的转换样例,可以参考下[DllImport("mydll", EntryPoint = "MyFunction", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
      

  5.   


    经测试判断是dll中所有函数都调用失败~
    但是在Unity3d中,Play运行没有问题,打包之后资源文件中也有dll,运行打包之后的exe,执行调用dll中方法的一些操作都无效了,这会是什么原因呢?
    Assets目录如下:MyModel,MyScript,Plugins,Scene。打包之后,资源自动会放到和生成的exe文件同目录下的ProjectName_Data目录,在这个目录下有Managed,Mono,Plugins(dll存在),Resources4个文件夹,mainData,PlayerConnectionConfigFile,sharedassets0.assets3个文件。
      

  6.   

    从log信息(0xc0000005)判断应该是Nui_Init函数初始化Kinect失败返回的HRESULT
      

  7.   

    C#可以和c联调的,项目属性-调试-启用非托管代码调试,可以跟一下,传进去的参数是否正确。
    还有那个init函数的参数,把bool改为int,再试试
      

  8.   

    经过各种测试表明应该是Nui_Init函数初始化Kinect失败返回的HRESULT  谢谢几位帮忙  结贴了