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. Source=Interop.emscosting StackTrace: 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'
I am already using this COM object without any issues from other VFP applications, Office applications, and in Javascript/Classic ASP.
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!
#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
......
NOTE: Both the two test functions defined above fail with the exception System.AccessViolationException