diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 142b7cb515..2a6ae3a618 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,59 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-02-10 12:34 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/pp/Makefile + * harbour/src/pp/hbpp.c + ! fixed compilation with HB_DYNLIB macro + + - harbour/src/vm/maindll.c + - removed unused dummy file + + * harbour/src/vm/Makefile + * harbour/include/hbapi.h + + harbour/src/vm/procaddr.c + + added hb_vmProcAddress() function + + * harbour/include/hbdefs.h + + added HB_EXPORT_ATTR and HB_IMPORT_ATTR macros - they are always + defined regardless of HB_DYNLIB macro state + + * harbour/src/vm/maindllh/Makefile + * disabled HB_DYNLIB + + * harbour/src/vm/maindllp/Makefile + + harbour/src/vm/maindllp/dllpcode.c + + added new import library for PCODE DLLs. It contains wrappers for + hb_vmProcessSymbols() and hb_vmExecute() implemented in a way + which creates minimal speed overhead. + + added error reporting (MessageBox()) when redirected functions + cannot be found. + + added hb_dllGetProcAddress() C function + + * harbour/include/hbtypes.h + - harbour/src/vm/maindllp.c + + harbour/src/vm/maindllp/dllext.c + * moved old wrappers to some of extended and array API functions + into separate file + * updated to use hb_dllGetProcAddress() + - removed functions which should not be used by user code + % cleaned, optimized and added error reporting to function wrappers. + + I do not know who chose exported functions but it looks like a + quite random set which should be extended for real functionality. + If someone is interested then he can do that. I updated this file + only for backward compatibility. + + Above modifications allows to use PCODE DLLs with any application + also static ones using Harbour compiled without exported symbols. + It's enough to link it with this function: + HB_EXPORT_ATTR PHB_FUNC dll_hb_vmProcAddress( const char * szFuncName ) + { + return hb_vmProcAddress( szFuncName ); + } + The official form of including above function to final binaries is not + defined yet. + 2010-02-10 01:00 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbide/docs/idemainpage.html * contrib/hbide/docs/multiviews.html diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 75da0c659c..c4b8d05455 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -1104,6 +1104,9 @@ extern void * hb_i18n_alloc( void * cargo ); extern HB_EXPORT void hb_vmSetLinkedMain( const char * szMain ); extern HB_EXPORT void hb_vmSetDefaultGT( const char * szGtName ); +extern HB_EXPORT PHB_FUNC hb_vmProcAddress( const char * szFuncName ); + + /* misc */ extern HB_EXPORT const char * hb_verCPU( void ); /* retrieves a constant string with CPU architecture */ extern HB_EXPORT char * hb_verPlatform( void ); /* retrieves a newly allocated buffer containing platform version */ diff --git a/harbour/include/hbdefs.h b/harbour/include/hbdefs.h index 36875da3a5..4d170935dd 100644 --- a/harbour/include/hbdefs.h +++ b/harbour/include/hbdefs.h @@ -1498,37 +1498,39 @@ typedef HB_U32 HB_FATTR; #define HB_DLL_ENTRY_POINT DllEntryPoint #endif +#if defined( __RSXNT__ ) + /* RSXNT does not support any type of export keyword. + Exported (i.e., public) names can be obtained via + the emxexp utility and the output can be used for + input to a module definition file. See emxdev.doc + in the RSXNT doc/ directory for more information. */ + #define HB_EXPORT_ATTR + +#elif defined( __GNUC__ ) && defined( HB_OS_WIN ) + #define HB_EXPORT_ATTR __attribute__ (( dllexport )) + +#elif defined( __GNUC__ ) && defined( HB_OS_LINUX ) && __GNUC__ >= 3 + #define HB_EXPORT_ATTR __attribute__ ((visibility ("default"))) + +#elif defined( __BORLANDC__ ) + #define HB_EXPORT_ATTR __declspec( dllexport ) + +#elif defined( __WATCOMC__ ) + #define HB_EXPORT_ATTR __declspec( dllexport ) + +#elif defined( ASANLM ) || defined( ASANT ) + #define HB_EXPORT_ATTR + +#elif defined( HB_OS_WIN ) + #define HB_EXPORT_ATTR _declspec( dllexport ) + +#else + #define HB_EXPORT_ATTR + +#endif + #if defined( HB_DYNLIB ) - #if defined( __RSXNT__ ) - /* RSXNT does not support any type of export keyword. - Exported (i.e., public) names can be obtained via - the emxexp utility and the output can be used for - input to a module definition file. See emxdev.doc - in the RSXNT doc/ directory for more information. */ - #define HB_EXPORT - - #elif defined( __GNUC__ ) && defined( HB_OS_WIN ) - #define HB_EXPORT __attribute__ (( dllexport )) - - #elif defined( __GNUC__ ) && defined( HB_OS_LINUX ) && __GNUC__ >= 3 - #define HB_EXPORT __attribute__ ((visibility ("default"))) - - #elif defined( __BORLANDC__ ) - #define HB_EXPORT __declspec( dllexport ) - - #elif defined( __WATCOMC__ ) - #define HB_EXPORT __declspec( dllexport ) - - #elif defined( ASANLM ) || defined( ASANT ) - #define HB_EXPORT - - #elif defined( HB_OS_WIN ) - #define HB_EXPORT _declspec( dllexport ) - - #else - #define HB_EXPORT - - #endif + #define HB_EXPORT HB_EXPORT_ATTR #else #define HB_EXPORT #endif @@ -1539,28 +1541,30 @@ typedef HB_U32 HB_FATTR; the emxexp utility and the output can be used for input to a module definition file. See emxdev.doc in the RSXNT doc/ directory for more information. */ - #define HB_IMPORT + #define HB_IMPORT_ATTR #elif defined( __GNUC__ ) && defined( HB_OS_WIN ) - #define HB_IMPORT __attribute__ (( dllimport )) + #define HB_IMPORT_ATTR __attribute__ (( dllimport )) #elif defined( __BORLANDC__ ) - #define HB_IMPORT __declspec( dllimport ) + #define HB_IMPORT_ATTR __declspec( dllimport ) #elif defined( __WATCOMC__ ) - #define HB_IMPORT __declspec( dllimport ) + #define HB_IMPORT_ATTR __declspec( dllimport ) #elif defined( ASANLM ) || defined( ASANT ) - #define HB_IMPORT + #define HB_IMPORT_ATTR #elif defined( HB_OS_WIN ) - #define HB_IMPORT _declspec( dllimport ) + #define HB_IMPORT_ATTR _declspec( dllimport ) #else - #define HB_IMPORT + #define HB_IMPORT_ATTR #endif +#define HB_IMPORT HB_IMPORT_ATTR + #if defined( HB_OS_WIN ) /* Features provided for Windows builds only */ diff --git a/harbour/include/hbtypes.h b/harbour/include/hbtypes.h index 6c17bead99..5dd559dcf4 100644 --- a/harbour/include/hbtypes.h +++ b/harbour/include/hbtypes.h @@ -55,26 +55,22 @@ #undef HB_API_MACROS -#include "hbvm.h" -#include "hbapiitm.h" +#include "hbapi.h" HB_EXTERN_BEGIN -typedef PHB_SYMB ( * VM_PROCESS_SYMBOLS ) - ( PHB_SYMB pModuleSymbols, HB_USHORT uiModuleSymbols, - const char * szModuleName, HB_ULONG ulID, HB_USHORT uiPcodeVer ); +extern PHB_FUNC hb_dllGetProcAddress( const char * szProcName ); -typedef void ( * VM_EXECUTE ) ( const HB_BYTE * pCode, PHB_SYMB pSymbols ); - -typedef HB_BOOL ( * EXT_IS_ARRAY ) ( int iParam ); -typedef char * ( * EXT_PARC1 ) ( int iParam ); -typedef char * ( * EXT_PARC2 ) ( int iParam, HB_SIZE ulArrayIndex ); +typedef int ( * HB_PCOUNT )( void ); +typedef HB_ULONG ( * HB_PARINFO )( int iParam ); +typedef HB_SIZE ( * HB_PARINFA )( int iParam, HB_SIZE nArrayIndex ); typedef PHB_ITEM ( * HB_PARAM )( int iParam, long lMask ); typedef PHB_ITEM ( * HB_PARAMERROR )( int iParam ); -typedef int ( * HB_PCOUNTS )( void ); +typedef HB_BOOL ( * HB_EXTISARRAY ) ( int iParam ); + typedef void ( * HB_RET )( void ); typedef void ( * HB_RETC )( const char * szText ); -typedef void ( * HB_RETCLEN )( const char * szText, HB_SIZE ulLen ); +typedef void ( * HB_RETCLEN )( const char * szText, HB_SIZE nLen ); typedef void ( * HB_RETDS )( const char * szDate ); typedef void ( * HB_RETD )( int iYear, int iMonth, int iDay ); typedef void ( * HB_RETDL )( long lJulian ); @@ -86,56 +82,41 @@ typedef void ( * HB_RETNLEN )( double dNumber, int iWidth, int iDec ); typedef void ( * HB_RETNDLEN )( double dNumber, int iWidth, int iDec ); typedef void ( * HB_RETNILEN )( int iNumber, int iWidth ); typedef void ( * HB_RETNLLEN )( long lNumber, int iWidth ); -typedef void ( * HB_RETA )( HB_SIZE ulLen ); -typedef HB_SIZE ( * HB_PARINFA )( int iParamNum, HB_SIZE uiArrayIndex ); -typedef HB_ULONG ( * HB_PARINFO )( int iParam ); -typedef HB_SIZE ( * HB_PARCLEN )( int iParam ); -typedef HB_SIZE ( * HB_PARCSIZ )( int iParam ); -typedef char * ( * HB_PARDS )( int iParam ); -typedef char * ( * HB_PARDSBUFF )( char * szDate,int iParam); -typedef int ( * HB_PARL )( int iParam ); -typedef double ( * HB_PARND )( int iParam ); -typedef int ( * HB_PARNI )( int iParam ); -typedef long ( * HB_PARNL )( int iParam ); -typedef HB_SIZE ( * HB_PARCLEN2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef HB_SIZE ( * HB_PARCSIZ2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef char * ( * HB_PARDS2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef char * ( * HB_PARDSBUFF2 )( char * szDate,int iParam, HB_SIZE ulArrayIndex ); -typedef int ( * HB_PARL2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef double ( * HB_PARND2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef int ( * HB_PARNI2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef long ( * HB_PARNL2 )( int iParam, HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORC )( const char * szText, int iParam ); -typedef int ( * HB_STORCLEN )( const char * szText, HB_SIZE ulLength, int iParam ); -typedef int ( * HB_STORDS )( const char * szDate, int iParam ); -typedef int ( * HB_STORL )( int iLogical, int iParam ); -typedef int ( * HB_STORNI )( int iValue, int iParam ); -typedef int ( * HB_STORNL )( long lValue, int iParam ); -typedef int ( * HB_STORND )( double dValue, int iParam ); -typedef int ( * HB_STORC2 )( const char * szText, int iParam , HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORCLEN2 )( const char * szText, HB_SIZE ulLength, int iParam , HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORDS2 )( const char * szDate, int iParam , HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORL2 )( int iLogical, int iParam , HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORNI2 )( int iValue, int iParam , HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORNL2 )( long lValue, int iParam , HB_SIZE ulArrayIndex ); -typedef int ( * HB_STORND2 )( double dValue, int iParam , HB_SIZE ulArrayIndex ); -typedef HB_BOOL ( * HB_ARRAYNEW )( PHB_ITEM pItem, HB_SIZE ulLen ); +typedef void ( * HB_RETA )( HB_SIZE nLen ); + +typedef char * ( * HB_PARVC ) ( int iParam, ... ); +typedef HB_SIZE ( * HB_PARVCLEN )( int iParam, ... ); +typedef HB_SIZE ( * HB_PARVCSIZ )( int iParam, ... ); +typedef char * ( * HB_PARVDS )( int iParam, ... ); +typedef char * ( * HB_PARVDSBUFF )( char * szDate, int iParam, ... ); +typedef int ( * HB_PARVL )( int iParam, ... ); +typedef double ( * HB_PARVND )( int iParam, ... ); +typedef int ( * HB_PARVNI )( int iParam, ... ); +typedef long ( * HB_PARVNL )( int iParam, ... ); + +typedef int ( * HB_STORVC )( const char * szText, int iParam, ... ); +typedef int ( * HB_STORVCLEN )( const char * szText, HB_SIZE nLength, int iParam, ... ); +typedef int ( * HB_STORVDS )( const char * szDate, int iParam, ... ); +typedef int ( * HB_STORVL )( int iLogical, int iParam, ... ); +typedef int ( * HB_STORVNI )( int iValue, int iParam, ... ); +typedef int ( * HB_STORVNL )( long lValue, int iParam, ... ); +typedef int ( * HB_STORVND )( double dValue, int iParam, ... ); + +typedef HB_BOOL ( * HB_ARRAYNEW )( PHB_ITEM pItem, HB_SIZE nLen ); typedef HB_SIZE ( * HB_ARRAYLEN )( PHB_ITEM pArray ); typedef HB_BOOL ( * HB_ARRAYISOBJECT )( PHB_ITEM pArray ); typedef HB_BOOL ( * HB_ARRAYADD )( PHB_ITEM pArray, PHB_ITEM pItemValue ); -typedef HB_BOOL ( * HB_ARRAYINS )( PHB_ITEM pArray, HB_SIZE ulIndex ); -typedef HB_BOOL ( * HB_ARRAYDEL )( PHB_ITEM pArray, HB_SIZE ulIndex ); -typedef HB_BOOL ( * HB_ARRAYSIZE )( PHB_ITEM pArray, HB_SIZE ulLen ); +typedef HB_BOOL ( * HB_ARRAYINS )( PHB_ITEM pArray, HB_SIZE nIndex ); +typedef HB_BOOL ( * HB_ARRAYDEL )( PHB_ITEM pArray, HB_SIZE nIndex ); +typedef HB_BOOL ( * HB_ARRAYSIZE )( PHB_ITEM pArray, HB_SIZE nLen ); typedef HB_BOOL ( * HB_ARRAYLAST )( PHB_ITEM pArray, PHB_ITEM pResult ); -typedef HB_BOOL ( * HB_ARRAYSET )( PHB_ITEM pArray, HB_SIZE ulIndex, PHB_ITEM pItem ); -typedef HB_BOOL ( * HB_ARRAYGET )( PHB_ITEM pArray, HB_SIZE ulIndex, PHB_ITEM pItem ); -typedef void ( * HB_XINIT )( void ); /* Initialize fixed memory subsystem */ -typedef void ( * HB_XEXIT )( void ); /* Deinitialize fixed memory subsystem */ -typedef void * ( * HB_XALLOC )( HB_ULONG ulSize ); /* allocates memory, returns NULL on failure */ -typedef void * ( * HB_XGRAB )( HB_ULONG ulSize ); /* allocates memory, exits on failure */ +typedef HB_BOOL ( * HB_ARRAYSET )( PHB_ITEM pArray, HB_SIZE nIndex, PHB_ITEM pItem ); +typedef HB_BOOL ( * HB_ARRAYGET )( PHB_ITEM pArray, HB_SIZE nIndex, PHB_ITEM pItem ); + +typedef void * ( * HB_XALLOC )( HB_SIZE nSize ); /* allocates memory, returns NULL on failure */ +typedef void * ( * HB_XGRAB )( HB_SIZE nSize ); /* allocates memory, exits on failure */ typedef void ( * HB_XFREE )( void * pMem ); /* frees memory */ -typedef void * ( * HB_XREALLOC )( void * pMem, HB_ULONG ulSize ); /* reallocates memory */ -typedef HB_ULONG ( * HB_XSIZE )( void * pMem ); /* returns the size of an allocated memory block */ +typedef void * ( * HB_XREALLOC )( void * pMem, HB_SIZE nSize ); /* reallocates memory */ HB_EXTERN_END diff --git a/harbour/src/pp/Makefile b/harbour/src/pp/Makefile index a76daab3a7..0cd7258c9c 100644 --- a/harbour/src/pp/Makefile +++ b/harbour/src/pp/Makefile @@ -30,7 +30,7 @@ vpath hbpp$(BIN_EXT) $(BIN_DIR) pptable.c : hbpp$(BIN_EXT) $(HB_HOST_BIN_DIR)/hbpp$(HB_HOST_BIN_EXT) $(TOP)$(ROOT)include/hbstdgen.ch -opptable.c -q -c$(TOP)$(ROOT) -v$(HB_VERHEADER) - -@$(RM) hbpp$(OBJ_EXT) + -@$(RM) hbpp$(OBJ_EXT) $(if $(OBJ_DYN_POSTFIX),hbpp$(OBJ_DYN_POSTFIX)$(OBJ_EXT),) ifneq ($(HB_BUILD_PARTS),lib) ifneq ($(HB_BIN_INSTALL),) diff --git a/harbour/src/pp/hbpp.c b/harbour/src/pp/hbpp.c index 05c0d841d6..a43150791c 100644 --- a/harbour/src/pp/hbpp.c +++ b/harbour/src/pp/hbpp.c @@ -52,11 +52,6 @@ * */ -/* NOTE: Trick to exclude content of this non-lib object from dynamic lib - generation. It's difficult to prevent it not being picked, so - we disable any content for the object created for dynamic lib. */ -#if ! defined( HB_DYNLIB ) - #include "hbapi.h" int hb_verSvnID( void ) { return 0; } @@ -832,5 +827,3 @@ int main( int argc, char * argv[] ) #if defined( HB_OS_WIN_CE ) && !defined( __CEGCC__ ) # include "hbwmain.c" #endif - -#endif diff --git a/harbour/src/vm/Makefile b/harbour/src/vm/Makefile index 4037c7b270..80aff91f01 100644 --- a/harbour/src/vm/Makefile +++ b/harbour/src/vm/Makefile @@ -102,6 +102,7 @@ C_SOURCES += \ pcount.c \ pvalue.c \ proc.c \ + procaddr.c \ runner.c \ vm.c \ $(C_MAIN) \ diff --git a/harbour/src/vm/maindll.c b/harbour/src/vm/maindll.c deleted file mode 100644 index aa1f9c16e0..0000000000 --- a/harbour/src/vm/maindll.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * Windows self-contained DLL entry point - * - * Copyright 1999 Antonio Linares - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version, with one exception: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbvm.h" -#include "hbapiitm.h" - -#if defined( HB_OS_WIN ) - #include -#endif - -#if defined( HB_OS_WIN ) - -HB_EXPORT BOOL WINAPI DllEntryPoint( HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved ); - -BOOL WINAPI DllEntryPoint( HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved ) -{ - HB_TRACE( HB_TR_DEBUG, ("DllEntryPoint(%p, %p, %p)", hInstance, fdwReason, - pvReserved ) ); - - HB_SYMBOL_UNUSED( hInstance ); - HB_SYMBOL_UNUSED( fdwReason ); - HB_SYMBOL_UNUSED( pvReserved ); - - switch( fdwReason ) - { - case DLL_PROCESS_ATTACH: - hb_vmInit( HB_FALSE ); /* Don't execute first linked symbol */ - break; - - case DLL_PROCESS_DETACH: - hb_vmQuit(); - break; - } - - return TRUE; -} - -LONG PASCAL HBDLLENTRY( const char * cProcName ) -{ - hb_itemDoC( cProcName, 0, 0 ); - - return 0; -} - -LONG PASCAL HBDLLENTRY1( const char * cProcName, void * pItem ) -{ - hb_itemDoC( cProcName, 1, ( PHB_ITEM ) pItem, 0 ); - - return 0; -} - -LONG PASCAL HBDLLENTRY2( const char * cProcName, void * pItem1, void * pItem2 ) -{ - hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 ); - - return 0; -} - -#endif diff --git a/harbour/src/vm/maindllh/Makefile b/harbour/src/vm/maindllh/Makefile index b8ccb698e6..6051d07754 100644 --- a/harbour/src/vm/maindllh/Makefile +++ b/harbour/src/vm/maindllh/Makefile @@ -13,7 +13,4 @@ C_SOURCES := \ LIBNAME := hbmaindllh -# always export symbols -HB_CFLAGS += -DHB_DYNLIB - include $(TOP)$(ROOT)config/lib.mk diff --git a/harbour/src/vm/maindllp.c b/harbour/src/vm/maindllp.c deleted file mode 100644 index 159fa13b51..0000000000 --- a/harbour/src/vm/maindllp.c +++ /dev/null @@ -1,866 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * Windows pcode DLL entry point and VM/RTL routing functions - * - * Copyright 2001 Antonio Linares - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version, with one exception: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbtypes.h" - -#if defined( HB_OS_WIN ) - #include -#endif - -#define HB_DLL_PREF TEXT( "harbour" ) -#define HB_DLL_PREF_MT TEXT( "harbourmt" ) -#define HB_DLL_VER TEXT( "-" ) TEXT( HB_MACRO2STRING( HB_VER_MAJOR ) ) TEXT( HB_MACRO2STRING( HB_VER_MINOR ) ) -#define HB_DLL_EXT TEXT( ".dll" ) - -#define HB_DLL_NAME HB_DLL_PREF HB_DLL_EXT -#define HB_DLL_NAMEMT HB_DLL_PREF_MT HB_DLL_EXT - -#if defined( HB_OS_WIN_CE ) && defined( HB_CPU_ARM ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-arm" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-arm" ) HB_DLL_EXT -#elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_MIPS ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-mips" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-mips" ) HB_DLL_EXT -#elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_SH ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-sh" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-sh" ) HB_DLL_EXT -#elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_X86 ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-x86" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-x86" ) HB_DLL_EXT -#elif defined( HB_OS_WIN_CE ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce" ) HB_DLL_EXT -#elif defined( __BORLANDC__ ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-bcc" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-bcc" ) HB_DLL_EXT -#elif defined( HB_OS_WIN_64 ) && defined( HB_CPU_X86_64 ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-x64" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-x64" ) HB_DLL_EXT -#elif defined( HB_OS_WIN_64 ) && defined( HB_CPU_IA_64 ) - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-ia64" ) HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-ia64" ) HB_DLL_EXT -#else - #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER HB_DLL_EXT - #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER HB_DLL_EXT -#endif - -#if defined( HB_OS_WIN ) -HB_EXTERN_BEGIN - -#if defined( HB_OS_WIN_CE ) -static FARPROC hb_getProcAddress( LPCTSTR szProcName ) -#else -static FARPROC hb_getProcAddress( LPCSTR szProcName ) -#endif -{ - static HMODULE s_hModule = NULL; - FARPROC pProcAddr = NULL; - - if( s_hModule == NULL ) - { - s_hModule = GetModuleHandle( HB_DLL_NAME ); - if( s_hModule == NULL ) - s_hModule = GetModuleHandle( HB_DLL_NAMEMT ); - if( s_hModule == NULL ) - s_hModule = GetModuleHandle( HB_DLL_NAME2 ); - if( s_hModule == NULL ) - s_hModule = GetModuleHandle( HB_DLL_NAMEMT2 ); - if( s_hModule == NULL ) - s_hModule = GetModuleHandle( NULL ); - } - - if( s_hModule ) - { - pProcAddr = GetProcAddress( s_hModule, szProcName ); - if( pProcAddr == NULL && szProcName[ 0 ] == '_' ) - pProcAddr = GetProcAddress( s_hModule, szProcName + 1 ); - } - - /* TODO: display error message, hb_errInternal() is not accessible here */ - /* - if( pProcAddr == NULL ) - hb_errInternal( 9997, "Cannot find address for function %s", szProcName, NULL ); - */ - - return pProcAddr; -} - -#if defined( HB_OS_WIN_CE ) && ( defined( _MSC_VER ) || defined( __POCC__ ) ) -HB_EXPORT BOOL WINAPI HB_DLL_ENTRY_POINT( HANDLE hInstance, DWORD fdwReason, PVOID pvReserved ) -#else -HB_EXPORT BOOL WINAPI HB_DLL_ENTRY_POINT( HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved ) -#endif -{ - HB_TRACE( HB_TR_DEBUG, ("DllEntryPoint(%p, %lu, %p)", hInstance, fdwReason, - pvReserved ) ); - - HB_SYMBOL_UNUSED( hInstance ); - HB_SYMBOL_UNUSED( fdwReason ); - HB_SYMBOL_UNUSED( pvReserved ); - - switch( fdwReason ) - { - case DLL_PROCESS_ATTACH: - break; - - case DLL_PROCESS_DETACH: - break; - } - - return TRUE; -} - -/* module symbols initialization with extended information */ -PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, HB_USHORT uiSymbols, const char * szModuleName, HB_ULONG ulID, HB_USHORT uiPcodeVer ) -{ - static FARPROC s_pProcessSymbols = NULL; - - if( !s_pProcessSymbols ) - s_pProcessSymbols = hb_getProcAddress( HBTEXT( "_hb_vmProcessDynLibSymbols" ) ); - - if( s_pProcessSymbols ) - return ( ( VM_PROCESS_SYMBOLS ) s_pProcessSymbols ) - ( pSymbols, uiSymbols, szModuleName, ulID, uiPcodeVer ); - /* else - * may we issue an error ? */ - - return pSymbols; -} - -/* execute PCODE function */ -void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols ) -{ - static FARPROC s_pExecute = NULL; - - if( !s_pExecute ) - s_pExecute = hb_getProcAddress( HBTEXT( "_hb_vmExecute" ) ); - - if( s_pExecute ) - ( ( VM_EXECUTE ) s_pExecute )( pCode, pSymbols ); - - /* else - * may we issue an error ? */ -} - - -/* extend API implementation for pcode DLLs */ - -const char * hb_parvc( int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pParC = hb_getProcAddress( HBTEXT( "_hb_parvc" ) ); - - if( pExtIsArray && pParC ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( EXT_PARC2 ) pParC )( iParam, ulArrayIndex ); - } - else - return ( ( EXT_PARC1 ) pParC )( iParam ); - } - - return NULL; -} - -PHB_ITEM hb_param( int iParam, long lMask ) /* retrieve a generic parameter */ -{ - FARPROC pParam = hb_getProcAddress( HBTEXT( "_hb_param" ) ); - return pParam ? ( ( HB_PARAM ) pParam )( iParam, lMask ) : NULL; -} - -PHB_ITEM hb_paramError( int iParam ) /* Returns either the generic parameter or a NIL item if param not provided */ -{ - FARPROC pParamError = hb_getProcAddress( HBTEXT( "_hb_paramError" ) ); - return pParamError ? ( ( HB_PARAMERROR ) pParamError )( iParam ) : NULL; -} -int hb_pcount( void ) /* returns the number of suplied parameters */ -{ - FARPROC pCounts = hb_getProcAddress( HBTEXT( "_hb_pcount" ) ); - return pCounts ? ( ( HB_PCOUNTS ) pCounts )() : 0; -} - -void hb_retc( const char * szText ) /* returns a string */ -{ - FARPROC pRetc = hb_getProcAddress( HBTEXT( "_hb_retc" ) ); - if( pRetc ) - ( ( HB_RETC ) pRetc )( szText ); -} - -void hb_retclen( const char * szText, HB_SIZE ulLen ) /* returns a string with a specific length */ -{ - FARPROC pRetclen = hb_getProcAddress( HBTEXT( "_hb_retclen" ) ); - if( pRetclen ) - ( ( HB_RETCLEN ) pRetclen )( szText, ulLen ); -} - -void hb_retds( const char * szDate ) /* returns a date, must use yyyymmdd format */ -{ - FARPROC pRetds = hb_getProcAddress( HBTEXT( "_hb_retds" ) ); - if( pRetds ) - ( ( HB_RETDS ) pRetds )( szDate ); -} - -void hb_retd( int iYear, int iMonth, int iDay ) /* returns a date */ -{ - FARPROC pRetd = hb_getProcAddress( HBTEXT( "_hb_retd" ) ); - if( pRetd ) - ( ( HB_RETD ) pRetd )( iYear, iMonth, iDay ); -} - -void hb_retdl( long lJulian ) /* returns a long value as a julian date */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retdl" ) ); - if( pRet ) - ( ( HB_RETDL ) pRet )( lJulian ); -} - -void hb_retl( int iTrueFalse ) /* returns a logical integer */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retl" ) ); - if( pRet ) - ( ( HB_RETDL ) pRet )( iTrueFalse ); -} - -void hb_retnd( double dNumber ) /* returns a double */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retnd" ) ); - if( pRet ) - ( ( HB_RETND ) pRet )( dNumber ); -} - -void hb_retni( int iNumber ) /* returns a integer number */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retni" ) ); - if( pRet ) - ( ( HB_RETNI ) pRet )( iNumber ); -} - -void hb_retnl( long lNumber ) /* returns a long number */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retnl" ) ); - if( pRet ) - ( ( HB_RETNL ) pRet )( lNumber ); -} - -void hb_retnlen( double dNumber, int iWidth, int iDec ) /* returns a double, with specific width and decimals */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retnlen" ) ); - if( pRet ) - ( ( HB_RETNLEN ) pRet )( dNumber, iWidth, iDec ); -} - -void hb_retndlen( double dNumber, int iWidth, int iDec ) /* returns a double, with specific width and decimals */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retndlen" ) ); - if( pRet ) - ( ( HB_RETNDLEN ) pRet )( dNumber, iWidth, iDec ); -} - -void hb_retnilen( int iNumber, int iWidth ) /* returns a integer number, with specific width */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retnilen" ) ); - if( pRet ) - ( ( HB_RETNILEN ) pRet )( iNumber, iWidth ); -} - -void hb_retnllen( long lNumber, int iWidth ) /* returns a long number, with specific width */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_retnilen" ) ); - if( pRet ) - ( ( HB_RETNLLEN ) pRet )( lNumber, iWidth ); -} - -void hb_reta( HB_SIZE ulLen ) /* returns an array with a specific length */ -{ - FARPROC pRet = hb_getProcAddress( HBTEXT( "_hb_reta" ) ); - if( pRet ) - ( ( HB_RETA ) pRet )( ulLen ); -} - -HB_SIZE hb_parinfa( int iParamNum, HB_SIZE uiArrayIndex ) /* retrieve length or element type of an array parameter */ -{ - FARPROC pParinfa = hb_getProcAddress( HBTEXT( "_hb_parinfa" ) ); - return pParinfa ? ( ( HB_PARINFA ) pParinfa )( iParamNum, uiArrayIndex ) : 0; -} - -HB_ULONG hb_parinfo( int iParam ) /* Determine the param count or data type */ -{ - FARPROC pParinfo = hb_getProcAddress( HBTEXT( "_hb_parinfo" ) ); - return pParinfo ? ( ( HB_PARINFO ) pParinfo )( iParam ) : 0; -} - -HB_SIZE hb_parvclen( int iParam, ... ) /* retrieve a string parameter length */ -{ - FARPROC pParC = hb_getProcAddress( HBTEXT( "_hb_parvclen" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - if( pExtIsArray && pParC ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARCLEN2 ) pParC )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARCLEN ) pParC )( iParam ); - } - - return 0; -} - -HB_SIZE hb_parvcsiz( int iParam, ... )/* retrieve a by-reference string parameter length, including terminator */ -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pParcSiz = hb_getProcAddress( HBTEXT( "_hb_parvcsiz" ) ); - - if( pExtIsArray && pParcSiz ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARCSIZ2 ) pParcSiz )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARCSIZ ) pParcSiz )( iParam ); - } - - return 0; -} - -const char * hb_parvds( int iParam, ... ) /* retrieve a date as a string yyyymmdd */ -{ - FARPROC pParDs = hb_getProcAddress( HBTEXT( "_hb_parvds" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - - if( pExtIsArray && pParDs ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARDS2 ) pParDs )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARDS ) pParDs )( iParam ); - } - - return ""; -} - -char * hb_parvdsbuff( char * szDate, int iParam, ... ) /* retrieve a date as a string yyyymmdd */ -{ - FARPROC pParDsBuff = hb_getProcAddress( HBTEXT( "_hb_parvdsbuff" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - - if( pExtIsArray && pParDsBuff ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARDSBUFF2 ) pParDsBuff )( szDate, iParam, ulArrayIndex ); - } - else - return ( ( HB_PARDSBUFF ) pParDsBuff )( szDate, iParam ); - } - - return szDate; -} - -int hb_parvl( int iParam, ... ) /* retrieve a logical parameter as an int */ -{ - /* int iReturn; */ - FARPROC pParL = hb_getProcAddress( HBTEXT( "_hb_parvl" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - - if( pExtIsArray && pParL ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARL2 ) pParL )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARL ) pParL )( iParam ); - } - - return 0; -} - -double hb_parvnd( int iParam, ... ) /* retrieve a numeric parameter as a double */ -{ - FARPROC pParNd = hb_getProcAddress( HBTEXT( "_hb_parvnd" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - - if( pExtIsArray && pParNd ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARND2 ) pParNd )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARND ) pParNd )( iParam ); - } - - return 0; -} - -int hb_parvni( int iParam, ... ) /* retrieve a numeric parameter as a integer */ -{ - /* int iReturn; */ - FARPROC pParNi = hb_getProcAddress( HBTEXT( "_hb_parvni" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - - if( pExtIsArray && pParNi ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARNI2 ) pParNi )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARNI ) pParNi )( iParam ); - } - - return 0; -} - -long hb_parvnl( int iParam, ... ) /* retrieve a numeric parameter as a long */ -{ - FARPROC pParNl = hb_getProcAddress( HBTEXT( "_hb_parvnl" ) ); - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - - if( pExtIsArray && pParNl ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - return ( ( HB_PARNL2 ) pParNl )( iParam, ulArrayIndex ); - } - else - return ( ( HB_PARNL ) pParNl )( iParam ); - } - - return 0; -} - -int hb_storvc( const char * szText, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorC = hb_getProcAddress( HBTEXT( "_hb_storvc" ) ); - - if( pExtIsArray && pStorC ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORC2 ) pStorC )( szText, iParam, ulArrayIndex ); - return 1; - } - else - { - ( ( HB_STORC ) pStorC )( szText, iParam ); - return 1; - } - } - - return 0; -} - -int hb_storvclen( const char * szText, HB_SIZE ulLen, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorC = hb_getProcAddress( HBTEXT( "_hb_storvclen" ) ); - - if( pExtIsArray && pStorC ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORCLEN2 ) pStorC )( szText, ulLen, iParam, ulArrayIndex ); - return 1; - } - else - { - ( ( HB_STORCLEN ) pStorC )( szText, ulLen, iParam ); - return 1; - } - } - - return 0; -} - -int hb_storvds( const char * szDate, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorDs = hb_getProcAddress( HBTEXT( "_hb_storvds" ) ); - - if( pExtIsArray && pStorDs ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORDS2 ) pStorDs )( szDate, iParam, ulArrayIndex ); - - return 1; - } - else - { - ( ( HB_STORDS ) pStorDs )( szDate, iParam ); - return 1; - } - } - - return 0; -} - -int hb_storvl( int iLogical, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorL = hb_getProcAddress( HBTEXT( "_hb_storvl" ) ); - - if( pExtIsArray && pStorL ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORL2 ) pStorL )( iLogical, iParam, ulArrayIndex ); - return 1; - } - else - { - ( ( HB_STORL ) pStorL )( iLogical, iParam ); - return 1; - } - } - - return 0; -} - -int hb_storvni( int iValue, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorNi = hb_getProcAddress( HBTEXT( "_hb_storvni" ) ); - - if( pExtIsArray && pStorNi ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORNI2 ) pStorNi )( iValue, iParam, ulArrayIndex ); - return 1; - } - else - { - ( ( HB_STORNI ) pStorNi )( iValue, iParam ); - return 1; - } - } - - return 0; -} - -int hb_storvnl( long lValue, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorNl = hb_getProcAddress( HBTEXT( "_hb_storvnl" ) ); - - if( pExtIsArray && pStorNl ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORNL2 ) pStorNl )( lValue, iParam, ulArrayIndex ); - return 1; - } - else - { - ( ( HB_STORNL ) pStorNl )( lValue, iParam ); - return 1; - } - } - - return 0; -} - -int hb_storvnd( double dNumber, int iParam, ... ) -{ - FARPROC pExtIsArray = hb_getProcAddress( HBTEXT( "_hb_extIsArray" ) ); - FARPROC pStorNd = hb_getProcAddress( HBTEXT( "_hb_storvnd" ) ); - - if( pExtIsArray && pStorNd ) - { - if( ( ( EXT_IS_ARRAY ) pExtIsArray ) ( iParam ) ) - { - va_list va; - HB_SIZE ulArrayIndex; - - va_start( va, iParam ); - ulArrayIndex = va_arg( va, HB_SIZE ); - va_end( va ); - - ( ( HB_STORND2 ) pStorNd )( dNumber, iParam, ulArrayIndex ); - return 1; - } - else - { - ( ( HB_STORND ) pStorNd )( dNumber, iParam ); - return 1; - } - } - - return 0; -} - -HB_BOOL hb_arrayNew( PHB_ITEM pItem, HB_SIZE ulLen ) /* creates a new array */ -{ - HB_ARRAYNEW pArrayNew = ( HB_ARRAYNEW ) hb_getProcAddress( HBTEXT( "_hb_arrayNew" ) ); - return pArrayNew ? pArrayNew( pItem, ulLen ) : HB_FALSE; -} - -HB_SIZE hb_arrayLen( PHB_ITEM pArray ) /* retrives the array len */ -{ - HB_ARRAYLEN pArrayLen = ( HB_ARRAYLEN ) hb_getProcAddress( HBTEXT( "_hb_arrayLen" ) ); - return pArrayLen ? pArrayLen( pArray ) : 0; -} - -HB_BOOL hb_arrayIsObject( PHB_ITEM pArray ) /* retrives if the array is an object */ -{ - HB_ARRAYISOBJECT pArrayIsObject = ( HB_ARRAYISOBJECT ) hb_getProcAddress( HBTEXT( "_hb_arrayIsObject" ) ); - return pArrayIsObject ? pArrayIsObject( pArray ) : HB_FALSE; -} - -HB_BOOL hb_arrayAdd( PHB_ITEM pArray, PHB_ITEM pItemValue ) /* add a new item to the end of an array item */ -{ - HB_ARRAYADD pArrayAdd = ( HB_ARRAYADD ) hb_getProcAddress( HBTEXT( "_hb_arrayAdd" ) ); - return pArrayAdd ? pArrayAdd( pArray, pItemValue ) : HB_FALSE; -} - -HB_BOOL hb_arrayIns( PHB_ITEM pArray, HB_SIZE ulIndex ) /* insert a nil item into an array, without changing the length */ -{ - HB_ARRAYINS pArrayIns = ( HB_ARRAYINS ) hb_getProcAddress( HBTEXT( "_hb_arrayIns" ) ); - return pArrayIns ? pArrayIns( pArray, ulIndex ) : HB_FALSE; -} - -HB_BOOL hb_arrayDel( PHB_ITEM pArray, HB_SIZE ulIndex ) /* delete an array item, without changing length */ -{ - HB_ARRAYDEL pArrayDel = ( HB_ARRAYDEL ) hb_getProcAddress( HBTEXT( "_hb_arrayDel" ) ); - return pArrayDel ? pArrayDel( pArray, ulIndex ) : HB_FALSE; -} - -HB_BOOL hb_arraySize( PHB_ITEM pArray, HB_SIZE ulLen ) /* sets the array total length */ -{ - HB_ARRAYSIZE pArraySize = ( HB_ARRAYSIZE ) hb_getProcAddress( HBTEXT( "_hb_arraySize" ) ); - return pArraySize ? pArraySize( pArray, ulLen ) : HB_FALSE; -} - -HB_BOOL hb_arrayLast( PHB_ITEM pArray, PHB_ITEM pResult ) /* retrieve last item in an array */ -{ - HB_ARRAYLAST pArrayLast = ( HB_ARRAYLAST ) hb_getProcAddress( HBTEXT( "_hb_arrayLast" ) ); - return pArrayLast ? pArrayLast( pArray, pResult ) : HB_FALSE; -} - -HB_BOOL hb_arraySet( PHB_ITEM pArray, HB_SIZE ulIndex, PHB_ITEM pItem ) /* sets an array element */ -{ - HB_ARRAYSET pArraySet = ( HB_ARRAYSET ) hb_getProcAddress( HBTEXT( "_hb_arraySet" ) ); - return pArraySet ? pArraySet( pArray, ulIndex, pItem ) : HB_FALSE; -} - -HB_BOOL hb_arrayGet( PHB_ITEM pArray, HB_SIZE ulIndex, PHB_ITEM pItem ) /* retrieves an item */ -{ - HB_ARRAYGET pArrayGet = ( HB_ARRAYGET ) hb_getProcAddress( HBTEXT( "_hb_arrayGet" ) ); - return pArrayGet ? pArrayGet( pArray, ulIndex, pItem ) : HB_FALSE; -} - -void hb_xinit( void ) /* Initialize fixed memory subsystem */ -{ - HB_XINIT pXinit = ( HB_XINIT ) hb_getProcAddress( HBTEXT( "_hb_xinit" ) ); - if( pXinit ) - pXinit(); -} - -void hb_xexit( void ) /* Deinitialize fixed memory subsystem */ -{ - HB_XEXIT pXexit = ( HB_XEXIT ) hb_getProcAddress( HBTEXT( "_hb_xexit" ) ); - if( pXexit ) - pXexit(); -} - -void * hb_xalloc( HB_ULONG ulSize ) /* allocates memory, returns NULL on failure */ -{ - HB_XALLOC pXalloc = ( HB_XALLOC ) hb_getProcAddress( HBTEXT( "_hb_xalloc" ) ); - return pXalloc ? pXalloc( ulSize ) : NULL; -} - -void * hb_xgrab( HB_ULONG ulSize ) /* allocates memory, exits on failure */ -{ - HB_XGRAB pXgrab = ( HB_XGRAB ) hb_getProcAddress( HBTEXT( "_hb_xgrab" ) ); - return pXgrab ? pXgrab( ulSize ) : NULL; -} - -void hb_xfree( void * pMem ) /* frees memory */ -{ - HB_XFREE pXfree = ( HB_XFREE ) hb_getProcAddress( HBTEXT( "_hb_xfree" ) ); - if( pXfree ) - pXfree( pMem ); -} - -void * hb_xrealloc( void * pMem, HB_ULONG ulSize ) /* reallocates memory */ -{ - HB_XREALLOC pXrealloc = ( HB_XREALLOC ) hb_getProcAddress( HBTEXT( "_hb_xrealloc" ) ); - return pXrealloc ? ( void * ) pXrealloc( pMem, ulSize ) : NULL; -} - -HB_ULONG hb_xsize( void * pMem ) /* returns the size of an allocated memory block */ -{ - HB_XSIZE pXsize = ( HB_XSIZE ) hb_getProcAddress( HBTEXT( "_hb_xsize" ) ); - return pXsize ? pXsize( ( void * ) pMem ) : 0; -} - -HB_EXTERN_END - -#endif diff --git a/harbour/src/vm/maindllp/Makefile b/harbour/src/vm/maindllp/Makefile index a933787301..8f8630e438 100644 --- a/harbour/src/vm/maindllp/Makefile +++ b/harbour/src/vm/maindllp/Makefile @@ -6,14 +6,10 @@ ROOT := ../../../ include $(TOP)$(ROOT)config/global.mk -vpath %.c ../ - C_SOURCES := \ - maindllp.c \ + dllpcode.c \ + dllext.c \ LIBNAME := hbmaindllp -# always export symbols -HB_CFLAGS += -DHB_DYNLIB - include $(TOP)$(ROOT)config/lib.mk diff --git a/harbour/src/vm/maindllp/dllext.c b/harbour/src/vm/maindllp/dllext.c new file mode 100644 index 0000000000..abdc266172 --- /dev/null +++ b/harbour/src/vm/maindllp/dllext.c @@ -0,0 +1,1033 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Windows pcode DLL entry point and VM/RTL routing functions + * + * Copyright 2001 Antonio Linares + * www - http://www.harbour-project.org + * + * Copyright 2010 Przemyslaw Czerpak + * rewritten + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version, with one exception: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbtypes.h" + +#if defined( HB_OS_WIN ) + +#include + +#define HB_DLL_MSG_NO_FUNC( func ) do { \ + MessageBox( NULL, \ + TEXT( "Function '" ) TEXT( func ) TEXT( "' not found!" ), \ + TEXT( func ), \ + MB_OK | MB_ICONERROR ); \ + } while( 0 ) + +int hb_pcount( void ) +{ + static HB_PCOUNT s_pcount = NULL; + + if( !s_pcount ) + { + s_pcount = ( HB_PCOUNT ) hb_dllGetProcAddress( "hb_pcount" ); + if( !s_pcount ) + HB_DLL_MSG_NO_FUNC( "hb_pcount" ); + } + + return s_pcount ? s_pcount() : 0; +} + +HB_ULONG hb_parinfo( int iParam ) +{ + static HB_PARINFO s_parinfo = NULL; + + if( !s_parinfo ) + { + s_parinfo = ( HB_PARINFO ) hb_dllGetProcAddress( "hb_parinfo" ); + if( !s_parinfo ) + HB_DLL_MSG_NO_FUNC( "hb_parinfo" ); + } + return s_parinfo ? s_parinfo( iParam ) : 0; +} + +HB_SIZE hb_parinfa( int iParam, HB_SIZE nArrayIndex ) +{ + static HB_PARINFA s_parinfa = NULL; + + if( !s_parinfa ) + { + s_parinfa = ( HB_PARINFA ) hb_dllGetProcAddress( "hb_parinfa" ); + if( !s_parinfa ) + HB_DLL_MSG_NO_FUNC( "hb_parinfa" ); + } + return s_parinfa ? s_parinfa( iParam, nArrayIndex ) : 0; +} + +PHB_ITEM hb_param( int iParam, long lMask ) +{ + static HB_PARAM s_param = NULL; + + if( !s_param ) + { + s_param = ( HB_PARAM ) hb_dllGetProcAddress( "hb_param" ); + if( !s_param ) + HB_DLL_MSG_NO_FUNC( "hb_param" ); + } + + return s_param ? s_param( iParam, lMask ) : NULL; +} + +PHB_ITEM hb_paramError( int iParam ) +{ + static HB_PARAMERROR s_paramError = NULL; + + if( !s_paramError ) + { + s_paramError = ( HB_PARAMERROR ) hb_dllGetProcAddress( "hb_paramError" ); + if( !s_paramError ) + HB_DLL_MSG_NO_FUNC( "hb_paramError" ); + } + + return s_paramError ? s_paramError( iParam ) : NULL; +} + +HB_BOOL hb_extIsArray( int iParam ) +{ + static HB_EXTISARRAY s_extIsArray = NULL; + + if( !s_extIsArray ) + { + s_extIsArray = ( HB_EXTISARRAY ) hb_dllGetProcAddress( "hb_extIsArray" ); + if( !s_extIsArray ) + HB_DLL_MSG_NO_FUNC( "hb_extIsArray" ); + } + + return s_extIsArray ? s_extIsArray( iParam ) : FALSE; +} + + +void hb_ret( void ) +{ + static HB_RET s_ret = NULL; + + if( !s_ret ) + { + s_ret = ( HB_RET ) hb_dllGetProcAddress( "hb_ret" ); + if( !s_ret ) + HB_DLL_MSG_NO_FUNC( "hb_ret" ); + } + + if( s_ret ) + s_ret(); +} + +void hb_retc( const char * szText ) +{ + static HB_RETC s_retc = NULL; + + if( !s_retc ) + { + s_retc = ( HB_RETC ) hb_dllGetProcAddress( "hb_retc" ); + if( !s_retc ) + HB_DLL_MSG_NO_FUNC( "hb_retc" ); + } + + if( s_retc ) + s_retc( szText ); +} + +void hb_retclen( const char * szText, HB_SIZE nLen ) +{ + static HB_RETCLEN s_retclen = NULL; + + if( !s_retclen ) + { + s_retclen = ( HB_RETCLEN ) hb_dllGetProcAddress( "hb_retclen" ); + if( !s_retclen ) + HB_DLL_MSG_NO_FUNC( "hb_retclen" ); + } + + if( s_retclen ) + s_retclen( szText, nLen ); +} + +void hb_retds( const char * szDate ) +{ + static HB_RETDS s_retds = NULL; + + if( !s_retds ) + { + s_retds = ( HB_RETDS ) hb_dllGetProcAddress( "hb_retds" ); + if( !s_retds ) + HB_DLL_MSG_NO_FUNC( "hb_retds" ); + } + + if( s_retds ) + s_retds( szDate ); +} + +void hb_retd( int iYear, int iMonth, int iDay ) +{ + static HB_RETD s_retd = NULL; + + if( !s_retd ) + { + s_retd = ( HB_RETD ) hb_dllGetProcAddress( "hb_retd" ); + if( !s_retd ) + HB_DLL_MSG_NO_FUNC( "hb_retd" ); + } + + if( s_retd ) + s_retd( iYear, iMonth, iDay ); +} + +void hb_retdl( long lJulian ) +{ + static HB_RETDL s_retdl = NULL; + + if( !s_retdl ) + { + s_retdl = ( HB_RETDL ) hb_dllGetProcAddress( "hb_retdl" ); + if( !s_retdl ) + HB_DLL_MSG_NO_FUNC( "hb_retdl" ); + } + + if( s_retdl ) + s_retdl( lJulian ); +} + +void hb_retl( int iValue ) +{ + static HB_RETL s_retl = NULL; + + if( !s_retl ) + { + s_retl = ( HB_RETL ) hb_dllGetProcAddress( "hb_retl" ); + if( !s_retl ) + HB_DLL_MSG_NO_FUNC( "hb_retl" ); + } + + if( s_retl ) + s_retl( iValue ); +} + +void hb_retnd( double dNumber ) +{ + static HB_RETND s_retnd = NULL; + + if( !s_retnd ) + { + s_retnd = ( HB_RETND ) hb_dllGetProcAddress( "hb_retnd" ); + if( !s_retnd ) + HB_DLL_MSG_NO_FUNC( "hb_retnd" ); + } + + if( s_retnd ) + s_retnd( dNumber ); +} + +void hb_retni( int iNumber ) +{ + static HB_RETNI s_retni = NULL; + + if( !s_retni ) + { + s_retni = ( HB_RETNI ) hb_dllGetProcAddress( "hb_retni" ); + if( !s_retni ) + HB_DLL_MSG_NO_FUNC( "hb_retni" ); + } + + if( s_retni ) + s_retni( iNumber ); +} + +void hb_retnl( long lNumber ) +{ + static HB_RETNL s_retnl = NULL; + + if( !s_retnl ) + { + s_retnl = ( HB_RETNL ) hb_dllGetProcAddress( "hb_retnl" ); + if( !s_retnl ) + HB_DLL_MSG_NO_FUNC( "hb_retnl" ); + } + + if( s_retnl ) + s_retnl( lNumber ); +} + +void hb_retnlen( double dNumber, int iWidth, int iDec ) +{ + static HB_RETNLEN s_retnlen = NULL; + + if( !s_retnlen ) + { + s_retnlen = ( HB_RETNLEN ) hb_dllGetProcAddress( "hb_retnlen" ); + if( !s_retnlen ) + HB_DLL_MSG_NO_FUNC( "hb_retnlen" ); + } + + if( s_retnlen ) + s_retnlen( dNumber, iWidth, iDec ); +} + +void hb_retndlen( double dNumber, int iWidth, int iDec ) +{ + static HB_RETNDLEN s_retndlen = NULL; + + if( !s_retndlen ) + { + s_retndlen = ( HB_RETNDLEN ) hb_dllGetProcAddress( "hb_retndlen" ); + if( !s_retndlen ) + HB_DLL_MSG_NO_FUNC( "hb_retndlen" ); + } + + if( s_retndlen ) + s_retndlen( dNumber, iWidth, iDec ); +} + +void hb_retnilen( int iNumber, int iWidth ) +{ + static HB_RETNILEN s_retnilen = NULL; + + if( !s_retnilen ) + { + s_retnilen = ( HB_RETNILEN ) hb_dllGetProcAddress( "hb_retnilen" ); + if( !s_retnilen ) + HB_DLL_MSG_NO_FUNC( "hb_retnilen" ); + } + + if( s_retnilen ) + s_retnilen( iNumber, iWidth ); +} + +void hb_retnllen( long lNumber, int iWidth ) +{ + static HB_RETNLLEN s_retnllen = NULL; + + if( !s_retnllen ) + { + s_retnllen = ( HB_RETNLLEN ) hb_dllGetProcAddress( "hb_retnllen" ); + if( !s_retnllen ) + HB_DLL_MSG_NO_FUNC( "hb_retnllen" ); + } + + if( s_retnllen ) + s_retnllen( lNumber, iWidth ); +} + +void hb_reta( HB_SIZE nLen ) +{ + static HB_RETA s_reta = NULL; + + if( !s_reta ) + { + s_reta = ( HB_RETA ) hb_dllGetProcAddress( "hb_reta" ); + if( !s_reta ) + HB_DLL_MSG_NO_FUNC( "hb_reta" ); + } + + if( s_reta ) + s_reta( nLen ); +} + +const char * hb_parvc( int iParam, ... ) +{ + static HB_PARVC s_parvc = NULL; + + if( !s_parvc ) + { + s_parvc = ( HB_PARVC ) hb_dllGetProcAddress( "hb_parvc" ); + if( !s_parvc ) + HB_DLL_MSG_NO_FUNC( "hb_parvc" ); + } + + if( s_parvc ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvc( iParam, nArrayIndex ); + } + + return NULL; +} + +HB_SIZE hb_parvclen( int iParam, ... ) +{ + static HB_PARVCLEN s_parvclen = NULL; + + if( !s_parvclen ) + { + s_parvclen = ( HB_PARVCLEN ) hb_dllGetProcAddress( "hb_parvclen" ); + if( !s_parvclen ) + HB_DLL_MSG_NO_FUNC( "hb_parvclen" ); + } + + if( s_parvclen ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvclen( iParam, nArrayIndex ); + } + + return 0; +} + +HB_SIZE hb_parvcsiz( int iParam, ... ) +{ + static HB_PARVCSIZ s_parvcsiz = NULL; + + if( !s_parvcsiz ) + { + s_parvcsiz = ( HB_PARVCSIZ ) hb_dllGetProcAddress( "hb_parvcsiz" ); + if( !s_parvcsiz ) + HB_DLL_MSG_NO_FUNC( "hb_parvcsiz" ); + } + + if( s_parvcsiz ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvcsiz( iParam, nArrayIndex ); + } + + return 0; +} + +const char * hb_parvds( int iParam, ... ) +{ + static HB_PARVDS s_parvds = NULL; + + if( !s_parvds ) + { + s_parvds = ( HB_PARVDS ) hb_dllGetProcAddress( "hb_parvds" ); + if( !s_parvds ) + HB_DLL_MSG_NO_FUNC( "hb_parvds" ); + } + + if( s_parvds ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvds( iParam, nArrayIndex ); + } + + return " "; +} + +char * hb_parvdsbuff( char * szDate, int iParam, ... ) +{ + static HB_PARVDSBUFF s_parvdsbuff = NULL; + + if( !s_parvdsbuff ) + { + s_parvdsbuff = ( HB_PARVDSBUFF ) hb_dllGetProcAddress( "hb_parvdsbuff" ); + if( !s_parvdsbuff ) + HB_DLL_MSG_NO_FUNC( "hb_parvdsbuff" ); + } + + if( s_parvdsbuff ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvdsbuff( szDate, iParam, nArrayIndex ); + } + + return szDate; +} + +int hb_parvl( int iParam, ... ) +{ + static HB_PARVL s_parvl = NULL; + + if( !s_parvl ) + { + s_parvl = ( HB_PARVL ) hb_dllGetProcAddress( "hb_parvl" ); + if( !s_parvl ) + HB_DLL_MSG_NO_FUNC( "hb_parvl" ); + } + + if( s_parvl ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvl( iParam, nArrayIndex ); + } + + return 0; +} + +double hb_parvnd( int iParam, ... ) +{ + static HB_PARVND s_parvnd = NULL; + + if( !s_parvnd ) + { + s_parvnd = ( HB_PARVND ) hb_dllGetProcAddress( "hb_parvnd" ); + if( !s_parvnd ) + HB_DLL_MSG_NO_FUNC( "hb_parvnd" ); + } + + if( s_parvnd ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvnd( iParam, nArrayIndex ); + } + + return 0; +} + +int hb_parvni( int iParam, ... ) +{ + static HB_PARVNI s_parvni = NULL; + + if( !s_parvni ) + { + s_parvni = ( HB_PARVNI ) hb_dllGetProcAddress( "hb_parvni" ); + if( !s_parvni ) + HB_DLL_MSG_NO_FUNC( "hb_parvni" ); + } + + if( s_parvni ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvni( iParam, nArrayIndex ); + } + + return 0; +} + +long hb_parvnl( int iParam, ... ) +{ + static HB_PARVNL s_parvnl = NULL; + + if( !s_parvnl ) + { + s_parvnl = ( HB_PARVNL ) hb_dllGetProcAddress( "hb_parvnl" ); + if( !s_parvnl ) + HB_DLL_MSG_NO_FUNC( "hb_parvnl" ); + } + + if( s_parvnl ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_parvnl( iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvc( const char * szText, int iParam, ... ) +{ + static HB_STORVC s_storvc = NULL; + + if( !s_storvc ) + { + s_storvc = ( HB_STORVC ) hb_dllGetProcAddress( "hb_storvc" ); + if( !s_storvc ) + HB_DLL_MSG_NO_FUNC( "hb_storvc" ); + } + + if( s_storvc ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvc( szText, iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvclen( const char * szText, HB_SIZE nLen, int iParam, ... ) +{ + static HB_STORVCLEN s_storvclen = NULL; + + if( !s_storvclen ) + { + s_storvclen = ( HB_STORVCLEN ) hb_dllGetProcAddress( "hb_storvclen" ); + if( !s_storvclen ) + HB_DLL_MSG_NO_FUNC( "hb_storvclen" ); + } + + if( s_storvclen ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvclen( szText, nLen, iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvds( const char * szDate, int iParam, ... ) +{ + static HB_STORVDS s_storvds = NULL; + + if( !s_storvds ) + { + s_storvds = ( HB_STORVDS ) hb_dllGetProcAddress( "hb_storvds" ); + if( !s_storvds ) + HB_DLL_MSG_NO_FUNC( "hb_storvds" ); + } + + if( s_storvds ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvds( szDate, iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvl( int iLogical, int iParam, ... ) +{ + static HB_STORVL s_storvl = NULL; + + if( !s_storvl ) + { + s_storvl = ( HB_STORVL ) hb_dllGetProcAddress( "hb_storvl" ); + if( !s_storvl ) + HB_DLL_MSG_NO_FUNC( "hb_storvl" ); + } + + if( s_storvl ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvl( iLogical, iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvni( int iValue, int iParam, ... ) +{ + static HB_STORVNI s_storvni = NULL; + + if( !s_storvni ) + { + s_storvni = ( HB_STORVNI ) hb_dllGetProcAddress( "hb_storvni" ); + if( !s_storvni ) + HB_DLL_MSG_NO_FUNC( "hb_storvni" ); + } + + if( s_storvni ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvni( iValue, iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvnl( long lValue, int iParam, ... ) +{ + static HB_STORVNL s_storvnl = NULL; + + if( !s_storvnl ) + { + s_storvnl = ( HB_STORVNL ) hb_dllGetProcAddress( "hb_storvnl" ); + if( !s_storvnl ) + HB_DLL_MSG_NO_FUNC( "hb_storvnl" ); + } + + if( s_storvnl ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvnl( lValue, iParam, nArrayIndex ); + } + + return 0; +} + +int hb_storvnd( double dNumber, int iParam, ... ) +{ + static HB_STORVND s_storvnd = NULL; + + if( !s_storvnd ) + { + s_storvnd = ( HB_STORVND ) hb_dllGetProcAddress( "hb_storvnd" ); + if( !s_storvnd ) + HB_DLL_MSG_NO_FUNC( "hb_storvnd" ); + } + + if( s_storvnd ) + { + HB_SIZE nArrayIndex = 0; + + if( hb_extIsArray( iParam ) ) + { + va_list va; + va_start( va, iParam ); + nArrayIndex = va_arg( va, HB_SIZE ); + va_end( va ); + } + + return s_storvnd( dNumber, iParam, nArrayIndex ); + } + + return 0; +} + +HB_BOOL hb_arrayNew( PHB_ITEM pItem, HB_SIZE nLen ) +{ + static HB_ARRAYNEW s_arrayNew = NULL; + + if( !s_arrayNew ) + { + s_arrayNew = ( HB_ARRAYNEW ) hb_dllGetProcAddress( "hb_arrayNew" ); + if( !s_arrayNew ) + HB_DLL_MSG_NO_FUNC( "hb_arrayNew" ); + } + return s_arrayNew ? s_arrayNew( pItem, nLen ) : HB_FALSE; +} + +HB_SIZE hb_arrayLen( PHB_ITEM pArray ) +{ + static HB_ARRAYLEN s_arrayLen = NULL; + + if( !s_arrayLen ) + { + s_arrayLen = ( HB_ARRAYLEN ) hb_dllGetProcAddress( "hb_arrayLen" ); + if( !s_arrayLen ) + HB_DLL_MSG_NO_FUNC( "hb_arrayLen" ); + } + return s_arrayLen ? s_arrayLen( pArray ) : 0; +} + +HB_BOOL hb_arrayIsObject( PHB_ITEM pArray ) +{ + static HB_ARRAYISOBJECT s_arrayIsObject = NULL; + + if( !s_arrayIsObject ) + { + s_arrayIsObject = ( HB_ARRAYISOBJECT ) hb_dllGetProcAddress( "hb_arrayIsObject" ); + if( !s_arrayIsObject ) + HB_DLL_MSG_NO_FUNC( "hb_arrayIsObject" ); + } + return s_arrayIsObject ? s_arrayIsObject( pArray ) : HB_FALSE; +} + +HB_BOOL hb_arrayAdd( PHB_ITEM pArray, PHB_ITEM pItem ) +{ + static HB_ARRAYADD s_arrayAdd = NULL; + + if( !s_arrayAdd ) + { + s_arrayAdd = ( HB_ARRAYADD ) hb_dllGetProcAddress( "hb_arrayAdd" ); + if( !s_arrayAdd ) + HB_DLL_MSG_NO_FUNC( "hb_arrayAdd" ); + } + return s_arrayAdd ? s_arrayAdd( pArray, pItem ) : HB_FALSE; +} + +HB_BOOL hb_arrayIns( PHB_ITEM pArray, HB_SIZE nIndex ) +{ + static HB_ARRAYINS s_arrayIns = NULL; + + if( !s_arrayIns ) + { + s_arrayIns = ( HB_ARRAYINS ) hb_dllGetProcAddress( "hb_arrayIns" ); + if( !s_arrayIns ) + HB_DLL_MSG_NO_FUNC( "hb_arrayIns" ); + } + return s_arrayIns ? s_arrayIns( pArray, nIndex ) : HB_FALSE; +} + +HB_BOOL hb_arrayDel( PHB_ITEM pArray, HB_SIZE nIndex ) +{ + static HB_ARRAYDEL s_arrayDel = NULL; + + if( !s_arrayDel ) + { + s_arrayDel = ( HB_ARRAYDEL ) hb_dllGetProcAddress( "hb_arrayDel" ); + if( !s_arrayDel ) + HB_DLL_MSG_NO_FUNC( "hb_arrayDel" ); + } + return s_arrayDel ? s_arrayDel( pArray, nIndex ) : HB_FALSE; +} + +HB_BOOL hb_arraySize( PHB_ITEM pArray, HB_SIZE nLen ) +{ + static HB_ARRAYSIZE s_arraySize = NULL; + + if( !s_arraySize ) + { + s_arraySize = ( HB_ARRAYSIZE ) hb_dllGetProcAddress( "hb_arraySize" ); + if( !s_arraySize ) + HB_DLL_MSG_NO_FUNC( "hb_arraySize" ); + } + return s_arraySize ? s_arraySize( pArray, nLen ) : HB_FALSE; +} + +HB_BOOL hb_arrayLast( PHB_ITEM pArray, PHB_ITEM pResult ) +{ + static HB_ARRAYLAST s_arrayLast = NULL; + + if( !s_arrayLast ) + { + s_arrayLast = ( HB_ARRAYLAST ) hb_dllGetProcAddress( "hb_arrayLast" ); + if( !s_arrayLast ) + HB_DLL_MSG_NO_FUNC( "hb_arrayLast" ); + } + return s_arrayLast ? s_arrayLast( pArray, pResult ) : HB_FALSE; +} + +HB_BOOL hb_arraySet( PHB_ITEM pArray, HB_SIZE nIndex, PHB_ITEM pItem ) +{ + static HB_ARRAYSET s_arraySet = NULL; + + if( !s_arraySet ) + { + s_arraySet = ( HB_ARRAYSET ) hb_dllGetProcAddress( "hb_arraySet" ); + if( !s_arraySet ) + HB_DLL_MSG_NO_FUNC( "hb_arraySet" ); + } + return s_arraySet ? s_arraySet( pArray, nIndex, pItem ) : HB_FALSE; +} + +HB_BOOL hb_arrayGet( PHB_ITEM pArray, HB_SIZE nIndex, PHB_ITEM pItem ) +{ + static HB_ARRAYGET s_arrayGet = NULL; + + if( !s_arrayGet ) + { + s_arrayGet = ( HB_ARRAYGET ) hb_dllGetProcAddress( "hb_arrayGet" ); + if( !s_arrayGet ) + HB_DLL_MSG_NO_FUNC( "hb_arrayGet" ); + } + return s_arrayGet ? s_arrayGet( pArray, nIndex, pItem ) : HB_FALSE; +} + +void * hb_xalloc( HB_SIZE nSize ) +{ + static HB_XALLOC s_xalloc = NULL; + + if( !s_xalloc ) + { + s_xalloc = ( HB_XALLOC ) hb_dllGetProcAddress( "hb_xalloc" ); + if( !s_xalloc ) + HB_DLL_MSG_NO_FUNC( "hb_xalloc" ); + } + + return s_xalloc ? s_xalloc( nSize ) : NULL; +} + +void * hb_xgrab( HB_SIZE nSize ) +{ + static HB_XGRAB s_xgrab = NULL; + + if( !s_xgrab ) + { + s_xgrab = ( HB_XGRAB ) hb_dllGetProcAddress( "hb_xgrab" ); + if( !s_xgrab ) + HB_DLL_MSG_NO_FUNC( "hb_xgrab" ); + } + + return s_xgrab ? s_xgrab( nSize ) : NULL; +} + +void hb_xfree( void * pMem ) +{ + static HB_XFREE s_xfree = NULL; + + if( !s_xfree ) + { + s_xfree = ( HB_XFREE ) hb_dllGetProcAddress( "hb_xfree" ); + if( !s_xfree ) + HB_DLL_MSG_NO_FUNC( "hb_xfree" ); + } + + if( s_xfree ) + s_xfree( pMem ); +} + +void * hb_xrealloc( void * pMem, HB_SIZE nSize ) +{ + static HB_XREALLOC s_xrealloc = NULL; + + if( !s_xrealloc ) + { + s_xrealloc = ( HB_XREALLOC ) hb_dllGetProcAddress( "hb_xrealloc" ); + if( !s_xrealloc ) + HB_DLL_MSG_NO_FUNC( "hb_xrealloc" ); + } + + return s_xrealloc ? s_xrealloc( pMem, nSize ) : NULL; +} + +#endif /* HB_OS_WIN */ diff --git a/harbour/src/vm/maindllp/dllpcode.c b/harbour/src/vm/maindllp/dllpcode.c new file mode 100644 index 0000000000..ffa1581b1f --- /dev/null +++ b/harbour/src/vm/maindllp/dllpcode.c @@ -0,0 +1,255 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Import library for PCODE DLLs + * + * Copyright 2010 Przemyslaw Czerpak + * This code uses HB_DLL_NAME* macros defined by + * Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbvm.h" +#include "hbtypes.h" + +#if defined( HB_OS_WIN ) + #include +#endif + +#define HB_DLL_PREF TEXT( "harbour" ) +#define HB_DLL_PREF_MT TEXT( "harbourmt" ) +#define HB_DLL_VER TEXT( "-" ) TEXT( HB_MACRO2STRING( HB_VER_MAJOR ) ) TEXT( HB_MACRO2STRING( HB_VER_MINOR ) ) +#define HB_DLL_EXT TEXT( ".dll" ) + +#define HB_DLL_NAME HB_DLL_PREF HB_DLL_EXT +#define HB_DLL_NAMEMT HB_DLL_PREF_MT HB_DLL_EXT + +#if defined( HB_OS_WIN_CE ) && defined( HB_CPU_ARM ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-arm" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-arm" ) HB_DLL_EXT +#elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_MIPS ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-mips" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-mips" ) HB_DLL_EXT +#elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_SH ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-sh" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-sh" ) HB_DLL_EXT +#elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_X86 ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce-x86" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce-x86" ) HB_DLL_EXT +#elif defined( HB_OS_WIN_CE ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-wce" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-wce" ) HB_DLL_EXT +#elif defined( __BORLANDC__ ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-bcc" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-bcc" ) HB_DLL_EXT +#elif defined( HB_OS_WIN_64 ) && defined( HB_CPU_X86_64 ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-x64" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-x64" ) HB_DLL_EXT +#elif defined( HB_OS_WIN_64 ) && defined( HB_CPU_IA_64 ) + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER TEXT( "-ia64" ) HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER TEXT( "-ia64" ) HB_DLL_EXT +#else + #define HB_DLL_NAME2 HB_DLL_PREF HB_DLL_VER HB_DLL_EXT + #define HB_DLL_NAMEMT2 HB_DLL_PREF_MT HB_DLL_VER HB_DLL_EXT +#endif + +#if defined( HB_OS_WIN ) + +HB_EXTERN_BEGIN + +#define HB_DLL_MSG_NO_FUNC( func ) do { \ + MessageBox( NULL, \ + TEXT( "Function '" ) TEXT( func ) TEXT( "' not found!" ), \ + TEXT( func ), \ + MB_OK | MB_ICONERROR ); \ + } while( 0 ) + +typedef PHB_FUNC ( * HB_PROC_GET )( const char * szFuncName ); + +/* hb_vmProcessSymbols() */ +typedef PHB_SYMB ( * HB_VM_PROCESS_SYMBOLS ) + ( PHB_SYMB pModuleSymbols, HB_USHORT uiModuleSymbols, + const char * szModuleName, HB_ULONG ulID, + HB_USHORT uiPcodeVer ); +static PHB_SYMB s_vmProcessSymbols( PHB_SYMB pSymbols, HB_USHORT uiSymbols, + const char * szModuleName, HB_ULONG ulID, + HB_USHORT uiPcodeVer ); +static HB_VM_PROCESS_SYMBOLS s_pProcessSymbols = s_vmProcessSymbols; + + +/* hb_vmExecute() */ +typedef void ( * HB_VM_EXECUTE ) ( const HB_BYTE * pCode, PHB_SYMB pSymbols ); +static void s_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols ); +static HB_VM_EXECUTE s_pExecute = s_vmExecute; + + +PHB_FUNC hb_dllGetProcAddress( const char * szProcName ) +{ + static HB_PROC_GET s_pProcGet = NULL; + static HMODULE s_hModule = NULL; + + if( s_hModule == NULL ) + { + s_hModule = GetModuleHandle( HB_DLL_NAME ); + if( s_hModule == NULL ) + s_hModule = GetModuleHandle( HB_DLL_NAMEMT ); + if( s_hModule == NULL ) + s_hModule = GetModuleHandle( HB_DLL_NAME2 ); + if( s_hModule == NULL ) + s_hModule = GetModuleHandle( HB_DLL_NAMEMT2 ); + if( s_hModule == NULL ) + s_hModule = GetModuleHandle( NULL ); + + if( s_hModule != NULL ) + { +#if defined( HB_OS_WIN_CE ) +# define HBTEXTSTR LPCTSTR +#else +# define HBTEXTSTR LPCSTR +#endif + static HBTEXTSTR s_szGetProcAddr = HBTEXT( "_dll_hb_vmProcAddress" ); + int i = 6; + + do + { + i -= i == 4 ? 3 : 1; + s_pProcGet = ( HB_PROC_GET ) GetProcAddress( s_hModule, s_szGetProcAddr + i ); + } + while( s_pProcGet == NULL && i > 0 ); + if( s_pProcGet == NULL ) + HB_DLL_MSG_NO_FUNC( "hb_vmProcAddress" ); + } + } + + return s_pProcGet ? s_pProcGet( szProcName ) : NULL; +} + + +#if defined( HB_OS_WIN_CE ) && ( defined( _MSC_VER ) || defined( __POCC__ ) ) +HB_EXPORT BOOL WINAPI HB_DLL_ENTRY_POINT( HANDLE hInstance, DWORD dwReason, PVOID pvReserved ) +#else +HB_EXPORT BOOL WINAPI HB_DLL_ENTRY_POINT( HINSTANCE hInstance, DWORD dwReason, PVOID pvReserved ) +#endif +{ + HB_TRACE( HB_TR_DEBUG, ("DllEntryPoint(%p, %lu, %p)", hInstance, dwReason, pvReserved ) ); + + HB_SYMBOL_UNUSED( hInstance ); + HB_SYMBOL_UNUSED( dwReason ); + HB_SYMBOL_UNUSED( pvReserved ); + + return TRUE; +} + + +static PHB_SYMB s_dummy_vmProcessSymbols( PHB_SYMB pSymbols, HB_USHORT uiSymbols, + const char * szModuleName, HB_ULONG ulID, + HB_USHORT uiPcodeVer ) +{ + HB_SYMBOL_UNUSED( uiSymbols ); + HB_SYMBOL_UNUSED( szModuleName ); + HB_SYMBOL_UNUSED( ulID ); + HB_SYMBOL_UNUSED( uiPcodeVer ); + + return pSymbols; +} + +static PHB_SYMB s_vmProcessSymbols( PHB_SYMB pSymbols, HB_USHORT uiSymbols, + const char * szModuleName, HB_ULONG ulID, + HB_USHORT uiPcodeVer ) +{ + HB_VM_PROCESS_SYMBOLS pProcessSymbols = ( HB_VM_PROCESS_SYMBOLS ) + hb_dllGetProcAddress( "hb_vmProcessSymbols" ); + if( pProcessSymbols ) + { + s_pProcessSymbols = pProcessSymbols; + return s_pProcessSymbols( pSymbols, uiSymbols, szModuleName, ulID, uiPcodeVer ); + } + else + { + s_pProcessSymbols = s_dummy_vmProcessSymbols; + HB_DLL_MSG_NO_FUNC( "hb_vmProcessSymbols" ); + return pSymbols; + } +} + +PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, HB_USHORT uiSymbols, + const char * szModuleName, HB_ULONG ulID, + HB_USHORT uiPcodeVer ) +{ + return s_pProcessSymbols( pSymbols, uiSymbols, szModuleName, ulID, uiPcodeVer ); +} + +static void s_dummy_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols ) +{ + HB_SYMBOL_UNUSED( pCode ); + HB_SYMBOL_UNUSED( pSymbols ); +} + +static void s_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols ) +{ + HB_VM_EXECUTE pExecute = ( HB_VM_EXECUTE ) + hb_dllGetProcAddress( "hb_vmExecute" ); + if( pExecute ) + { + s_pExecute = pExecute; + s_pExecute( pCode, pSymbols ); + } + else + { + s_pExecute = s_dummy_vmExecute; + HB_DLL_MSG_NO_FUNC( "hb_vmExecute" ); + } +} + +void hb_vmExecute( const HB_BYTE * pCode, PHB_SYMB pSymbols ) +{ + s_pExecute( pCode, pSymbols ); +} + +HB_EXTERN_END + +#endif /* HB_OS_WIN */ diff --git a/harbour/src/vm/procaddr.c b/harbour/src/vm/procaddr.c new file mode 100644 index 0000000000..69bc959a81 --- /dev/null +++ b/harbour/src/vm/procaddr.c @@ -0,0 +1,140 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Function to export chosen addresses of public API function + * + * Copyright 2010 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" + +PHB_FUNC hb_vmProcAddress( const char * szFuncName ) +{ + typedef struct + { + const char * szFuncName; + PHB_FUNC pFuncAddr; + } + HB_FUNC_REF_ADDR; + + /* NOTE: this table must be well sorted by function names */ + static const HB_FUNC_REF_ADDR s_funcTable[] = + { + { "hb_arrayAdd", ( PHB_FUNC ) hb_arrayAdd }, + { "hb_arrayDel", ( PHB_FUNC ) hb_arrayDel }, + { "hb_arrayGet", ( PHB_FUNC ) hb_arrayGet }, + { "hb_arrayIns", ( PHB_FUNC ) hb_arrayIns }, + { "hb_arrayIsObject", ( PHB_FUNC ) hb_arrayIsObject }, + { "hb_arrayLast", ( PHB_FUNC ) hb_arrayLast }, + { "hb_arrayLen", ( PHB_FUNC ) hb_arrayLen }, + { "hb_arrayNew", ( PHB_FUNC ) hb_arrayNew }, + { "hb_arraySet", ( PHB_FUNC ) hb_arraySet }, + { "hb_arraySize", ( PHB_FUNC ) hb_arraySize }, + { "hb_extIsArray", ( PHB_FUNC ) hb_extIsArray }, + { "hb_param", ( PHB_FUNC ) hb_param }, + { "hb_paramError", ( PHB_FUNC ) hb_paramError }, + { "hb_parinfa", ( PHB_FUNC ) hb_parinfa }, + { "hb_parinfo", ( PHB_FUNC ) hb_parinfo }, + { "hb_parvc", ( PHB_FUNC ) hb_parvc }, + { "hb_parvclen", ( PHB_FUNC ) hb_parvclen }, + { "hb_parvcsiz", ( PHB_FUNC ) hb_parvcsiz }, + { "hb_parvds", ( PHB_FUNC ) hb_parvds }, + { "hb_parvdsbuff", ( PHB_FUNC ) hb_parvdsbuff }, + { "hb_parvl", ( PHB_FUNC ) hb_parvl }, + { "hb_parvnd", ( PHB_FUNC ) hb_parvnd }, + { "hb_parvni", ( PHB_FUNC ) hb_parvni }, + { "hb_parvnl", ( PHB_FUNC ) hb_parvnl }, + { "hb_pcount", ( PHB_FUNC ) hb_pcount }, + { "hb_ret", ( PHB_FUNC ) hb_ret }, + { "hb_reta", ( PHB_FUNC ) hb_reta }, + { "hb_retc", ( PHB_FUNC ) hb_retc }, + { "hb_retclen", ( PHB_FUNC ) hb_retclen }, + { "hb_retd", ( PHB_FUNC ) hb_retd }, + { "hb_retdl", ( PHB_FUNC ) hb_retdl }, + { "hb_retds", ( PHB_FUNC ) hb_retds }, + { "hb_retl", ( PHB_FUNC ) hb_retl }, + { "hb_retnd", ( PHB_FUNC ) hb_retnd }, + { "hb_retndlen", ( PHB_FUNC ) hb_retndlen }, + { "hb_retni", ( PHB_FUNC ) hb_retni }, + { "hb_retnilen", ( PHB_FUNC ) hb_retnilen }, + { "hb_retnl", ( PHB_FUNC ) hb_retnl }, + { "hb_retnlen", ( PHB_FUNC ) hb_retnlen }, + { "hb_retnllen", ( PHB_FUNC ) hb_retnllen }, + { "hb_storvc", ( PHB_FUNC ) hb_storvc }, + { "hb_storvclen", ( PHB_FUNC ) hb_storvclen }, + { "hb_storvds", ( PHB_FUNC ) hb_storvds }, + { "hb_storvl", ( PHB_FUNC ) hb_storvl }, + { "hb_storvnd", ( PHB_FUNC ) hb_storvnd }, + { "hb_storvni", ( PHB_FUNC ) hb_storvni }, + { "hb_storvnl", ( PHB_FUNC ) hb_storvnl }, + { "hb_vmExecute", ( PHB_FUNC ) hb_vmExecute }, + { "hb_vmProcessSymbols", ( PHB_FUNC ) hb_vmProcessDynLibSymbols }, + { "hb_xalloc", ( PHB_FUNC ) hb_xalloc }, + { "hb_xfree", ( PHB_FUNC ) hb_xfree }, + { "hb_xgrab", ( PHB_FUNC ) hb_xgrab }, + { "hb_xrealloc", ( PHB_FUNC ) hb_xrealloc }, + }; + + unsigned int uiFirst = 0, uiLast = HB_SIZEOFARRAY( s_funcTable ), uiMiddle; + int iCmp; + + do + { + uiMiddle = ( uiFirst + uiLast ) >> 1; + iCmp = strcmp( szFuncName, s_funcTable[ uiMiddle ].szFuncName ); + if( iCmp <= 0 ) + uiLast = uiMiddle; + else + uiFirst = uiMiddle + 1; + } + while( uiFirst < uiLast ); + + if( uiFirst != uiMiddle ) + iCmp = strcmp( szFuncName, s_funcTable[ uiFirst ].szFuncName ); + + return iCmp == 0 ? s_funcTable[ uiFirst ].pFuncAddr : NULL; +}