系统.访问用visualfoxpro编写的COM DLL时出现AccessViolationException错误

本文关键字:DLL 错误 AccessViolationException COM 访问 visualfoxpro 系统 | 更新日期: 2023-09-27 18:18:07

我有一个c# WinForms . net 3.5应用程序,我需要调用一个用Visual FoxPro 7编写的COM DLL。我已经将COM对象添加到c#项目中,并且可以

在对象浏览器中查看对象及其成员

然而,当我试图调用任何方法或从COM对象访问任何属性时,我得到以下异常抛出:

系统。未处理AccessViolationException消息=试图读写受保护的内存。这通常表明其他内存已损坏。源= Interop.emscosting加:在emscosting.ComBaseClass。ShellExecute(字符串tcItem,字符串tcAction)…

下面是我使用的一些c#代码示例:

emscosting。ComBaseClass com = new emscosting.ComBaseClass();com。ShellExecute(文件,"真正的");<——这里抛出异常

另外,当我尝试访问调试器监视窗口中的COM对象的任何公共属性时,我得到以下内容出现在值列中:com。数据库用户名抛出了类型为"系统"的异常。AccessViolationException '

我已经在使用这个COM对象,没有任何来自其他VFP应用程序,Office应用程序和Javascript/Classic ASP的问题。

有人能帮我解决这个问题吗?

我仍然有COM的原始VFP源代码,下面是我声明公共属性的代码片段,但是我试图

尽量避免重写COM DLL !

#If BUILD_AS_COM_OBJECT
Define Class emsCosting As Combase OlePublic
#Else
Define Class emsCosting As Combase
#Endif
CostingsPath = COSTINGS_PATH
Dimension CostingsPath_COMATTRIB[5]
CostingsPath_COMATTRIB[1] = COMATTRIB_NONE
CostingsPath_COMATTRIB[2] = "Contains the path of where the costings get saved" && HelpString
CostingsPath_COMATTRIB[3] = "CostingsPath" && Capitalisation
CostingsPath_COMATTRIB[4] = "String" && Property Type
CostingsPath_COMATTRIB[5] = 0 && Number of parameters
CostingsMaster = COSTINGS_MASTER
Dimension CostingsMaster_COMATTRIB[5]
CostingsMaster_COMATTRIB[1] = COMATTRIB_NONE
CostingsMaster_COMATTRIB[2] = "Contains the filename of the costings master (usually costings.xls)" && HelpString
CostingsMaster_COMATTRIB[3] = "CostingsMaster" && Capitalisation
CostingsMaster_COMATTRIB[4] = "String" && Property Type
CostingsMaster_COMATTRIB[5] = 0 && Number of parameters
Function SetCostingsPath(tcPath As String) As VOID HelpString "This is a test function"
    CostingsPath = tcPath
EndFunc
Function TestFunctionNoParam() AS String HelpString "This is a helpstring"
    Return "''TEST'ContractReviewCostings'"
EndFunc

……

注意:上面定义的两个测试函数都因System异常而失败。AccessViolationException

系统.访问用visualfoxpro编写的COM DLL时出现AccessViolationException错误

如果您使用的是x64系统,则必须为x86编译。net应用程序。当你用"任意CPU"或"x64"编译它时,你不能访问x32的FoxPro-DLL。