示例#1
0
        /// <summary>
        /// 装载动态链接库。
        /// </summary>
        /// <param name="dllName">装载动态链接库的文件名称。</param>
        public virtual void Load(string dllName)
        {
            if (IsLoaded)
            {
                throw new InvalidOperationException("Libaray already loaded.");
            }

            IntPtr dllHandle = WIN32_API.LoadLibrary(dllName);

            if (dllHandle == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            try
            {
                GetAllProcAddress(dllHandle);
            }
            catch (Exception)
            {
                WIN32_API.FreeLibrary(dllHandle);
                throw;
            }

            m_dllName   = dllName;
            m_dllHandle = dllHandle;
        }
示例#2
0
 /// <summary>
 /// 释放由DllLoader占用的资源。
 /// </summary>
 /// <param name="disposing">资源释放标志,为True释放所有资源;为False则仅释放非受控资源。</param>
 protected virtual void Dispose(bool disposing)
 {
     if (m_dllHandle != IntPtr.Zero)
     {
         WIN32_API.FreeLibrary(m_dllHandle);
         m_dllHandle = IntPtr.Zero;
     }
 }