【发布时间】:2011-08-12 11:25:35
【问题描述】:
Delphi写的dll,按照手册我要先用SET_XML()设置xml路径,然后用你喜欢的任何函数。
Delphi 功能根据手册:
function SET_XML(var path: PAnsiChar): LongInt;
function GET_CALCULATION_FAN_ALONE(var fanDescription: PAnsiChar): LongInt;
根据手册在VB中使用:
Public Declare Function SET_XML_PATH Lib "fan.dll" (ByRef path As String) As Long
Public Declare Function GET_CALCULATION_FAN_ALONE Lib "fan.dll" (ByRef path As String) As Long
Sub Main()
Dim a As Long, b As Long, Str_Result As String, Str_Input As String
Str_Input = "C:\Users\Sebastiaan\Documents\Visual Studio 2010\Projects\Lucam selectie\Lucam selectie\bin"
a = SET_XML_PATH(Str_Input)
Str_Result = "65464;;;1,2;;23;424,8;0,3766;;"
b = GET_CALCULATION_FAN_ALONE(Str_Result)
End Sub
我确实用 C# 重写了它
const string _dllLocation = "EbmPapstFan.dll";
[DllImport(_dllLocation)]
public static extern long SET_XML_PATH(ref String path);
[DllImport(_dllLocation)]
public static extern long GET_CALCULATION_FAN_ALONE(ref String fanDescription);
public Main()
{
String path = @"C:\Users\Sebastiaan\Documents\Visual Studio 2010\Projects\Lucam selectie\Lucam selectie\bin";
long a = SET_XML_PATH(ref path);
String fanDescription = "65464;;;1,2;;23;424,8;0,3766;;";
long c = GET_CALCULATION_FAN_ALONE(ref fanDescription);
}
运行 de 应用程序时,我得到一个 AccessViolationException
尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
设置断点并逐步调试代码时,一切正常。有时我在调试模式下遇到错误(在线“long c = GET_CALU ...”)
我做错了什么?
【问题讨论】:
-
我不确定,但是当我看到这个错误时,我总是在想 System.Diagnostics.Process.EnterDebugMode();