cResToStr working function

cResToStr working function

Postby toninhofwi » Fri Apr 17, 2009 1:07 am

Hi Antonio.

Look at this code please:

Code: Select all  Expand view
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.
Last edited by toninhofwi on Sat Apr 18, 2009 4:16 pm, edited 1 time in total.
toninhofwi
 
Posts: 172
Joined: Tue Oct 18, 2005 10:01 am

Re: cResToStr help needed

Postby vailtom » Fri Apr 17, 2009 11:08 am

Because sizeof(int) or sizeof(hResource) always return 4 (integers have 4 bytes in length)....
Vailton Renato
User avatar
vailtom
 
Posts: 47
Joined: Thu Jan 05, 2006 6:56 pm

Re: cResToStr help needed

Postby Antonio Linares » Fri Apr 17, 2009 2: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cResToStr help needed

Postby toninhofwi » Fri Apr 17, 2009 4: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: Select all  Expand view
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: Select all  Expand view
? Len( crestostr( 7777, "BITMAP" ) )



This code is the original crestostr from FWH.

What is wrong please?

Regards,

Toninho.
toninhofwi
 
Posts: 172
Joined: Tue Oct 18, 2005 10:01 am

Re: cResToStr help needed

Postby Antonio Linares » Fri Apr 17, 2009 7:16 pm

Toninho,

Have you tried SizeofResource() instead of GlobalSize() ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cResToStr help needed

Postby toninhofwi » Fri Apr 17, 2009 7: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.
toninhofwi
 
Posts: 172
Joined: Tue Oct 18, 2005 10:01 am

Re: cResToStr help needed

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cResToStr help needed

Postby toninhofwi » Sat Apr 18, 2009 4:15 pm

Hi Antonio,

This is the right code:

Code: Select all  Expand view
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.
toninhofwi
 
Posts: 172
Joined: Tue Oct 18, 2005 10:01 am

Re: cResToStr working function

Postby Antonio Linares » Sat Apr 18, 2009 11:18 pm

very good :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 96 guests