最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to get the name of IChannelControl from IntPtr? - Stack Overflow

programmeradmin0浏览0评论

I have registered a callback to get errors that looks like this and I am trying to get the name of the callbackInfo.instance to debug it but callbackInfo.instancetype is a ERRORCALLBACK_INSTANCETYPE.CHANNELCONTROL and reading the docs it corresponds to an IChannelControl interface which can be either a Channel or a ChannelGroup and I cant figure out a way to determine which one it actually is and if I chose wrong all I get is garbage.

var errorCallback = new FMOD.SYSTEM_CALLBACK(ERROR_CALLBACK);
system.setCallback(errorCallback, FMOD.SYSTEM_CALLBACK_TYPE.ERROR);

private static FMOD.RESULT ERROR_CALLBACK(IntPtr system, FMOD.SYSTEM_CALLBACK_TYPE type, IntPtr commanddata1, IntPtr commanddata2, IntPtr userdata)
{
    FMOD.ERRORCALLBACK_INFO callbackInfo = Marshal.PtrToStructure<FMOD.ERRORCALLBACK_INFO>(commanddata1);

    if(callbackInfo.instancetype == ERRORCALLBACK_INSTANCETYPE.CHANNELGROUP)
    {
        // get the name or other identifier of the callbackInfo.instance
    }
}

So I either need a way to determine which type it is or a way to get the name without knowing the type.

Edit 1: To clarify, both Channel and ChannelGroup have constructors that take an IntPtr, thats the only way i have found to actually create those objects. Marshalling like is done above for the ERRORCALLBACK_INFO does not work since the structs dont have any actual data and is just a wrapper for a c++ object.

发布评论

评论列表(0)

  1. 暂无评论