* 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.
256 lines
9.3 KiB
C
256 lines
9.3 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* Import library for PCODE DLLs
|
|
*
|
|
* Copyright 2010 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
|
* 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 <windows.h>
|
|
#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 */
|