0

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

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

但是,当我尝试从 COM 对象调用任何方法或访问任何属性时,会抛出以下异常:

System.AccessViolationException 未处理 Message=尝试读取或写入受保护的内存。这通常表明其他内存已损坏。Source=Interop.emscosting StackTrace:在 emscosting.ComBaseClass.ShellExecute(String tcItem, String tcAction) ...

下面是我正在使用的一些示例 C# 代码:

emscosting.ComBaseClass com = new emscosting.ComBaseClass(); com.ShellExecute(文件,“真”);<--- 这里抛出异常

此外,当我尝试在调试器监视窗口中访问 COM 对象的任何公共属性时,值列中出现以下内容:“com.DatabaseUserName”引发了“System.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

4

1 回答 1

0

如果您有 x64 系统,则必须为 x86 编译您的 .Net 应用程序。当您使用“Any CPU”或“x64”编译它时,您无法访问 x32 FoxPro-DLL。

于 2013-06-18T06:43:04.120 回答