System.AccessViolationException exception when accessing COM DLL written in VFP
Posted on 2013-06-13
I have a C# WinForms .NET 3.5 application that I need to call a COM DLL written in Visual FoxPro 7. I have added the COM object to the C# project fine, and can
view the objects and its members in the object browser fine.
However when I attempt to call any methods or access any properties from the COM object I get the following exception thrown :
System.AccessViolationException was unhandled
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at emscosting.ComBaseClass.ShellExecute(String tcItem, String tcAction)
Below is some example C# code I am using :
emscosting.ComBaseClass com = new emscosting.ComBaseClass();
com.ShellExecute(file, "TRUE"); <--- The exception is thrown here
Also when I try and access any of the public properties of the COM object in the debugger watch window I get the following appear in the Value column :
'com.DatabaseUserName' threw an exception of type 'System.AccessViolationException'
Can someone help me resolve this issue please ?
I do have the original VFP source code for the COM still and below is a snippet of the code where I am declaring the public properties, however I am trying to
avoid rewriting the COM DLL if possible!
Define Class emsCosting As Combase OlePublic
Define Class emsCosting As Combase
CostingsPath = COSTINGS_PATH
CostingsPath_COMATTRIB = COMATTRIB_NONE
CostingsPath_COMATTRIB = "Contains the path of where the costings get saved" && HelpString
CostingsPath_COMATTRIB = "CostingsPath" && Capitalisation
CostingsPath_COMATTRIB = "String" && Property Type
CostingsPath_COMATTRIB = 0 && Number of parameters
CostingsMaster = COSTINGS_MASTER
CostingsMaster_COMATTRIB = COMATTRIB_NONE
CostingsMaster_COMATTRIB = "Contains the filename of the costings master (usually costings.xls)" && HelpString
CostingsMaster_COMATTRIB = "CostingsMaster" && Capitalisation
CostingsMaster_COMATTRIB = "String" && Property Type
CostingsMaster_COMATTRIB = 0 && Number of parameters
Function SetCostingsPath(tcPath As String) As VOID HelpString "This is a test function"
CostingsPath = tcPath
Function TestFunctionNoParam() AS String HelpString "This is a helpstring"
NOTE: Both the tow test functions defined above fail with the exception System.AccessViolationException