Estoy intentando hacer un FTP directory pero me da un error al momento de compilar que después se traduce en un GPF Error cuando se ejecuta el programa.
Error al compilar: Warning W8075 pruebaFTP.prg 331: suspicius pointer conversion in function HB_FTPFINDFIRSTFILE.
He estado buscando y no encuentro donde está el error por lo que necesito que alguien lo revise a ver si da con el mismo.
Agradeciendo de antemano su ayuda acompaño el código completo del ejemplo que es el siguiente:
- Code: Select all Expand view
- #include "Fivewin.ch"
#include "fileio.ch"
#include "Struct.ch"
//
// File attributes
//
#define FILE_ATTRIBUTE_READONLY 1
#define FILE_ATTRIBUTE_HIDDEN 2
#define FILE_ATTRIBUTE_SYSTEM 4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE 32
#define FILE_ATTRIBUTE_NORMAL 128
#define FILE_ATTRIBUTE_TEMPORARY 256
//
// access types for InternetOpen()
//
#define INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT 1 // direct to net
#define INTERNET_OPEN_TYPE_PROXY 3 // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS
//
// manifests
//
#define INTERNET_INVALID_PORT_NUMBER 0 // use the protocol-specific default
#define INTERNET_DEFAULT_FTP_PORT 21 // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT 70 // " " gopher "
#define INTERNET_DEFAULT_HTTP_PORT 80 // " " HTTP "
#define INTERNET_DEFAULT_HTTPS_PORT 443 // " " HTTPS "
#define INTERNET_DEFAULT_SOCKS_PORT 1080 // default for SOCKS firewall servers.
//
// service types for InternetConnect()
//
#define INTERNET_SERVICE_FTP 1
#define INTERNET_SERVICE_GOPHER 2
#define INTERNET_SERVICE_HTTP 3
//
// flags for FTP
//
#define INTERNET_FLAG_TRANSFER_ASCII 1
#define INTERNET_FLAG_TRANSFER_BINARY 2
//
// file access types
//
#define GENERIC_READ 2147483648
#define GENERIC_WRITE 1073741824
function MAIN()
local oWnd
DEFINE WINDOW oWnd
@ 2, 2 BUTTON "FTP Upload";
SIZE 150,40;
ACTION UPLOADFILE("FTPWRITEFILENEW.INI",,"/EBOC","localhost","FTP_E00","59EA03B84") OF oWnd
@ 4, 2 BUTTON "FTP download";
SIZE 150,40;
ACTION DOWNLOADFILE( oWnd ) OF oWnd
@ 6, 2 BUTTON "FTP Directory";
SIZE 150,40;
ACTION FTPDirectory( "*.*","localhost","FTP_E00","59EA03B84" ) OF oWnd
ACTIVATE WINDOW oWnd MAXIMIZED
return NIL
static function DOWNLOADFILE( oPrg )
local hInternet, hConnect, hSource, hDest, nRead
local cData := space( 1024 )
hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
hConnect = INTERNETCONNECT( hInternet, "localhost", INTERNET_INVALID_PORT_NUMBER, "FTP_E00","59EA03B84", INTERNET_SERVICE_FTP, 0, 0 )
hSource = FTPOPENFILE( hConnect, "FTPWRITEFILENEW.INI", GENERIC_READ, 0, 0 )
hDest = FCREATE( "FTPWRITEFILENEW.INI" )
while .T.
nRead = INTERNETREADFILE( hSource, @cData )
if nRead = -1
msginfo( "Download error" )
exit
endif
if nRead = 0
msginfo( "Download OK" )
exit
endif
FWRITE( hDest, cData, nRead )
enddo
FCLOSE( hDest )
INTERNETCLOSEHANDLE( hSource )
INTERNETCLOSEHANDLE( hConnect )
INTERNETCLOSEHANDLE( hInternet )
return NIL
static function UPLOADFILE(cSourceFile,cDestFile,cDestPath,cIP,cUser,cPass)
local hInternet, hConnect, hSource, hDest, nRead
local nBufferSize:=1024, cData := space( nBufferSize )
local nPos := 0
local lResult:=.F.
default cDestFile := cSourceFile
default cDestPath := ""
hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
hConnect = INTERNETCONNECT( hInternet, cIP, INTERNET_INVALID_PORT_NUMBER, cUser, cPass, INTERNET_SERVICE_FTP, 0, 0 )
// Devuelve 0 si no ha conectado.
hSource = FOPEN( cSourceFile, FO_READWRITE )
hDest = FTPOPENFILE( hConnect, cDestPath+iif(cDestPath<>NIL,"/","")+cDestFile, GENERIC_WRITE, 0, 0 )
//msginfo(cDestPath+iif(cDestPath<>NIL,"/","")+cDestFile)
while .T.
nRead = FREAD(hSource,@cData,nBufferSize)
if nRead = -1
msginfo( "Error reading source file" )
exit
endif
if nRead = 0
if lResult
FCLOSE(hSource)
msginfo( "Upload Finished OK" )
else
msginfo( "Upload error" )
endif
exit
endif
lResult:= INTERNETWRITEFILE( hDest, @cData, nRead )
nPos += len( cData )
//oPrg:set(nPos)
enddo
INTERNETCLOSEHANDLE( hDest )
INTERNETCLOSEHANDLE( hConnect )
INTERNETCLOSEHANDLE( hInternet )
return lResult
function FTPDirectory( cMask,cIP,cUser,cPass )
local hFTPDir, aFiles := {}
local oWin32FindData, cBuffer
default cMask := "*.*"
STRUCT oWin32FindData
MEMBER nFileAttributes AS DWORD
MEMBER nCreationTime AS STRING LEN 8
MEMBER nLastReadAccess AS STRING LEN 8
MEMBER nLastWriteAccess AS STRING LEN 8
MEMBER nSizeHight AS DWORD
MEMBER nSizeLow AS DWORD
MEMBER nReserved0 AS DWORD
MEMBER nReserved1 AS DWORD
MEMBER cFileName AS STRING LEN 260
MEMBER cAltName AS STRING LEN 14
ENDSTRUCT
hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
hConnect = INTERNETCONNECT( hInternet, cIP, INTERNET_INVALID_PORT_NUMBER, cUser, cPass, INTERNET_SERVICE_FTP, 0, 0 )
if hConnect != nil
cBuffer = oWin32FindData:cBuffer
hFTPDir = FtpFindFirstFile( hConnect, cMask, @cBuffer, 0, 0 )
oWin32FindData:cBuffer = cBuffer
if ! Empty( oWin32FindData:cFileName )
aadd( aFiles, { oWin32FindData:cFileName,;
oWin32FindData:nSizeLow } )
while InternetFindNextFile( hFTPDir, @cBuffer )
oWin32FindData:cBuffer = cBuffer
aadd( aFiles, { oWin32FindData:cFileName,;
oWin32FindData:nSizeLow } )
end
endif
InternetCloseHandle( hFTPDir )
INTERNETCLOSEHANDLE( hConnect )
endif
INTERNETCLOSEHANDLE( hInternet )
return aFiles
#pragma BEGINDUMP
#include "windows.h"
#include "wininet.h"
#include "hbapi.h"
HB_FUNC( INTERNETOPEN )
{
hb_retnl( ( LONG ) InternetOpen( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parnl( 5 ) ) );
}
HB_FUNC( INTERNETCLOSEHANDLE )
{
hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
}
HB_FUNC( INTERNETCONNECT )
{
hb_retnl( ( LONG ) InternetConnect( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( INTERNET_PORT ) hb_parnl( 3 ), hb_parc( 4 ), hb_parc( 5 ), hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) ) );
// Devuelve 0 si no ha conectado.
}
HB_FUNC( FTPOPENFILE )
{
hb_retnl( ( LONG ) FtpOpenFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}
HB_FUNC( FTPGETFILESIZE )
{
DWORD nFileSizeHigh;
hb_retnl( ( LONG ) FtpGetFileSize( ( HINTERNET ) hb_parnl( 1 ), &nFileSizeHigh ) );
}
HB_FUNC( INTERNETREADFILE )
{
DWORD nBytesRead;
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );
if ( !lSuccess )
hb_retnl( -1 );
else
hb_retnl( nBytesRead );
}
HB_FUNC( INTERNETWRITEFILE )
{
DWORD nBytesWritten;
BOOL lSuccess = InternetWriteFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), &nBytesWritten );
hb_retl( lSuccess );
}
HB_FUNC( FTPFINDFIRSTFILE )
{
LPWIN32_FIND_DATAA cBuffer;
hb_retnl( ( LONG ) FtpFindFirstFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), &cBuffer, hb_parnl( 4 ), hb_parnl( 5 ) ) );
}
HB_FUNC( INTERNETFINDNEXTFILE )
{
LPWIN32_FIND_DATAA cBuffer;
BOOL lSuccess = InternetFindNextFile( ( HINTERNET ) hb_parnl( 1 ), &cBuffer ) ;
hb_retl( lSuccess );
}
#pragma ENDDUMP