I use WinINet.dll to transfer files to/from a FTP-Server. That works great. If you have very large files it is a bit annoying to get no feedback until the transfer is done. What I am trying to do now is to get some feedback about the transfer progress with a call to InternetSetStatusCallback.
hINet = InternetOpen(ByVal VarPtr(INetAgent), _
ByVal %INTERNET_OPEN_TYPE_PRECONFIG, _
ByVal %NULL, _
ByVal %NULL, _
ByVal 0)
dResult = InternetSetStatusCallback(hINet, CodePtr(iNetStatusCallBack))
dContex = 2
hFtpCon = InternetConnect(hINet, _
FtpServer, _
%INTERNET_INVALID_PORT_NUMBER, _
szUserName, _
szPassword, _
%INTERNET_SERVICE_FTP, _
%INTERNET_FLAG_PASSIVE, _
dContext)
The call to InternetConnect results in a GPF because Windows wants to read the address of the value(!) of hINet. I tried all possible combinations to declare hINet in InternetSetStatusCallback and dContext in InternetConnect but no luck...
Has anybody got better results with InternetSetStatusCallback in combination with the StatusCallBack function ?
Quote
The call to InternetConnect results in a GPF because Windows wants to read the address of the value(!) of hINet.
I don't think so. It wants to read the address of the value of dwContext. According to MSDN documentation, http://msdn.microsoft.com/en-us/library/aa384363(VS.85).aspx
Quote
dwContext [in]
Pointer to a variable that contains an application-defined value that is used to identify the application context for the returned handle in callbacks.
Try it using BYVAL VARPTR(dContext) instead of passing dConetxt.
That was one of the options I tested already.
The result is:
result form InternetOpen: hINet=&H00CC0004
Error after call to InternetConnect with BYVAL VARPTR(dContext): Access violation reading location 0x00cc0004
seems to be very tricky...
This works, Compare it with what you are doing (you don't show your callback function).
' SED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "c:\pbwin90\winapi\win32api.inc"
#INCLUDE "c:\pbwin90\winapi\wininet.inc"
FUNCTION PBMAIN () AS LONG
LOCAL hInternet AS DWORD
LOCAL hConnect AS DWORD
LOCAL lRes AS LONG
LOCAL dwRes AS DWORD
LOCAL dwContext AS DWORD
hInternet = InternetOpen("Sample", _
%INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0)
? "hInternet = " hInternet
IF hInternet = %NULL THEN EXIT FUNCTION
dwRes = InternetSetStatusCallback(hInternet, CODEPTR(MyStatusCallback))
? "InternetSetStatusCallback = " dwRes
dwContext = 2
hConnect = InternetConnect(hInternet, "ftp.freebsd.org", _
%INTERNET_INVALID_PORT_NUMBER, _
"", "", %INTERNET_SERVICE_FTP, _
%INTERNET_FLAG_PASSIVE, BYVAL VARPTR(dwContext))
? "hConnect = " hConnect
IF hConnect = %NULL THEN GOTO LExit
lRes = FtpGetFile(hConnect, "/pub/FreeBSD/doc/README", "c:\xxx\README", _
%FALSE, %FILE_ATTRIBUTE_ARCHIVE, _
%FTP_TRANSFER_TYPE_UNKNOWN, 0&)
IF lRes THEN ? "File downloaded"
LExit:
IF hConnect THEN lRes = InternetCloseHandle(hConnect)
IF hInternet THEN lRes = InternetCloseHandle(hInternet)
WAITKEY$
END FUNCTION
'typedef
'VOID
'(CALLBACK * INTERNET_STATUS_CALLBACK)(
' __in HINTERNET hInternet,
' __in_opt DWORD_PTR dwContext,
' __in DWORD dwInternetStatus,
' __in_opt LPVOID lpvStatusInformation,
' __in DWORD dwStatusInformationLength
' );
SUB MyStatusCallback ( _
BYVAL hInternet AS DWORD, _
BYVAL dwContext AS DWORD PTR, _
BYVAL dwInternetStatus AS DWORD, _
BYVAL lpvStatusInformation AS DWORD, _
BYVAL dwStatusInformationLength AS DWORD)
? "hInternet = " hInternet
? "dwContext = " dwContext
IF dwContext THEN ? "dwContext value = " @dwContext
? "dwInternetStatus = " dwInternetStatus
END SUB
José,
YES now it works !
I missed the BYVAL's within the declaration of StatusCallBack.
Thank you for your great help and time!!