Commit c775e1ec authored by Richard Cohen's avatar Richard Cohen Committed by Alexandre Julliard

Wrap an exception handler around FindResource.

parent 72e1be10
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "winuser.h" #include "winuser.h"
#include "wine/winbase16.h" #include "wine/winbase16.h"
#include "wine/winuser16.h" #include "wine/winuser16.h"
#include "wine/exception.h"
#include "ldt.h" #include "ldt.h"
#include "global.h" #include "global.h"
#include "heap.h" #include "heap.h"
...@@ -124,84 +125,111 @@ static WORD MapHRsrc16ToType( NE_MODULE *pModule, HRSRC16 hRsrc16 ) ...@@ -124,84 +125,111 @@ static WORD MapHRsrc16ToType( NE_MODULE *pModule, HRSRC16 hRsrc16 )
} }
/********************************************************************** /* filter for page-fault exceptions */
* RES_FindResource static WINE_EXCEPTION_FILTER(page_fault)
*/
static HRSRC RES_FindResource( HMODULE hModule, LPCSTR type,
LPCSTR name, WORD lang,
BOOL bUnicode, BOOL bRet16 )
{ {
HRSRC hRsrc = 0; if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
return EXCEPTION_EXECUTE_HANDLER;
return EXCEPTION_CONTINUE_SEARCH;
}
static HRSRC RES_FindResource2( HMODULE hModule, LPCSTR type,
LPCSTR name, WORD lang,
BOOL bUnicode, BOOL bRet16 )
{
HRSRC hRsrc = 0;
HMODULE16 hMod16 = MapHModuleLS( hModule ); HMODULE16 hMod16 = MapHModuleLS( hModule );
NE_MODULE *pModule = NE_GetPtr( hMod16 ); NE_MODULE *pModule = NE_GetPtr( hMod16 );
WINE_MODREF *wm = pModule && pModule->module32? WINE_MODREF *wm = pModule && pModule->module32?
MODULE32_LookupHMODULE( pModule->module32 ) : NULL; MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
TRACE("(%08x %s, %08x%s, %08x%s, %04x, %s, %s)\n", TRACE("(%08x %s, %08x%s, %08x%s, %04x, %s, %s)\n",
hModule, hModule,
pModule ? (char *)NE_MODULE_NAME(pModule) : "NULL dereference", pModule ? (char *)NE_MODULE_NAME(pModule) : "NULL dereference",
(UINT)type, HIWORD(type)? (bUnicode? debugstr_w((LPWSTR)type) : debugstr_a(type)) : "", (UINT)type, HIWORD(type)? (bUnicode? debugstr_w((LPWSTR)type) : debugstr_a(type)) : "",
(UINT)name, HIWORD(name)? (bUnicode? debugstr_w((LPWSTR)name) : debugstr_a(name)) : "", (UINT)name, HIWORD(name)? (bUnicode? debugstr_w((LPWSTR)name) : debugstr_a(name)) : "",
lang, lang,
bUnicode? "W" : "A", bUnicode? "W" : "A",
bRet16? "NE" : "PE" ); bRet16? "NE" : "PE" );
if ( !pModule ) return 0; if (pModule)
if ( wm )
{ {
/* 32-bit PE module */ if ( wm )
LPWSTR typeStr, nameStr; {
/* 32-bit PE module */
if ( HIWORD( type ) && !bUnicode ) LPWSTR typeStr, nameStr;
typeStr = HEAP_strdupAtoW( GetProcessHeap(), 0, type );
else if ( HIWORD( type ) && !bUnicode )
typeStr = (LPWSTR)type; typeStr = HEAP_strdupAtoW( GetProcessHeap(), 0, type );
if ( HIWORD( name ) && !bUnicode ) else
nameStr = HEAP_strdupAtoW( GetProcessHeap(), 0, name ); typeStr = (LPWSTR)type;
else if ( HIWORD( name ) && !bUnicode )
nameStr = (LPWSTR)name; nameStr = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
else
hRsrc = PE_FindResourceExW( wm, nameStr, typeStr, lang ); nameStr = (LPWSTR)name;
if ( HIWORD( type ) && !bUnicode ) hRsrc = PE_FindResourceExW( wm, nameStr, typeStr, lang );
HeapFree( GetProcessHeap(), 0, typeStr );
if ( HIWORD( name ) && !bUnicode ) if ( HIWORD( type ) && !bUnicode )
HeapFree( GetProcessHeap(), 0, nameStr ); HeapFree( GetProcessHeap(), 0, typeStr );
if ( HIWORD( name ) && !bUnicode )
HeapFree( GetProcessHeap(), 0, nameStr );
/* If we need to return 16-bit HRSRC, perform conversion */
if ( bRet16 )
hRsrc = MapHRsrc32To16( pModule, hRsrc,
HIWORD( type )? 0 : LOWORD( type ) );
}
else
{
/* 16-bit NE module */
LPSTR typeStr, nameStr;
if ( HIWORD( type ) && bUnicode )
typeStr = HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)type );
else
typeStr = (LPSTR)type;
if ( HIWORD( name ) && bUnicode )
nameStr = HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)name );
else
nameStr = (LPSTR)name;
hRsrc = NE_FindResource( pModule, nameStr, typeStr );
if ( HIWORD( type ) && bUnicode )
HeapFree( GetProcessHeap(), 0, typeStr );
if ( HIWORD( name ) && bUnicode )
HeapFree( GetProcessHeap(), 0, nameStr );
/* If we need to return 32-bit HRSRC, no conversion is necessary,
we simply use the 16-bit HRSRC as 32-bit HRSRC */
}
}
return hRsrc;
}
/**********************************************************************
* RES_FindResource
*/
/* If we need to return 16-bit HRSRC, perform conversion */ static HRSRC RES_FindResource( HMODULE hModule, LPCSTR type,
if ( bRet16 ) LPCSTR name, WORD lang,
hRsrc = MapHRsrc32To16( pModule, hRsrc, BOOL bUnicode, BOOL bRet16 )
HIWORD( type )? 0 : LOWORD( type ) ); {
HRSRC hRsrc;
__TRY
{
hRsrc = RES_FindResource2(hModule, type, name, lang, bUnicode, bRet16);
} }
else __EXCEPT(page_fault)
{ {
/* 16-bit NE module */ WARN("page fault\n");
LPSTR typeStr, nameStr; SetLastError(ERROR_INVALID_PARAMETER);
return 0;
if ( HIWORD( type ) && bUnicode )
typeStr = HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)type );
else
typeStr = (LPSTR)type;
if ( HIWORD( name ) && bUnicode )
nameStr = HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)name );
else
nameStr = (LPSTR)name;
hRsrc = NE_FindResource( pModule, nameStr, typeStr );
if ( HIWORD( type ) && bUnicode )
HeapFree( GetProcessHeap(), 0, typeStr );
if ( HIWORD( name ) && bUnicode )
HeapFree( GetProcessHeap(), 0, nameStr );
/* If we need to return 32-bit HRSRC, no conversion is necessary,
we simply use the 16-bit HRSRC as 32-bit HRSRC */
} }
__ENDTRY
return hRsrc; return hRsrc;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment