急!! 请教!!我用delphi调用vb做的dll,最后出现这样的错误:“project project.exe raised exception class eaviolation with message "access violation at address73474179 in module MSVBVM60.DLL" read of address 00000076.”
VB 中DLL的代码是:
Option ExplicitDim io_mgr As VisaComLib.ResourceManager ' to be used for the resource manager
Dim DMM As VisaComLib.FormattedIO488 ' to create a formatted I/O referenceDim connected As Boolean ' Sets flag to determine if instrument is connected or not
Sub RunProgram()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This sub sets the 3458A to a pre-defined state, makes measurements, and
' returns the measurements.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
If connected = False Then
If Not OpenPort Then
Exit Sub
End If
End If ' Setup the 3458A
Setup
' Call the sub that opens communication with instrument' Make measurements and return readings
'GetReadingsEnd SubSub Setup()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This sub performs the instrument setup.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim Cmds As String' Setup the 3458A
Cmds = "PRESET NORM;" ' Preset to the designated state (Normal)
Cmds = Cmds + "NRDGS 100,AUTO;" ' Set the number of readings pre trigger (4100 readings)
Cmds = Cmds + "TARM AUTO;" ' Setup the trigger
Cmds = Cmds + "TRIG HOLD;" ' Hold the trigge until triggered
Cmds = Cmds + "MEM FIFO;" ' Clear memory and set memory storage type
Cmds = Cmds + "MFORMAT DINT;" ' Set the memory storage format (double integer)
Cmds = Cmds + "OFORMAT ASCII;" ' Set the output format (ASCII)
Cmds = Cmds + "APER 1E-4;" ' Set the arperature time' Set for the real time processing, if selected
Cmds = Cmds + "MATH STAT"
' Execute the commands
DMM.WriteString Cmds' Check for errors
Check_Error "Setup"End SubFunction GetReadings() As Double'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This sub triggers the instrument and returns the readings from memory.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim rdcnt As Integer
Dim NumSamp As Integer
Dim StdDev As Double
Dim MeanVal As Double
Dim UpperVal As Double
Dim LowerVal As Double
SelectAddr_Click
RunProgram
' Trigger the 3458A
DMM.WriteString "TRIG SGL"' Set sufficient timeout to make all measurements
DMM.IO.Timeout = 8000 With DMM
' Get number of readings taken
.WriteString "RMATH NSAMP"
NumSamp = .ReadNumber ' Get the standard deviation
.WriteString "RMATH SDEV"
StdDev = .ReadNumber
' Get the mean (avearage) value
.WriteString "RMATH MEAN"
MeanVal = .ReadNumber ' Get the upper (maximum) value
.WriteString "RMATH UPPER"
UpperVal = .ReadNumber
' Get the lower (minimum) value
.WriteString "RMATH LOWER"
LowerVal = .ReadNumber
End With
' Set timeout to a default value
DMM.IO.Timeout = 2000
' Check for errors
'Check_Error "GetReadings"
GetReadings = StdDevEnd FunctionFunction OpenPort() As Boolean
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This function opens a port (the communication between the instrument and computer).
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim addr As String ' to be used for the instrument address
Dim retval As String' Exit if error occurs
' If port is open, close it
If connected Then
DMM.IO.Close
End If' Set the resource manager session
Set io_mgr = New AgilentRMLib.SRMCls' Create the VISA Com object
Set DMM = New VisaComLib.FormattedIO488' Get the instrument address form the text box
addr = UCase$("GPIB::13")
' Set the VISA Com resource session
Set DMM.IO = io_mgr.Open(addr, True, True, "")' Set timeout to 2 seconds
DMM.IO.Timeout = 2000' Set the termination character to carriage return (i.e., 13);
' the 3458A uses this character
DMM.IO.TerminationCharacter = 13' Set the flag to terminate when receiving a termination character
DMM.IO.TerminationCharacterEnabled = True' Query instrument ID string
With DMM
.WriteString "ID?"
retval = .ReadString
End With' Check if correct instrument is addressed
If InStr(retval, "3458A") = 0 Then
MsgBox "Wrong instrument addressed!"
' addrSelect.Text = "GPIB0::22"
' addrSelect.Refresh
connected = False
OpenPort = False ' Close the session
DMM.IO.Close Exit Function
End If' Reset the 3458A to it's power on state
DMM.WriteString "RESET"' Check for errors
Check_Error "OpenPort"connected = True
OpenPort = TrueExit Function
End FunctionSub ClosePort()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This club closes the communication with the instrument.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""If connected Then
' Close the port
DMM.IO.Close
End IfEnd SubSub Check_Error(msg As String)
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' Checks for syntax and other errors.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim ErrMsg As String * 80' Check for error
With DMM
.WriteString "ERRSTR?"
ErrMsg = .ReadString
End With' If error is found, show the error
End Sub
Private Sub SelectAddr_Click()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' Selects address and opens session
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""' Open port
If Not OpenPort Then
Exit Sub
Else
connected = True
End IfEnd Sub
我用DELPHI调用代码是:implementation
function GetReadings(StdDev:real):integer;stdcall;
external 'c:\aaa\ProjectOK.dll';{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var x:real;
begin
x:=GetReadings(StdDev);
edit1.text:= inttostr(StdDev);
//edit2.text:= inttostr(x);
//edit3.text:= inttostr(x);
//edit4.text:= inttostr(x);
end;
请教高手!!为什么每次调用DLL,点击delphi的button,就出现了前面提到的错误???
VB 中DLL的代码是:
Option ExplicitDim io_mgr As VisaComLib.ResourceManager ' to be used for the resource manager
Dim DMM As VisaComLib.FormattedIO488 ' to create a formatted I/O referenceDim connected As Boolean ' Sets flag to determine if instrument is connected or not
Sub RunProgram()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This sub sets the 3458A to a pre-defined state, makes measurements, and
' returns the measurements.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
If connected = False Then
If Not OpenPort Then
Exit Sub
End If
End If ' Setup the 3458A
Setup
' Call the sub that opens communication with instrument' Make measurements and return readings
'GetReadingsEnd SubSub Setup()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This sub performs the instrument setup.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim Cmds As String' Setup the 3458A
Cmds = "PRESET NORM;" ' Preset to the designated state (Normal)
Cmds = Cmds + "NRDGS 100,AUTO;" ' Set the number of readings pre trigger (4100 readings)
Cmds = Cmds + "TARM AUTO;" ' Setup the trigger
Cmds = Cmds + "TRIG HOLD;" ' Hold the trigge until triggered
Cmds = Cmds + "MEM FIFO;" ' Clear memory and set memory storage type
Cmds = Cmds + "MFORMAT DINT;" ' Set the memory storage format (double integer)
Cmds = Cmds + "OFORMAT ASCII;" ' Set the output format (ASCII)
Cmds = Cmds + "APER 1E-4;" ' Set the arperature time' Set for the real time processing, if selected
Cmds = Cmds + "MATH STAT"
' Execute the commands
DMM.WriteString Cmds' Check for errors
Check_Error "Setup"End SubFunction GetReadings() As Double'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This sub triggers the instrument and returns the readings from memory.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim rdcnt As Integer
Dim NumSamp As Integer
Dim StdDev As Double
Dim MeanVal As Double
Dim UpperVal As Double
Dim LowerVal As Double
SelectAddr_Click
RunProgram
' Trigger the 3458A
DMM.WriteString "TRIG SGL"' Set sufficient timeout to make all measurements
DMM.IO.Timeout = 8000 With DMM
' Get number of readings taken
.WriteString "RMATH NSAMP"
NumSamp = .ReadNumber ' Get the standard deviation
.WriteString "RMATH SDEV"
StdDev = .ReadNumber
' Get the mean (avearage) value
.WriteString "RMATH MEAN"
MeanVal = .ReadNumber ' Get the upper (maximum) value
.WriteString "RMATH UPPER"
UpperVal = .ReadNumber
' Get the lower (minimum) value
.WriteString "RMATH LOWER"
LowerVal = .ReadNumber
End With
' Set timeout to a default value
DMM.IO.Timeout = 2000
' Check for errors
'Check_Error "GetReadings"
GetReadings = StdDevEnd FunctionFunction OpenPort() As Boolean
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This function opens a port (the communication between the instrument and computer).
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim addr As String ' to be used for the instrument address
Dim retval As String' Exit if error occurs
' If port is open, close it
If connected Then
DMM.IO.Close
End If' Set the resource manager session
Set io_mgr = New AgilentRMLib.SRMCls' Create the VISA Com object
Set DMM = New VisaComLib.FormattedIO488' Get the instrument address form the text box
addr = UCase$("GPIB::13")
' Set the VISA Com resource session
Set DMM.IO = io_mgr.Open(addr, True, True, "")' Set timeout to 2 seconds
DMM.IO.Timeout = 2000' Set the termination character to carriage return (i.e., 13);
' the 3458A uses this character
DMM.IO.TerminationCharacter = 13' Set the flag to terminate when receiving a termination character
DMM.IO.TerminationCharacterEnabled = True' Query instrument ID string
With DMM
.WriteString "ID?"
retval = .ReadString
End With' Check if correct instrument is addressed
If InStr(retval, "3458A") = 0 Then
MsgBox "Wrong instrument addressed!"
' addrSelect.Text = "GPIB0::22"
' addrSelect.Refresh
connected = False
OpenPort = False ' Close the session
DMM.IO.Close Exit Function
End If' Reset the 3458A to it's power on state
DMM.WriteString "RESET"' Check for errors
Check_Error "OpenPort"connected = True
OpenPort = TrueExit Function
End FunctionSub ClosePort()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This club closes the communication with the instrument.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""If connected Then
' Close the port
DMM.IO.Close
End IfEnd SubSub Check_Error(msg As String)
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' Checks for syntax and other errors.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Dim ErrMsg As String * 80' Check for error
With DMM
.WriteString "ERRSTR?"
ErrMsg = .ReadString
End With' If error is found, show the error
End Sub
Private Sub SelectAddr_Click()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' Selects address and opens session
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""' Open port
If Not OpenPort Then
Exit Sub
Else
connected = True
End IfEnd Sub
我用DELPHI调用代码是:implementation
function GetReadings(StdDev:real):integer;stdcall;
external 'c:\aaa\ProjectOK.dll';{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var x:real;
begin
x:=GetReadings(StdDev);
edit1.text:= inttostr(StdDev);
//edit2.text:= inttostr(x);
//edit3.text:= inttostr(x);
//edit4.text:= inttostr(x);
end;
请教高手!!为什么每次调用DLL,点击delphi的button,就出现了前面提到的错误???
解决方案 »
- setup factory 7.0 打包程序及驱动时,怎样提示安装?
- adodb程序运行出错,求~~~~~~~~~~~
- 谁能告诉哪里有InstallSHield pro 6.30下载,还有序列号最好也能提供!
- 文件复制的问题
- 一个有关下载控件的问题,急盼答案!!!!!!!!!
- 心情不好,失恋+失业,怎么办????????散分(分太了,只能给这一点,意思)
- 请问怎样设置数据库的相对路径呀?
- 哪位高手帮帮忙呀!是有关于C#的一个小问题(我只是入门者呀)谢了!!!!
- 请问如何用keybd_event()模拟Shift+Tab键?
- 真的碰到问题了! :(
- 一个长度计算 VB ACCESS
- 关于shell的用法 怎么打开在text里写的那个应用程序
普通的DLL只有VB才能使用