public NativeModule(String filename)
        {
            UInt32 flags = 0;

            if (System.IO.Path.IsPathRooted(filename))
            {
                flags = 0x00000008;
            }

            m_Module = LoadLibraryEx(filename, IntPtr.Zero, flags);
            if (m_Module == IntPtr.Zero)
            {
                throw new Exception("Unable to load " + filename);
            }

            IntPtr fptr = GetProcAddress(m_Module, "PluginInit");

            m_PluginInitFunc = Marshal.GetDelegateForFunctionPointer(fptr, typeof(NativeModule_PluginInitFunc)) as NativeModule_PluginInitFunc;

            fptr = GetProcAddress(m_Module, "ClassCount");
            m_ModuleCountFunc = Marshal.GetDelegateForFunctionPointer(fptr, typeof(NativeModule_ModuleCountFunc)) as NativeModule_ModuleCountFunc;

            fptr             = GetProcAddress(m_Module, "ClassInfo");
            m_ModuleInfoFunc = Marshal.GetDelegateForFunctionPointer(fptr, typeof(NativeModule_ModuleInfoFunc)) as NativeModule_ModuleInfoFunc;

            if (m_ModuleInfoFunc == null || m_ModuleCountFunc == null || m_ModuleInfoFunc == null)
            {
                throw new Exception("Not a native Voodoo module.");
            }

            IntPtr versionptr = m_PluginInitFunc();

            m_Version = (VersionInfo)Marshal.PtrToStructure(versionptr, typeof(VersionInfo));

            m_Count = m_ModuleCountFunc();

            m_Classes = new Dictionary <UInt32, ClassInfo>();

            for (UInt32 i = 0; i < m_Count; ++i)
            {
                Guid   tClassID = Guid.Empty;
                IntPtr nameptr  = m_ModuleInfoFunc(i, out tClassID);
                if (nameptr != null)
                {
                    String tname = Marshal.PtrToStringUni(nameptr);
                    m_Classes.Add(i, new ClassInfo(tClassID, tname));
                }
            }
        }
Exemple #2
0
        public NativeModule(String filename)
        {
            UInt32 flags = 0;
            if (System.IO.Path.IsPathRooted(filename))
            {
                flags = 0x00000008;
            }

            m_Module = LoadLibraryEx(filename, IntPtr.Zero, flags);
            if (m_Module == IntPtr.Zero)
            {
                throw new Exception("Unable to load " + filename);
            }

            IntPtr fptr = GetProcAddress(m_Module, "PluginInit");
            m_PluginInitFunc = Marshal.GetDelegateForFunctionPointer(fptr, typeof(NativeModule_PluginInitFunc)) as NativeModule_PluginInitFunc;

            fptr = GetProcAddress(m_Module, "ClassCount");
            m_ModuleCountFunc = Marshal.GetDelegateForFunctionPointer(fptr, typeof(NativeModule_ModuleCountFunc)) as NativeModule_ModuleCountFunc;

            fptr = GetProcAddress(m_Module, "ClassInfo");
            m_ModuleInfoFunc = Marshal.GetDelegateForFunctionPointer(fptr, typeof(NativeModule_ModuleInfoFunc)) as NativeModule_ModuleInfoFunc;

            if (m_ModuleInfoFunc == null || m_ModuleCountFunc == null || m_ModuleInfoFunc == null)
            {
                throw new Exception("Not a native Voodoo module.");
            }

            IntPtr versionptr = m_PluginInitFunc();
            m_Version = (VersionInfo)Marshal.PtrToStructure(versionptr, typeof(VersionInfo));

            m_Count = m_ModuleCountFunc();

            m_Classes = new Dictionary<UInt32, ClassInfo>();

            for (UInt32 i = 0; i < m_Count; ++i)
            {
                Guid tClassID = Guid.Empty;
                IntPtr nameptr = m_ModuleInfoFunc(i, out tClassID);
                if (nameptr != null)
                {
                    String tname = Marshal.PtrToStringUni(nameptr);
                    m_Classes.Add(i, new ClassInfo(tClassID, tname));
                }
            }
        }