private IntPtr LoadDll(string archiveFile) { //DLLの存在を確認 IntPtr pathPtr; if (UnlhaAPI.SearchPath(null, dllName, null, 0, null, out pathPtr) == 0) { throw new ApplicationException("unlha32.dllが見つかりません。"); } //DLLをロード IntPtr hmod = UnlhaAPI.LoadLibrary(dllName); if (hmod == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } try { IntPtr funcAddr; //DLLのチェック funcAddr = UnlhaAPI.GetProcAddress(hmod, "UnlhaGetVersion"); if (funcAddr == IntPtr.Zero) { throw new ApplicationException("unlha32.dllがインストールされていません。"); } UnlhaAPI.GetVersionDelegate getVersion = (UnlhaAPI.GetVersionDelegate)Marshal.GetDelegateForFunctionPointer( funcAddr, typeof(UnlhaAPI.GetVersionDelegate)); ushort ver = getVersion(); if (ver < 300) { throw new ApplicationException(string.Format("unlha32.dllはバージョン3.00を要求。Ver{0:0.00}", ver / 100f)); } //動作中かチェック funcAddr = UnlhaAPI.GetProcAddress(hmod, "UnlhaGetRunning"); if (funcAddr != IntPtr.Zero) { UnlhaAPI.GetRunningDelegate getRunning = (UnlhaAPI.GetRunningDelegate)Marshal.GetDelegateForFunctionPointer( funcAddr, typeof(UnlhaAPI.GetRunningDelegate)); if (getRunning()) { throw new ApplicationException("unlha32.dllが現在動作中です。"); } } //展開できるかチェック funcAddr = UnlhaAPI.GetProcAddress(hmod, "UnlhaCheckArchive"); if (funcAddr == IntPtr.Zero) { throw new ApplicationException("UnlhaCheckArchiveのアドレスを取得できませんでした。"); } UnlhaAPI.CheckArchiveDelegate checkArchive = (UnlhaAPI.CheckArchiveDelegate)Marshal.GetDelegateForFunctionPointer( funcAddr, typeof(UnlhaAPI.CheckArchiveDelegate)); if (!checkArchive(archiveFile, 0)) { throw new ApplicationException("unlha32.dllでは展開できません。"); } } catch { //開放する UnlhaAPI.FreeLibrary(hmod); throw; } return(hmod); }