.net 为什么安装Office 2013会在使用MAPI后破坏WinForms RichTextBox?
我有三个节目- 程序1:附加使用MAPI的Microsoft Outlook加载项 程序2:不使用MAPI的独立exe 程序3:使用MAPI的独立exe 这三个程序都是用C#编写的,并在某些时候使用WinForms RichTextBox 在安装了Office 365的x64 Windows 8上,程序“1”和“3”没有问题,但一旦使用以下堆栈构造RichTextBox控件,程序“2”就会崩溃:.net 为什么安装Office 2013会在使用MAPI后破坏WinForms RichTextBox?,.net,pinvoke,richtextbox,mapi,loadlibrary,.net,Pinvoke,Richtextbox,Mapi,Loadlibrary,我有三个节目- 程序1:附加使用MAPI的Microsoft Outlook加载项 程序2:不使用MAPI的独立exe 程序3:使用MAPI的独立exe 这三个程序都是用C#编写的,并在某些时候使用WinForms RichTextBox 在安装了Office 365的x64 Windows 8上,程序“1”和“3”没有问题,但一旦使用以下堆栈构造RichTextBox控件,程序“2”就会崩溃: System.IO.FileNotFoundException : C:\Program Files
System.IO.FileNotFoundException : C:\Program Files (x86)\Common Files\Microsoft Shared\Office15\riched20.dll
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at System.Windows.Forms.RichTextBox.get_CreateParams()
at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
at System.Windows.Forms.TextBoxBase..ctor()
at System.Windows.Forms.RichTextBox..ctor()
<snip>
System.IO.FileNotFoundException:C:\Program Files(x86)\Common Files\Microsoft Shared\Office15\riched20.dll
位于System.Diagnostics.FileVersionInfo.GetVersionInfo(字符串文件名)
在System.Windows.Forms.RichTextBox.get_CreateParams()中
位于System.Windows.Forms.Control..ctor(布尔值autoInstallSyncContext)
在System.Windows.Forms.TextBoxBase..ctor()中
在System.Windows.Forms.RichTextBox..ctor()中
反汇编RichTextBox.get_CreateParams()会显示它在“riched20.dll”上调用LoadLibrary,然后在加载的模块上调用GetModuleFileName
对于程序2,Visual Studio告诉我它已从路径“C:\Program Files\Microsoft Office 15\root\vfs\ProgramFilesCommonX86\Microsoft Shared\OFFICE15\riched20.dll”加载riched20.dll
然后调用FileVersionInfo.GetVersionInfo()失败,因为给定的路径不存在
然而,程序1(outlook加载项)也从同一路径加载了riched20.dll,但不知怎的成功了
不加载MAPI的程序2工作正常,它从C:\Windows\syswow62加载riched20.dll
程序3在创建富文本框之前初始化MAPI,我知道某些MAPI函数会将当前工作目录更改为MAPI目录。这可能解释了为什么程序3加载office的riched20.dll,而程序2加载system32副本
我怀疑程序1运行与程序3失败之间的区别在于路径中的vfs代表“虚拟文件系统”,因此作为Outlook加载项运行的程序1可以使用实际不存在的路径以某种方式找到riched20.dll
所有这三个程序都与以前版本的office配合使用
作为一种解决方法,在初始化MAPI之前自己调用“LoadLibrary”(“riched20.dll”)可以解决问题,但感觉像是一种可怕的黑客行为
我也找不到关于这个“vfs”文件路径的任何信息以及它在互联网上的含义
就我个人而言,有人能更好地解释这里发生了什么吗
更新:我已经确定这与“点击运行”功能有关。解决方案是在初始化MAPI之前使用pinvoke调用“riched20.dll”上的LoadLibrary
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr LoadLibrary(string lpFileName);
LoadLibrary("riched20");
是,路径对应于单击以运行Outlook 2013安装。您能否提前加载正确的dll以确保在加载和初始化MAPI时加载它?是的,我可以。。。(迟做总比不做强!)您是否曾经遇到过此解决方案的问题,或者它是否运行稳定?