Posted: Thu Jan 17, 2002 6:38 pm
Restored from previous forum. Originally posted by Rings.
I want to call a external DLL.LoadLibrary,GetProcAdress and Call does work, but i have trouble Pushing Variables on the Stack and getting them back after call.Always get an Assembly Error.
It must be a simply syntax-error.How to do it (Push) correctly in PureBasic ?
The WinIO Libs is from http://www.internals.com .
;
Procedure CallDLL(DLLFile$,DLLFunction$)
hLib.l
lpDLLEntryPoint.l
hLib = LoadLibrary_(DLLFile$) ;Load the DLL into memory
If hLib =0
ProcedureReturn 0
EndIf
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint = 0
FreeLibrary_(hLib)
ProcedureReturn -1 ;This is not a ActiveX
EndIf
FreeLibrary_(hLib)
ProcedureReturn lpDLLEntryPoint
EndProcedure
Result.l
Result1=CallDLL("c:\WinIO\DLL\release\winio.dll","InitializeWinIo")
Result2=CallDLL("c:\WinIO\DLL\release\winio.dll","ShutdownWinIo")
;Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte) As Boolean
Result3=CallDLL("c:\WinIO\DLL\release\winio.dll","GetPortVal")
If Result1 And Result2 And Result3
hLib.l
lpDLLEntryPoint.l
DLLFile$="c:\WinIO\DLL\release\winio.dll"
hLib = LoadLibrary_(DLLFile$) ;Load the DLL into memory
DLLFunction$="InitializeWinIo"
If hLib 0
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
Call lpDLLEntryPoint
;Push Result,[EAX]
MessageRequester("INFO","DLLTest:"+Str(Result),0)
EndIf
;PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte
PortAddr.w=$278
PortVal.l=12
bSize.b=2
DLLFunction$="GetPortVal"
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
Push bSize
; PUSH DWORD PortVal
; PUSH DWORD PortAddr
Call lpDLLEntryPoint
;Push Result,[EAX]
EndIf
DLLFunction$="ShutdownWinIo"
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
Call lpDLLEntryPoint
MessageRequester("INFO","DLLTest:"+Str(Result),0)
;Push Result,[EAX]
EndIf
FreeLibrary_(hLib)
EndIf
Else
MessageRequester("INFO","DLLTest failed !",0)
EndIf
Getting better with a little help from my friends....thx Siggi
I want to call a external DLL.LoadLibrary,GetProcAdress and Call does work, but i have trouble Pushing Variables on the Stack and getting them back after call.Always get an Assembly Error.
It must be a simply syntax-error.How to do it (Push) correctly in PureBasic ?
The WinIO Libs is from http://www.internals.com .
;
Procedure CallDLL(DLLFile$,DLLFunction$)
hLib.l
lpDLLEntryPoint.l
hLib = LoadLibrary_(DLLFile$) ;Load the DLL into memory
If hLib =0
ProcedureReturn 0
EndIf
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint = 0
FreeLibrary_(hLib)
ProcedureReturn -1 ;This is not a ActiveX
EndIf
FreeLibrary_(hLib)
ProcedureReturn lpDLLEntryPoint
EndProcedure
Result.l
Result1=CallDLL("c:\WinIO\DLL\release\winio.dll","InitializeWinIo")
Result2=CallDLL("c:\WinIO\DLL\release\winio.dll","ShutdownWinIo")
;Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte) As Boolean
Result3=CallDLL("c:\WinIO\DLL\release\winio.dll","GetPortVal")
If Result1 And Result2 And Result3
hLib.l
lpDLLEntryPoint.l
DLLFile$="c:\WinIO\DLL\release\winio.dll"
hLib = LoadLibrary_(DLLFile$) ;Load the DLL into memory
DLLFunction$="InitializeWinIo"
If hLib 0
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
Call lpDLLEntryPoint
;Push Result,[EAX]
MessageRequester("INFO","DLLTest:"+Str(Result),0)
EndIf
;PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte
PortAddr.w=$278
PortVal.l=12
bSize.b=2
DLLFunction$="GetPortVal"
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
Push bSize
; PUSH DWORD PortVal
; PUSH DWORD PortAddr
Call lpDLLEntryPoint
;Push Result,[EAX]
EndIf
DLLFunction$="ShutdownWinIo"
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
Call lpDLLEntryPoint
MessageRequester("INFO","DLLTest:"+Str(Result),0)
;Push Result,[EAX]
EndIf
FreeLibrary_(hLib)
EndIf
Else
MessageRequester("INFO","DLLTest failed !",0)
EndIf
Getting better with a little help from my friends....thx Siggi