Posted: Wed Jul 03, 2002 7:14 pm
Restored from previous forum. Originally posted by Shawn.
Hi.
I am writing a program using procedures with memory and library functions, and am having difficulty returning results from the procedure. I have rewritten the sample below without procedures and it works fine. With procedures, the program crashes on the ProcedureReturn line.
I am using Windows2000 and Dr Watson gives the error "Exception number: 0000005 (access violation)"
The program is for a travel agency on a private network so you won't be able to test this example, but here is what it is supposed to do:
The program should establish a connection with the airline reservation system (a.k.a. Sabre, "the host") in order to send and recieve messages later on in the program.
The dll provides a function for establishing a connection (ConnectToHost). It takes a pointer to a string (#SabreRoute) and will return a pointer (*SabreHandle) to a session handle to be used later.
I have shared the 2 pointers in the procedure because otherwise I get a message saying that the "Specified address is null" when trying the line "result = PeekL(*SabreHandle)"
I am using PB version 3.20.
Does anyone know why this doesn't work and what I can do instead?
Thanks.
Shawn
This code doesn't work. (with procedures)
This code works. (without procedures)
Hi.
I am writing a program using procedures with memory and library functions, and am having difficulty returning results from the procedure. I have rewritten the sample below without procedures and it works fine. With procedures, the program crashes on the ProcedureReturn line.
I am using Windows2000 and Dr Watson gives the error "Exception number: 0000005 (access violation)"
The program is for a travel agency on a private network so you won't be able to test this example, but here is what it is supposed to do:
The program should establish a connection with the airline reservation system (a.k.a. Sabre, "the host") in order to send and recieve messages later on in the program.
The dll provides a function for establishing a connection (ConnectToHost). It takes a pointer to a string (#SabreRoute) and will return a pointer (*SabreHandle) to a session handle to be used later.
I have shared the 2 pointers in the procedure because otherwise I get a message saying that the "Specified address is null" when trying the line "result = PeekL(*SabreHandle)"
I am using PB version 3.20.
Does anyone know why this doesn't work and what I can do instead?
Thanks.
Shawn
This code doesn't work. (with procedures)
Code: Select all
#ProgramName = "Sabre Connection"
#SabreRoute = "FIXEDOFEPSABRE"
Global SabreHandle.l
If OpenLibrary(0, "CCSAPI.DLL")
Else
MessageRequester(#ProgramName, "Error opening Library - This program will end.",0)
End
EndIf
Procedure.l ConnectToSabre()
Shared *Route, *SabreHandle
CallDebugger
result.l = 0
*Route = AllocateMemory(0, Len(#SabreRoute), 0)
*SabreHandle = AllocateMemory(1, 1, 0)
PokeS(*Route, #SabreRoute)
Debug "*Route = " + Str(*Route) ; yields *Route = 8003216
Debug "*SabreHandle = " + Str(*SabreHandle) ; yields *SabreHandle = 8003240
If CallFunction(0, "ConnectToHost", *SabreHandle, *Route) = 0
result = PeekL(*SabreHandle)
EndIf
Debug "result = " + Str(result) ; yields result = 10682440 (random number generated by the host)
ProcedureReturn result
EndProcedure
SabreHandle.l = ConnectToSabre()
If SabreHandle.l = 0
MessageRequester(#ProgramName, "Error connecting to host - This program will end.",0)
End
EndIf
CloseLibrary(0)
Code: Select all
#ProgramName = "Sabre Connection"
#SabreRoute = "FIXEDOFEPSABRE"
Global SabreHandle.l
If OpenLibrary(0, "CCSAPI.DLL")
Else
MessageRequester(#ProgramName, "Error opening Library - This program will end.",0)
End
EndIf
;Procedure.l ConnectToSabre()
; Shared *Route, *SabreHandle
CallDebugger
result.l = 0
*Route = AllocateMemory(0, Len(#SabreRoute), 0)
*SabreHandle = AllocateMemory(1, 1, 0)
PokeS(*Route, #SabreRoute)
Debug "*Route = " + Str(*Route) ; yields *Route = 8003216
Debug "*SabreHandle = " + Str(*SabreHandle) ; yields *SabreHandle = 8003240
If CallFunction(0, "ConnectToHost", *SabreHandle, *Route) = 0
result = PeekL(*SabreHandle)
EndIf
Debug "result = " + Str(result) ; yields result = 10682440 (random number generated by the host)
; ProcedureReturn result
;EndProcedure
SabreHandle.l = result
If SabreHandle.l = 0
MessageRequester(#ProgramName, "Error connecting to host - This program will end.",0)
End
EndIf
CloseLibrary(0)