Warning W8075

Warning W8075

Postby ukservice » 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: Select all  Expand view
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );



And whole function is:

Code: Select all  Expand view

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
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: Warning W8075

Postby Daniel Garcia-Gil » 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: Select all  Expand view

#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
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Warning W8075

Postby ukservice » 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: Select all  Expand view
LPSTR cFileName = hb_parc( 1 ) ;

 




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

Code: Select all  Expand view
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
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: Warning W8075

Postby Daniel Garcia-Gil » Sun May 29, 2011 12:04 pm

Hello

Code: Select all  Expand view
LPSTR cFileName = ( LPSTR ) hb_parc( 1 ) ;



what is the definitions of hFile, pRes, size, &bytesWritten ??
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Warning W8075

Postby ukservice » Sun May 29, 2011 12:48 pm

Hello

This is the complete function:

Code: Select all  Expand view

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
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: Warning W8075

Postby Daniel Garcia-Gil » Sun May 29, 2011 12:50 pm

Hello

should be
Code: Select all  Expand view
DWORD bytesWritten;
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Warning W8075

Postby ukservice » Sun May 29, 2011 1: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
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: Warning W8075

Postby Daniel Garcia-Gil » Sun May 29, 2011 1:43 pm

Hello

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

i learned C reading the harbour source code
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Warning W8075

Postby Enrico Maria Giordano » Sun May 29, 2011 2:34 pm

ukservice wrote:
Code: Select all  Expand view
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );


Code: Select all  Expand view
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: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Warning W8075

Postby ukservice » Mon May 30, 2011 1: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
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: Warning W8075

Postby Enrico Maria Giordano » Mon May 30, 2011 5:42 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Warning W8075

Postby ukservice » Mon May 30, 2011 6: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
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: Warning W8075

Postby nageswaragunupudi » Mon May 30, 2011 6: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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Warning W8075

Postby ukservice » Tue May 31, 2011 8:14 am

Thank you Mr. Rao.

You are a Master of FWH ;)
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 98 guests