From a876c981d91a7cb6cdceee9078e269bda85262ef Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 9 May 2011 13:28:15 +0000 Subject: [PATCH] 2011-05-09 15:25 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/wapi_misc.c ! trying to make hbwapi_LoadLibrarySystem() really safe by using LoadLibraryEx() with special flag. On win7/64 tested with 32-bit or 64-bit exe, it still tries to load f.e. winspool.drv from the apps own dir, at least as per procmon. GetSystemDirectory() will return system32 as the .dll dir, though it is SysWOW64, but this seems to be fixed internall by kernel. (safety is apparently fully going against MS's will, but anyway, maybe I'm not getting it) * contrib/hbwin/wce_simc.c * contrib/hbwin/wce_smsc.c * contrib/hbwin/hbwin.hbx * contrib/hbwin/wce_sim.prg ! fixed to always define wce (and compiler) specific .prg level functions --- harbour/ChangeLog | 17 ++++++++++++++++ harbour/contrib/hbwin/hbwin.hbx | 8 ++++++++ harbour/contrib/hbwin/wapi_misc.c | 2 +- harbour/contrib/hbwin/wce_sim.prg | 4 ---- harbour/contrib/hbwin/wce_simc.c | 34 +++++++++++++++++++++++++++---- harbour/contrib/hbwin/wce_smsc.c | 11 ++++++---- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index fe5578096b..e53d869caf 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,23 @@ The license applies to all entries newer than 2009-04-28. */ +2011-05-09 15:25 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/wapi_misc.c + ! trying to make hbwapi_LoadLibrarySystem() really safe + by using LoadLibraryEx() with special flag. On win7/64 tested + with 32-bit or 64-bit exe, it still tries to load f.e. winspool.drv + from the apps own dir, at least as per procmon. GetSystemDirectory() + will return system32 as the .dll dir, though it is SysWOW64, but + this seems to be fixed internall by kernel. + (safety is apparently fully going against MS's will, but anyway, + maybe I'm not getting it) + + * contrib/hbwin/wce_simc.c + * contrib/hbwin/wce_smsc.c + * contrib/hbwin/hbwin.hbx + * contrib/hbwin/wce_sim.prg + ! fixed to always define wce (and compiler) specific .prg level functions + 2011-05-09 13:32 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/hbwapi.h * contrib/hbwin/wapi_misc.c diff --git a/harbour/contrib/hbwin/hbwin.hbx b/harbour/contrib/hbwin/hbwin.hbx index 216ded0f2c..b3db08fb84 100644 --- a/harbour/contrib/hbwin/hbwin.hbx +++ b/harbour/contrib/hbwin/hbwin.hbx @@ -289,6 +289,14 @@ DYNAMIC WAPI_WAITFORMULTIPLEOBJECTSEX DYNAMIC WAPI_WAITFORSINGLEOBJECT DYNAMIC WAPI_WAITFORSINGLEOBJECTEX DYNAMIC WAPI_WNETGETLASTERROR +DYNAMIC WCE_SIM +DYNAMIC WCE_SIMDEINITIALIZE +DYNAMIC WCE_SIMDELETEPHONEBOOKENTRY +DYNAMIC WCE_SIMINITIALIZE +DYNAMIC WCE_SIMPHONEBOOKSTATUS +DYNAMIC WCE_SIMREADPHONEBOOKENTRY +DYNAMIC WCE_SIMWRITEPHONEBOOKENTRY +DYNAMIC WCE_SMSSENDMESSAGE DYNAMIC WIDETOANSI DYNAMIC WIN_ABORTDOC DYNAMIC WIN_ANSITOWIDE diff --git a/harbour/contrib/hbwin/wapi_misc.c b/harbour/contrib/hbwin/wapi_misc.c index afafe0759a..f85476a244 100644 --- a/harbour/contrib/hbwin/wapi_misc.c +++ b/harbour/contrib/hbwin/wapi_misc.c @@ -136,7 +136,7 @@ HMODULE hbwapi_LoadLibrarySystem( LPCTSTR pFileName ) { TCHAR * pLibPath = hbwapi_FileNameAtSystemDir( pFileName ); - HMODULE h = LoadLibrary( pLibPath ); + HMODULE h = LoadLibraryEx( pLibPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); hb_xfree( pLibPath ); diff --git a/harbour/contrib/hbwin/wce_sim.prg b/harbour/contrib/hbwin/wce_sim.prg index 9a34f5581a..91950cadf1 100644 --- a/harbour/contrib/hbwin/wce_sim.prg +++ b/harbour/contrib/hbwin/wce_sim.prg @@ -50,8 +50,6 @@ * */ -#if defined( __PLATFORM__WINCE ) - #include "hbclass.ch" #include "common.ch" @@ -231,5 +229,3 @@ METHOD End() CLASS wce_sim ENDIF RETURN NIL - -#endif diff --git a/harbour/contrib/hbwin/wce_simc.c b/harbour/contrib/hbwin/wce_simc.c index 125d748b7d..179350e772 100644 --- a/harbour/contrib/hbwin/wce_simc.c +++ b/harbour/contrib/hbwin/wce_simc.c @@ -54,25 +54,36 @@ #include "hbapiitm.h" #if defined( HB_OS_WIN_CE ) && ! defined( __MINGW32__ ) - -#include +# include +# define __HB_COMPONENT_SUPPORTED__ +#endif HB_FUNC( WCE_SIMINITIALIZE ) /* hSim by reference, lNotifications */ { +#ifdef __HB_COMPONENT_SUPPORTED__ HSIM hSim = 0; HRESULT hResult = SimInitialize( hb_parl( 2 ) ? SIM_INIT_SIMCARD_NOTIFICATIONS : 0, NULL, 0, &hSim ); hb_storptr( hResult == S_OK ? hSim : 0, 1 ); hb_retnl( hResult ); +#else + hb_storptr( 0, 1 ); + hb_retnl( -1 ); +#endif } HB_FUNC( WCE_SIMDEINITIALIZE ) /* hSim */ { +#ifdef __HB_COMPONENT_SUPPORTED__ hb_retnl( SimDeinitialize( ( HSIM ) hb_parptr( 1 ) ) ); +#else + hb_retnl( -1 ); +#endif } HB_FUNC( WCE_SIMPHONEBOOKSTATUS ) /* hSim, nLocation, @nTotal, @nUsed */ { +#ifdef __HB_COMPONENT_SUPPORTED__ DWORD dwUsed = 0, dwTotal = 0; HRESULT hResult = SimGetPhonebookStatus( ( HSIM ) hb_parptr( 1 ), ( DWORD ) hb_parnl( 2 ) /* dwLocation */, &dwUsed, &dwTotal ); @@ -80,10 +91,16 @@ HB_FUNC( WCE_SIMPHONEBOOKSTATUS ) /* hSim, nLocation, @nTotal, @nUsed */ hb_stornl( hResult == S_OK ? ( long ) dwUsed : 0, 4 ); hb_retnl( hResult ); +#else + hb_stornl( 0, 3 ); + hb_stornl( 0, 4 ); + hb_retnl( -1 ); +#endif } HB_FUNC( WCE_SIMREADPHONEBOOKENTRY ) /* hSim, nLocation, nPos, @aEntry */ { +#ifdef __HB_COMPONENT_SUPPORTED__ HSIM hSim = ( HSIM ) hb_parptr( 1 ); DWORD dwIndex = ( DWORD ) hb_parnl( 3 ); SIMPHONEBOOKENTRY PhoneEntry; @@ -102,10 +119,14 @@ HB_FUNC( WCE_SIMREADPHONEBOOKENTRY ) /* hSim, nLocation, nPos, @aEntry */ hb_itemParamStoreForward( 4, pArray ); hb_itemRelease( pArray ); +#else + hb_reta( 0 ); +#endif } HB_FUNC( WCE_SIMWRITEPHONEBOOKENTRY ) /* hSim, nLocation, nPos, cNumber, cName, nPlan, nAddrType */ { +#ifdef __HB_COMPONENT_SUPPORTED__ SIMPHONEBOOKENTRY PhoneEntry; void * hAddress; @@ -122,11 +143,16 @@ HB_FUNC( WCE_SIMWRITEPHONEBOOKENTRY ) /* hSim, nLocation, nPos, cNumber, cName, hb_strfree( hAddress ); hb_strfree( hText ); +#else + hb_retnl( -1 ); +#endif } HB_FUNC( WCE_SIMDELETEPHONEBOOKENTRY ) /* hSim, nLocation, nPos */ { +#ifdef __HB_COMPONENT_SUPPORTED__ hb_retnl( SimDeletePhonebookEntry( ( HSIM ) hb_parptr( 1 ), ( DWORD ) hb_parnl( 2 ), ( DWORD ) hb_parnl( 3 ) ) ); -} - +#else + hb_retnl( -1 ); #endif +} diff --git a/harbour/contrib/hbwin/wce_smsc.c b/harbour/contrib/hbwin/wce_smsc.c index abff8ae53f..fe5423a3fc 100644 --- a/harbour/contrib/hbwin/wce_smsc.c +++ b/harbour/contrib/hbwin/wce_smsc.c @@ -55,11 +55,13 @@ #if defined( HB_OS_WIN_CE ) && \ ! defined( __MINGW32__ ) && \ !( ! defined( __cplusplus ) && ( defined( _MSC_VER ) && ( _MSC_VER <= 1310 ) ) ) - -#include +# include +# define __HB_COMPONENT_SUPPORTED__ +#endif HB_FUNC( WCE_SMSSENDMESSAGE ) /* cMessage, cNumber */ { +#ifdef __HB_COMPONENT_SUPPORTED__ SMS_HANDLE smshHandle = 0; HRESULT hr = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL ); /* try to open an SMS Handle */ @@ -112,6 +114,7 @@ HB_FUNC( WCE_SMSSENDMESSAGE ) /* cMessage, cNumber */ SmsClose( smshHandle ); } -} - +#else + hb_retnl( -1 ); #endif +}