Page 1 of 1

Problema de FindResource con xhb.com y fwh

PostPosted: Tue Oct 25, 2011 4:20 am
by carlos vargas
Antonio, he continuado en la busqueda del error de pintado de bitmap y brush entre xhb.com y fwh.
el caso es que toda mi busqueda queda en la funcion FindResource, la cual tu me indicas que es usada la WINAPI
GetResource da valor diferente a cero, pero FindResource da cero, por eso fallan, que se podria hacer?
con xharbour.org retornan valores diferenets a cero tanto GetResources y FindResource.

Code: Select all  Expand view

#pragma BEGINDUMP

#ifndef __BORLANDC__
   #define WINVER 5
#endif

#include "hbapi.h"

#include "windows.h"

#define IF(x,y,z) ((x)?(y):(z))
HINSTANCE GetResources( void );
void PalBmpNew( HWND hWnd, HBITMAP hBitmap, HPALETTE hPalette );
HBITMAP hPalBitmapNew( HDC hDC, LPBITMAPINFO pbmi );

static HPALETTE hPalette = 0;

HB_FUNC( PALBMPLOAD ) // ( cResourceName )
{
    #ifndef UNICODE
       HRSRC  hRes = FindResource( ( HMODULE ) GetResources(),
                     IF( ISCHAR( 1 ), hb_parc( 1 ), MAKEINTRESOURCE( hb_parni( 1 ) ) ),
                     RT_BITMAP );
    #else
       LPWSTR pW = AnsiToWide( ( char * ) hb_parc( 1 ) );
       HRSRC  hRes = FindResource( ( HMODULE ) GetResources(),
                     IF( HB_ISCHAR( 1 ), pW, MAKEINTRESOURCE( hb_parni( 1 ) ) ),
                     RT_BITMAP );

    #endif
    HANDLE hResource = IF( hRes, LoadResource( GetResources(), hRes ), 0 );

    #ifdef UNICODE
       hb_xfree( pW );
    #endif

    char szDMCBug[20];
    sprintf( szDMCBug, "FindResource-->: %i\n", (LONG) FindResource( ( HMODULE ) GetResources(), hb_parc(1), RT_BITMAP  ) );
    //sprintf( szDMCBug, "GetResource-->: %i\n", (LONG) ( HMODULE ) GetResources() );

    hb_OutDebug( szDMCBug );

    if( hRes )
    {
       OutputDebugStringA("hRes OK\n");
       if( hResource)
       {
          OutputDebugStringA( "hResource OK\n"   );
       }
       else
       {
          OutputDebugStringA( "hResource FAIL\n" );
       }
    }
    else
    {
       OutputDebugStringA("hRes FAIL\n");
    }

    if( hRes )
    {
       #ifndef __FLAT__
          hb_reta( 2 );
          hb_stornl( ( LONG ) hPalBitmapNew( 0, (LPBITMAPINFO) GlobalLock( hResource ) ), -1, 1 );
          hb_stornl( ( LONG ) hPalette, -1, 2 );
          GlobalUnlock( hResource );
       #else
          hb_reta( 2 );
          hb_storvnl( ( LONG ) hPalBitmapNew( 0, ( struct tagBITMAPINFO * ) hResource ), -1, 1 );
          hb_storvnl( ( LONG ) hPalette, -1, 2 );
       #endif
       #ifndef UNICODE
          FreeResource( hResource );
       #endif
    }
    else
    {
       hb_reta( 2 );
       hb_storvnl( 0, -1, 1 );
       hb_storvnl( 0, -1, 2 );
    }

}

HB_FUNC( FINDRESOURCE ) // ( hResources, cResourceName, nResType )
{
  hb_OutDebug( "FindResource\n" );
   #ifndef UNICODE
      #ifndef _WIN64
         hb_retnl( ( LONG ) FindResource( ( HINSTANCE ) hb_parnl( 1 ),
                          hb_parc( 2 ), MAKEINTRESOURCE( hb_parni( 3 ) ) ) );
      #else
         hb_retnl( ( LONG ) FindResource( ( HINSTANCE ) hb_parnll( 1 ),
                          hb_parc( 2 ), MAKEINTRESOURCE( hb_parni( 3 ) ) ) );
      #endif
   #else
      LPWSTR pW = AnsiToWide( ( char * ) hb_parc( 2 ) );
      hb_retnl( ( LONG ) FindResource( ( HINSTANCE ) hb_parnl( 1 ),
                       pW, MAKEINTRESOURCE( hb_parni( 3 ) ) ) );
      _xfree( pW );
   #endif
}
#pragma ENDDUMP
 

Re: Antonio - Problema de FindResource con xhb.com y fwh

PostPosted: Tue Oct 25, 2011 5:43 am
by carlos vargas
Antonio, leyendo el foro encontre este post
forums.fivetechsupport.com/viewtopic.php?f=3&t=896&hilit=FINDRESOURCE


el caso es que renombrando los recursos, son reconocidos ya por las funciones involucradas, el por que?
no lo se, ni aun el post se aclara.

tu mismo estuviste involucrado en el post, dado que fue en el 2005 (ya hace algunos años) parece que se te olvido el incidente :-)

salu2
carlos vargas

Re: Problema de FindResource con xhb.com y fwh

PostPosted: Wed Oct 26, 2011 4:42 pm
by Antonio Linares
Carlos,

Ese es un viejo error conocido de Windows, por el que algunas veces, no localiza un recurso con un determinado nombre. La única solución en esos casos es cambiarles el nombre.

Como no disponemos de los fuentes de Windows pues es muy dificil saber el porqué. En todo caso se podría revisar el código fuente de Wine para esa función y ver si tambien falla. De todas formas lo más simple es cambiarle el nombre :-)

Re: Problema de FindResource con xhb.com y fwh

PostPosted: Thu Oct 27, 2011 7:52 pm
by Blessed
Hola Carlos

Yo tuve ese problema con los recursos, cambiaba el nombre del recurso, y me aparecia otro reportado por mis clientes.
Y la solucion con que di es asignar un definir en el archivo de recursos cada dialogo con un numero.

#define DLG_PRODUCTO 1


Y en el Codigo del programa incluir la definicion, ya sea directamente o con un archivo cabecera.

Code: Select all  Expand view
   DEFINE DIALOG oWndChild RESOURCE DLG_PRODUCTO
 


no con nombre de recurso, si no que con numero de recurso; no he probado directamente con Bitmaps, pero bien seria tratar.
Con los dialogos no ha sido la solucion definitiva, ya que se me dan algunos problemas, pero en menor grado que antes.

Espero te sirva.

Re: Problema de FindResource con xhb.com y fwh

PostPosted: Thu Oct 27, 2011 8:39 pm
by carlos vargas
gracias por la indicacion, algo que note tambiem es que si se usan recursos en un dll funciona sin problemas.

salu2
carlos vargas