我在代码中使用 .net Primary Interoperability Assembly for Excel。
但是,该应用程序可以在未安装 .net PIA for Excel 的计算机上运行。
我想如果没有安装就给出错误信息
即使我正在检查 GAC,以查看 PIA 是否已安装,并且仅当它存在时,我才使用 Microsoft.Office.Interop.Excel 相关代码。我收到错误。
我的问题是 - 我收到错误 - 未处理的异常 - 找不到无法加载文件或程序集 Microsoft.Office.Interop.Excel
有什么解决办法吗?
提前致谢!
我已使用此构建块在 5 月 NHunspell 包装器中加载 hunspell 的 x86 / x64 版本。也许这是您自己的动态加载器的一个很好的起点:
// Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively
SYSTEM_INFO info = new SYSTEM_INFO();
GetSystemInfo( ref info );
// Load the correct DLL according to the processor architecture
switch( info.wProcessorArchitecture )
{
case PROCESSOR_ARCHITECTURE.Intel:
string pathx86 = AppDomain.CurrentDomain.BaseDirectory;
if (!pathx86.EndsWith("\\"))
pathx86 += "\\";
pathx86 += Resources.HunspellX86DllName;
dllHandle = LoadLibrary(pathx86);
if (dllHandle == IntPtr.Zero)
throw new DllNotFoundException(string.Format(Resources.HunspellX86DllNotFoundMessage, pathx86));
break;
case PROCESSOR_ARCHITECTURE.Amd64:
string pathx64 = AppDomain.CurrentDomain.BaseDirectory;
if (!pathx64.EndsWith("\\"))
pathx64 += "\\";
pathx64 += Resources.HunspellX64DllName;
dllHandle = LoadLibrary(pathx64);
if (dllHandle == IntPtr.Zero)
throw new DllNotFoundException(string.Format(Resources.HunspellX64DllNotFoundMessage, pathx64));
break;
看看这个委托声明:
internal delegate bool HunspellSpellDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word);
以及如何将库函数绑定到它
HunspellSpell = (HunspellSpellDelegate)GetDelegate("HunspellSpell", typeof(HunspellSpellDelegate));
我认为这也应该适合您,但您必须声明完整的互操作代码。您可以查看 Nhunspell 代码来获取该技术的工作示例:
NHunspell 网站 http://nhunspell.sourceforge.net
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)