FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Warning W8075
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Warning W8075

Posted: Sun May 29, 2011 11:13 AM
Hello,

I get the following waring when I compile:

Warning W8075 c:\\myapp\\test\\FTP.PRG 645: Suspicious pointer conversion in function HB_FUN_INTERNETREADFILE

Line is:

Code (fw): Select all Collapse
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );



And whole function is:

Code (fw): Select all Collapse
HB_FUNC( INTERNETREADFILE )
{
    DWORD nBytesRead;

    BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );

    if ( !lSuccess )
        hb_retnl( -1 );
    else
        hb_retnl( nBytesRead );
}



What is wrong?.

Thank you very much!!.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM

Re: Warning W8075

Posted: Sun May 29, 2011 11:54 AM
Hello

the 2nd parameter is a output buffer that receives the data.

hb_parc() is a pointer to constant char, we can not change this,
should allocate memory to use like output buffer
1) send the variable by reference and return the length or
2) returning the output buffer

please test both case ( i didn't test )

Code (fw): Select all Collapse
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <wininet.h>

HB_FUNC( INTERNETREADFILE1  )
{
    DWORD nBytesRead;
    char * pOut = ( char * ) hb_xgrab( hb_parnl( 2 ) );

    BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), 
                                      pOut, hb_parnl( 2 ), &nBytesRead );

    if ( !lSuccess )
        hb_ret();
    else
        hb_retc( pOut );
}

HB_FUNC( INTERNETREADFILE2  )
{
    DWORD nBytesRead;
    char * pOut = ( char * ) hb_xgrab( hb_parclen( 2 ) );

    BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), 
                                      pOut, hb_parclen( 2 ), &nBytesRead );

    if ( !lSuccess )    
        hb_retnl( -1 );
    else
    {
        hb_storc( pOut, 2 );
        hb_xfree( pOut );
        hb_retnl( nBytesRead );
    }
}

#pragma ENDDUMP
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Re: Warning W8075

Posted: Sun May 29, 2011 12:00 PM
Thank you four quick support.

My code works despite the warning. I got this warning when I move from Harbour 1.x to Harbour 2.0

Also, I get the same warning in other code:

Warning W8075 update.prg 382: Suspicious pointer conversion in function HB_FUN_FILETIMES

Code (fw): Select all Collapse
LPSTR cFileName = hb_parc( 1 ) ;




Warning W8075 update.prg 478: Suspicious pointer conversion in function HB_FUN_RESTOFILE

Code (fw): Select all Collapse
WriteFile(hFile,pRes,size,&bytesWritten,NULL);




So I do not understand the problem.

What could happend?.

Thank you.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM

Re: Warning W8075

Posted: Sun May 29, 2011 12:04 PM
Hello

Code (fw): Select all Collapse
LPSTR cFileName = ( LPSTR ) hb_parc( 1 ) ;



what is the definitions of hFile, pRes, size, &bytesWritten ??
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Re: Warning W8075

Posted: Sun May 29, 2011 12:48 PM
Hello

This is the complete function:

Code (fw): Select all Collapse
HB_FUNC( RESTOFILE )
{
   HRSRC res=FindResource(NULL,"ACTVER",RT_RCDATA);
   LPDWORD bytesWritten;
   int size=SizeofResource(NULL,res);
   HGLOBAL hRes=LoadResource(NULL,res);
   unsigned char *pRes=(unsigned char *)LockResource(hRes);
   HANDLE hFile=CreateFile("ACTVER.EXE",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
   WriteFile(hFile,pRes,size,&bytesWritten,NULL);
   CloseHandle(hFile);
}


Thank you.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM

Re: Warning W8075

Posted: Sun May 29, 2011 12:50 PM
Hello

should be
Code (fw): Select all Collapse
DWORD bytesWritten;
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Re: Warning W8075

Posted: Sun May 29, 2011 01:33 PM

Daniel,

Thank you very much for so quick support!!. Now warnings are off.

Those changes refer to Bielsys article about updating software via FTP.

What book do you recomend me to learn C in Harbour?.

Thanks again.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM

Re: Warning W8075

Posted: Sun May 29, 2011 01:43 PM

Hello

look my firm :-)
( our best documentation is the source code )

i learned C reading the harbour source code

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM

Re: Warning W8075

Posted: Sun May 29, 2011 02:34 PM
ukservice wrote:
Code (fw): Select all Collapse
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );


Code (fw): Select all Collapse
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );


Please note that you have to pass an existing buffer by reference to the function:

Code (fw): Select all Collapse
LOCAL cData := SPACE( 1024 )

...

nRead = INTERNETREADFILE( hSource, @cData )


You don't need to allocate the buffer in the C function but you can if you prefer doing so.

EMG
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Re: Warning W8075

Posted: Mon May 30, 2011 01:56 PM

Mr Enrico,

Thank you. It works perfect.

By the way, what books do you recomend me to learn C?.

Thank you again.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM

Re: Warning W8075

Posted: Mon May 30, 2011 05:42 PM

I start learning C in the middle of '80th using the "bible" Kernighan & Ritchie.

EMG

Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Re: Warning W8075

Posted: Mon May 30, 2011 06:10 PM

Thank you again.

But is there something recent for Harbour?.

I am afraid I won´t understand Harbour sources as Daniel suggested to me.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Warning W8075

Posted: Mon May 30, 2011 06:59 PM
Enrico Maria Giordano wrote:I start learning C in the middle of '80th using the "bible" Kernighan & Ritchie.

EMG

Me too.

Ritchie is the creator of C language.

This book is available for download as e-book.
http://www.inf.unideb.hu/grafika/eng/rt ... uage_C.pdf

Very easy to understand even for a dull-head like me.
Regards



G. N. Rao.

Hyderabad, India
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM

Re: Warning W8075

Posted: Tue May 31, 2011 08:14 AM

Thank you Mr. Rao.

You are a Master of FWH ;)

FWH 11.11, Harbour 3.1 and Borland C++ 5.82

Continue the discussion