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
Push Variable correctly ?
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
AFAIK, you must use:
instead of:
I mean, use string pointers instead of strings in API function parameters. Haven't tried it, though. Anyway and, by the way, use the 'code' facility when posting, please. It helps a lot.
Bye,
El_Choni
AFAIK, you must use:
Code: Select all
GetProcAddress_(hLib, @DLLFunction$)
Code: Select all
GetProcAddress_(hLib, DLLFunction$)
Bye,
El_Choni
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
Nope, El_Choni.
PUSHes the address of the string
on the stack, so it works how it should.
@Rings: change this lines...
The Error:
bSize.b=2
[...]
PUSH bSize
There is no "PUSH m8" or "PUSH r8", only a
"PUSH imm8". And "PUSH imm8" is expanded to
a WORD before pushing.
cya,
...Danilo
Edited by - Danilo on 18 January 2002 08:42:57
Nope, El_Choni.
Code: Select all
GetProcAddress_(hLib, DLLFunction.s)
on the stack, so it works how it should.
@Rings: change this lines...
Code: Select all
PortAddr.l=$278
PortVal.l=12
bSize.l=2
DLLFunction$="GetPortVal"
lpDLLEntryPoint = GetProcAddress_(hLib, DLLFunction$) ;'Find Procedure in DLL
If lpDLLEntryPoint 0
PUSH bSize
PUSH PortVal
PUSH PortAddr
CALL lpDLLEntryPoint
bSize.b=2
[...]
PUSH bSize
There is no "PUSH m8" or "PUSH r8", only a
"PUSH imm8". And "PUSH imm8" is expanded to
a WORD before pushing.
cya,
...Danilo
Edited by - Danilo on 18 January 2002 08:42:57
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm