delphi 调用 vb做的dll,出现“access violation at address73474179 in module MSVBVM60.DLL
急!! 请教!!我用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 Explicit
Dim io_mgr As VisaComLib.ResourceManager ' to be used for the resource manager
Dim DMM As VisaComLib.FormattedIO488 ' to create a formatted I/O reference
Dim 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
'GetReadings
End Sub
Sub 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 Sub
Function 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 = StdDev
End Function
Function 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 = True
Exit Function
End Function
Sub ClosePort()
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' This club closes the communication with the instrument.
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
If connected Then
' Close the port
DMM.IO.Close
End If
End Sub
Sub 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 If
End 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编译成win32 API的才行。
普通的DLL只有VB才能使用
补充:VB , API