FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour cResToStr working function
Posts: 182
Joined: Tue Oct 18, 2005 10:01 AM
cResToStr working function
Posted: Fri Apr 17, 2009 01:07 AM
Hi Antonio.

Look at this code please:

Code (fw): Select all Collapse
HB_FUNC( CRESTOSTR )
{
    HRSRC  hRes = FindResource( ( HMODULE ) GetResources(), MAKEINTRESOURCE( hb_parni( 1 ) ), RT_BITMAP );

    HANDLE hResource = LoadResource( ( HINSTANCE ) GetResources(), hRes );

    hb_retclen( ( LPSTR ) LockResource( hResource ), sizeof( hResource ) );
}


? Len( cResToStr( 7777 ) ) always return 4 bytes instead a string of a full bitmap bits.

The same occur with original crestostr() FWH function.

Any hint please ?


Regards,

Toninho.
Posts: 47
Joined: Thu Jan 05, 2006 06:56 PM
Re: cResToStr help needed
Posted: Fri Apr 17, 2009 11:08 AM

Because sizeof(int) or sizeof(hResource) always return 4 (integers have 4 bytes in length)....

Vailton Renato
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cResToStr help needed
Posted: Fri Apr 17, 2009 02:36 PM

Toninho,

You are not using SizeofResource() which it is needed.

Also you are not checking for wrong returned values! You are assuming that everything will be found, which can not be the case.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 182
Joined: Tue Oct 18, 2005 10:01 AM
Re: cResToStr help needed
Posted: Fri Apr 17, 2009 04:25 PM
Antonio Linares wrote:Toninho,
You are not using SizeofResource() which it is needed.
Also you are not checking for wrong returned values! You are assuming that everything will be found, which can not be the case.


Hi Antonio and Vailton,

It is intentional, only to simplify my code, but lets go, here is the full code, that doesn´t work:

Code (fw): Select all Collapse
HB_FUNC( CRESTOSTR )
{
   HRSRC  hRes = FindResource( ( HINSTANCE ) GetResources(), ( LPCSTR ) ( ISNUM( 1 ) ? ( LPCSTR ) hb_parnl( 1 ) : hb_parc( 1 ) ), ( LPCSTR ) hb_parnl( 2 ) );

   HANDLE hglb;

   if( hRes )
   {
      hglb = LoadResource( ( HINSTANCE ) GetResources(), hRes );

      if( hglb )
      {
         hb_retclen( ( LPSTR ) LockResource( hglb ), GlobalSize( hglb ) );
      }
      else
      {
         hb_retc( "" );
      }
   }
   else
   {
      hb_retc( "" );
   }
}


To test it:

Code (fw): Select all Collapse
? Len( crestostr( 7777, "BITMAP" ) )



This code is the original crestostr from FWH.

What is wrong please?

Regards,

Toninho.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cResToStr help needed
Posted: Fri Apr 17, 2009 07:16 PM

Toninho,

Have you tried SizeofResource() instead of GlobalSize() ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 182
Joined: Tue Oct 18, 2005 10:01 AM
Re: cResToStr help needed
Posted: Fri Apr 17, 2009 07:45 PM
Antonio Linares wrote:Toninho,

Have you tried SizeofResource() instead of GlobalSize() ?


Yes, and no works... :-)

My intention in load a png file from resource. Now, I´m trying with BITMAP because is easy, if works with bitmap, I´ll load png.

I´d tried native FWH crestostr() and no works too.

TIA and best regards,

Toninho.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cResToStr help needed
Posted: Fri Apr 17, 2009 10:45 PM

Toninho,

Please try this:

In your RC file:
test PNG "file.png"

then from your PRG:
MsgInfo( Len( cResToStr( "test", "PNG" ) ) )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 182
Joined: Tue Oct 18, 2005 10:01 AM
Re: cResToStr help needed
Posted: Sat Apr 18, 2009 04:15 PM
Hi Antonio,

This is the right code:

Code (fw): Select all Collapse
HB_FUNC( CRESTOSTR )
{
   HMODULE hMod = GetResources();

   HRSRC hRes = FindResource( hMod, MAKEINTRESOURCE( hb_parni( 1 ) ), "PNG" );  // need change to get param 2

   LONG size = SizeofResource( hMod, hRes );

   HANDLE pt = LoadResource( hMod, hRes );

   LPSTR pResult;

   pResult = ( LPSTR ) hb_xgrab( size + 1 );

   memcpy( pResult, pt, size );

   hb_retclen( pResult, size );

   hb_xfree( pResult );
}



Regards,

Toninho.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cResToStr working function
Posted: Sat Apr 18, 2009 11:18 PM

very good :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion