俺晕!!!怎么就没人回答,应该没这么难吧??? (100分)

  • 主题发起人 主题发起人 Tiger_Dxj
  • 开始时间 开始时间
T

Tiger_Dxj

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL调用VB,VC都实现了,为什么Delphi就不行了????
这是我的delphi程序,调用InitializeWinIo就可以,调用GetPortVal就出错,说
'Access Violation at address 1000143c in WinIo.dll. Write of address 0000000'
请问为什么,我的程序有问题吗?

implementation
Function InitializeWinIo() : Bool;Cdecl;external 'WinIo.Dll'
Function GetPortVal(wPortAddr:WORD; pdwPortVal:PDWord; bSize:BYTE) : Bool;Cdecl;external 'WinIo.Dll'
Function ShutdownWinIo() : Bool;Cdecl;external 'WinIo.Dll'
{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
Var
AA : PDWord;
begin
if InitializeWinIo() Then
Begin
AA := Nil;
ShowMessage('Init Success!');

if GetPortVal($500,AA,1) Then
ShowMessage('ReadOk')
Else
ShowMessage('ReadError');

End;
if ShutdownWinIo() Then
ShowMessage('CloseOk')
Else
ShowMessage('CloseError');
end;


这是VB的程序
Private Sub BtnGet_Click()
Dim Result As Boolean
Dim PortVal As Long

Result = GetPortVal(Val("&H" + TxtPortAddr), PortVal, 1)

If (Result = False) Then
MsgBox "Whoops ! There is a problem with GetPortByte.", vbOKOnly + vbCritical, "VBDumpPort32"
Unload FrmVBDumpPort32
Else
TxtPortByte = Hex$(PortVal And &HFF)
End If
End Sub
Private Sub BtnQuit_Click()
Unload FrmVBDumpPort32
End Sub
Private Sub BtnSet_Click()
Dim Result As Boolean

Result = SetPortVal(Val("&H" + TxtPortAddr), Val("&H" + TxtPortByte), 1)

If (Result = False) Then
MsgBox "Whoops ! There is a problem with SetPortByte.", vbOKOnly + vbCritical, "VBDumpPort32"
Unload FrmVBDumpPort32
End If
End Sub

 
我在delphi把AA:=Nil这局屏蔽,把$500改成其它值也不行
 
声明函数时加SAFECALL或STDCALL试一下
 
OK,俺解决了
怎么取消这个帖子啊??????
 
函数原型中PDWORD是一个指向DWord型的指针,delphi调用是变量AA改成@AA就行了
 
Tiger_Dxj我按你的方法用后还是不行,能把你的源码发过来email:lg613@163.net
 
接受答案了.
 
后退
顶部