From 83bbb7b34d2fb1423eb84e037e4d7216f62feb5c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 17 Feb 2010 02:09:17 +0000 Subject: [PATCH] 2010-02-17 03:06 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * src/rtl/fstemp.c ! Using hb_fsTempDir() in HB_FTEMPCREATEEX() instead of old solution. This should fix it for some non-*nix platforms where *nix specific TEMPDIR envvar was used to determine temp directory. * contrib/hbwin/Makefile * include/Makefile * src/rtl/Makefile - contrib/hbwin/hbdyn.ch + include/hbdyn.ch - contrib/hbwin/hbdyn.c + src/rtl/hbdyn.c - contrib/hbwin/win_dllc.c + src/rtl/hbdynhb.c - contrib/hbwin/tests/testdll.c + tests/testdyn.c - contrib/hbwin/tests/testdll.prg + tests/testdyn.prg - contrib/hbwin/tests/testdll1.prg + tests/testdyn1.prg - contrib/hbwin/hbdyn.h * include/hbapi.h * Moved dynamic library call related functions to core (RTL). * Windows specific test code (currently all) guarded for platform. * Changed default calling convention to cdecl. Tests adaptd accordingly. * Terminology change: 'dll' -> 'dynamic library' ; HB_DYNCALL() is now part of core Harbour, and it's platform independent. It's platform (ABI) dependent though, and currently x64 and x86/stdcall/syscall/cdecl is supported and these were tested (except OS/2 syscall). * contrib/hbwin/hbwin.h * contrib/hbwin/win_misc.c * contrib/hbwin/legacycd.c * Low level hbwin_getprocaddress() function moved to legacy file and made static. * contrib/xpp/Makefile * contrib/xpp/dllx.c * contrib/xpp/xpp.hbc + Enabled DLL*() functions for all platforms. - Deleted dependence on hbwin library. * contrib/xpp/tests/testdll.prg * Windows specific parts (currently the whole test) guarded for platform. * contrib/hbct/Makefile - contrib/hbct/diskhb.prg * contrib/hbct/disk.c * contrib/xhb/Makefile + contrib/xhb/diskhb.prg * GETVOLINFO() moved from hbct to xhb. * ChangeLog * Marked some TODO/TOFIX items as DONE. --- harbour/ChangeLog | 74 +++++++++++- harbour/contrib/hbct/Makefile | 1 - harbour/contrib/hbct/disk.c | 1 - harbour/contrib/hbwin/Makefile | 4 - harbour/contrib/hbwin/hbdyn.h | 65 ----------- harbour/contrib/hbwin/hbwin.h | 5 +- harbour/contrib/hbwin/legacycd.c | 57 ++++++++- harbour/contrib/hbwin/tests/testdll.prg | 108 ------------------ harbour/contrib/hbwin/tests/testdll1.prg | 49 -------- harbour/contrib/hbwin/win_misc.c | 53 --------- harbour/contrib/xhb/Makefile | 1 + harbour/contrib/{hbct => xhb}/diskhb.prg | 0 harbour/contrib/xpp/Makefile | 4 - harbour/contrib/xpp/dllx.c | 17 +-- harbour/contrib/xpp/tests/testdll.prg | 76 ++++++------ harbour/contrib/xpp/xpp.hbc | 1 - harbour/include/Makefile | 1 + harbour/include/hbapi.h | 2 + harbour/{contrib/hbwin => include}/hbdyn.ch | 4 +- harbour/src/rtl/Makefile | 2 + harbour/src/rtl/fstemp.c | 31 +---- harbour/{contrib/hbwin => src/rtl}/hbdyn.c | 2 +- .../hbwin/win_dllc.c => src/rtl/hbdynhb.c} | 5 +- .../hbwin/tests/testdll.c => tests/testdyn.c} | 32 +++--- harbour/tests/testdyn.prg | 108 ++++++++++++++++++ harbour/tests/testdyn1.prg | 49 ++++++++ 26 files changed, 354 insertions(+), 398 deletions(-) delete mode 100644 harbour/contrib/hbwin/hbdyn.h delete mode 100644 harbour/contrib/hbwin/tests/testdll.prg delete mode 100644 harbour/contrib/hbwin/tests/testdll1.prg rename harbour/contrib/{hbct => xhb}/diskhb.prg (100%) rename harbour/{contrib/hbwin => include}/hbdyn.ch (97%) rename harbour/{contrib/hbwin => src/rtl}/hbdyn.c (99%) rename harbour/{contrib/hbwin/win_dllc.c => src/rtl/hbdynhb.c} (98%) rename harbour/{contrib/hbwin/tests/testdll.c => tests/testdyn.c} (58%) create mode 100644 harbour/tests/testdyn.prg create mode 100644 harbour/tests/testdyn1.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0955e1b837..fb747d1530 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,68 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-02-17 03:06 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * src/rtl/fstemp.c + ! Using hb_fsTempDir() in HB_FTEMPCREATEEX() instead of + old solution. This should fix it for some non-*nix + platforms where *nix specific TEMPDIR envvar was used + to determine temp directory. + + * contrib/hbwin/Makefile + * include/Makefile + * src/rtl/Makefile + - contrib/hbwin/hbdyn.ch + + include/hbdyn.ch + - contrib/hbwin/hbdyn.c + + src/rtl/hbdyn.c + - contrib/hbwin/win_dllc.c + + src/rtl/hbdynhb.c + - contrib/hbwin/tests/testdll.c + + tests/testdyn.c + - contrib/hbwin/tests/testdll.prg + + tests/testdyn.prg + - contrib/hbwin/tests/testdll1.prg + + tests/testdyn1.prg + - contrib/hbwin/hbdyn.h + * include/hbapi.h + * Moved dynamic library call related functions to + core (RTL). + * Windows specific test code (currently all) guarded + for platform. + * Changed default calling convention to cdecl. + Tests adaptd accordingly. + * Terminology change: 'dll' -> 'dynamic library' + ; HB_DYNCALL() is now part of core Harbour, and it's + platform independent. It's platform (ABI) dependent though, + and currently x64 and x86/stdcall/syscall/cdecl + is supported and these were tested (except OS/2 syscall). + + * contrib/hbwin/hbwin.h + * contrib/hbwin/win_misc.c + * contrib/hbwin/legacycd.c + * Low level hbwin_getprocaddress() function moved + to legacy file and made static. + + * contrib/xpp/Makefile + * contrib/xpp/dllx.c + * contrib/xpp/xpp.hbc + + Enabled DLL*() functions for all platforms. + - Deleted dependence on hbwin library. + + * contrib/xpp/tests/testdll.prg + * Windows specific parts (currently the whole test) guarded + for platform. + + * contrib/hbct/Makefile + - contrib/hbct/diskhb.prg + * contrib/hbct/disk.c + * contrib/xhb/Makefile + + contrib/xhb/diskhb.prg + * GETVOLINFO() moved from hbct to xhb. + + * ChangeLog + * Marked some TODO/TOFIX items as DONE. + 2010-02-17 01:42 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbmysql/mysql.c ! Typo. @@ -72,7 +134,7 @@ ; NOTE: Please review this code. It's the first time I used GC references in code, and it may be wrong. ; TODO: Remove hbwin dependence after having moved hb_dynCall() - from hbwin to core. + from hbwin to core. [DONE] + contrib/xpp/tests/hbmk.hbm + Added missing file from prev commit. @@ -203,8 +265,8 @@ - Passing function pointer directly. - Automatic lookup for function names with 'A' and 'W' ending. - Automatic UNICODE encoding for functions ending with 'W'. - ; TODO: Make the default calling convention cdecl? - ; TODO: Move 'hbdyn' subsystem to core after review. + ; TODO: Make the default calling convention cdecl? [DONE] + ; TODO: Move 'hbdyn' subsystem to core after review. [DONE - no review yet though] ; HB_DYNCALL() should be called as follows: @@ -2860,7 +2922,7 @@ ! Fixed to not use -fomit-frame-pointer option for debug builds. ! Hack added to disable -fomit-frame-pointer for hbwin lib. ; TOFIX: Fix hb_Dynacall() to not be sensitive on this option - in mingw builds. Is it possible? + in mingw builds. Is it possible? [DONE] 2010-02-06 16:04 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * src/rtl/filesys.c @@ -3300,7 +3362,7 @@ the temp directory will be wrongly calculated by checking TMPDIR envvar. Such envvar seems *nix specific. If new hb_fsTempDir() will be tested, above can be fixed - by using this new function. + by using this new function. [DONE] * package/winuni/RELNOTES + Noted update to Firebird 2.5.0rc1 @@ -5831,7 +5893,7 @@ + Using new UNICODE macros in TRUENAME(), GETVOLINFO() and VOLSERIAL(). ! GETVOLINFO(), which is not a CT function, got moved to a separate source file to avoid name collisions. - ; TOFIX: It should be moved to xhb lib eventually. + ; TOFIX: It should be moved to xhb lib eventually. [DONE] * contrib/hbct/ctnet.c * Cleaned NETREDIR() and NETRMTNAME() functions. diff --git a/harbour/contrib/hbct/Makefile b/harbour/contrib/hbct/Makefile index c7f6606251..6089e1da93 100644 --- a/harbour/contrib/hbct/Makefile +++ b/harbour/contrib/hbct/Makefile @@ -100,7 +100,6 @@ PRG_SOURCES := \ ctmisc.prg \ ctrand.prg \ cttime.prg \ - diskhb.prg \ fcopy.prg \ getinfo.prg \ getinput.prg \ diff --git a/harbour/contrib/hbct/disk.c b/harbour/contrib/hbct/disk.c index 5cb4017fc8..ab06baf4be 100644 --- a/harbour/contrib/hbct/disk.c +++ b/harbour/contrib/hbct/disk.c @@ -13,7 +13,6 @@ * DirName() - Ready. * DriveType() - Ready. corrected * Volume() - Ready. - * GetVolInfo() - Ready. This function is new. * VolSerial() - Ready. * * Copyright 2004 Phil Krylov diff --git a/harbour/contrib/hbwin/Makefile b/harbour/contrib/hbwin/Makefile index 41d6e67216..e29f4a4ba4 100644 --- a/harbour/contrib/hbwin/Makefile +++ b/harbour/contrib/hbwin/Makefile @@ -10,7 +10,6 @@ LIBNAME := hbwin C_SOURCES := \ axcore.c \ - hbdyn.c \ legacycd.c \ legacyco.c \ legacycp.c \ @@ -35,7 +34,6 @@ C_SOURCES := \ win_bmpd.c \ win_com.c \ win_dlg.c \ - win_dllc.c \ win_misc.c \ win_osc.c \ win_prn1.c \ @@ -56,13 +54,11 @@ PRG_SOURCES := \ win_tprn.prg \ C_HEADERS := \ - hbdyn.h \ hbwapi.h \ hbwin.h \ hbwinole.h \ PRG_HEADERS := \ - hbdyn.ch \ hbwin.ch \ ifneq ($(filter $(HB_PLATFORM),win wce),) diff --git a/harbour/contrib/hbwin/hbdyn.h b/harbour/contrib/hbwin/hbdyn.h deleted file mode 100644 index 2a3c2cadc1..0000000000 --- a/harbour/contrib/hbwin/hbdyn.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * Dynamic call (low-level header) - * - * Copyright 2010 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. - * - */ - -#ifndef __HBDYN_H -#define __HBDYN_H - -#include "hbapi.h" -#include "hbdyn.ch" - -HB_EXTERN_BEGIN - -extern HB_EXPORT void hb_dynCall( int iFuncFlags, void * pFunction, int iParams, int iFirst, int * piArgFlags ); - -HB_EXTERN_END - -#endif /* __HBDYN_H */ diff --git a/harbour/contrib/hbwin/hbwin.h b/harbour/contrib/hbwin/hbwin.h index cfe48a18ee..d7c0aea5fd 100644 --- a/harbour/contrib/hbwin/hbwin.h +++ b/harbour/contrib/hbwin/hbwin.h @@ -93,10 +93,7 @@ HB_EXTERN_BEGIN -extern HB_EXPORT int hbwin_bitmapType( const void * pImgBuf, HB_SIZE size ); -extern FARPROC hbwin_getprocaddress( HMODULE hDLL, PHB_ITEM pParam, HB_BOOL * pbWIDE ); - -extern HB_EXPORT void hb_dynCall( int iFuncFlags, void * pFunction, int iParams, int iFirst, int * piArgFlags ); +extern HB_EXPORT int hbwin_bitmapType( const void * pImgBuf, HB_SIZE size ); HB_EXTERN_END diff --git a/harbour/contrib/hbwin/legacycd.c b/harbour/contrib/hbwin/legacycd.c index 96b64234e4..a619e2ca94 100644 --- a/harbour/contrib/hbwin/legacycd.c +++ b/harbour/contrib/hbwin/legacycd.c @@ -58,7 +58,9 @@ [vszakats] */ #include "hbwin.h" -#include "hbdyn.h" +#include "hbapiitm.h" + +#include "hbdyn.ch" #if ! defined( HB_LEGACY_LEVEL3 ) && ! defined( HB_WIN_LEGACY_LEVEL_OFF ) #define HB_WIN_LEGACY_LEVEL_OFF @@ -113,6 +115,59 @@ HB_FUNC( CALLDLLTYPED ) hb_dynCall( HB_DYN_CALLCONV_STDCALL | hb_parni( 2 ), hb_parptr( 1 ), hb_pcount(), 3, NULL ); } +static FARPROC hbwin_getprocaddress( HMODULE hDLL, PHB_ITEM pParam, HB_BOOL * pbWIDE ) +{ +#if defined( HB_OS_WIN_CE ) + void * hStr; + HB_SIZE nLen; + LPCWSTR szProc = hb_itemGetStrU16( pParam, HB_CDP_ENDIAN_NATIVE, &hStr, &nLen ); + FARPROC lpFunction = GetProcAddress( hDLL, szProc ? szProc : + ( LPCWSTR ) ( HB_PTRDIFF ) ( hb_itemGetNI( pParam ) & 0x0FFFF ) ); + + if( ! lpFunction && szProc ) /* try with WIDE suffix? */ + { + LPWSTR pszProcW = ( LPWSTR ) hb_xgrab( ( nLen + 2 ) * sizeof( WCHAR ) ); + memcpy( pszProcW, szProc, nLen * sizeof( WCHAR ) ); + pszProcW[ nLen++ ] = L'W'; + pszProcW[ nLen++ ] = 0; + lpFunction = GetProcAddress( hDLL, pszProcW ); + hb_xfree( pszProcW ); + } + hb_strfree( hStr ); + + if( pbWIDE ) + *pbWIDE = HB_TRUE; +#else + const char * szProc = hb_itemGetCPtr( pParam ); + FARPROC lpFunction = GetProcAddress( hDLL, szProc ? szProc : + ( LPCSTR ) ( HB_PTRDIFF ) ( hb_itemGetNI( pParam ) & 0x0FFFF ) ); + + if( pbWIDE ) + *pbWIDE = HB_FALSE; + +#if defined( UNICODE ) + if( ! lpFunction && szProc ) /* try with WIDE suffix? */ + { + char * pszFuncName = hb_xstrcpy( NULL, szProc, "W", NULL ); + lpFunction = GetProcAddress( hDLL, pszFuncName ); + hb_xfree( pszFuncName ); + if( pbWIDE ) + *pbWIDE = HB_TRUE; + } +#endif + + if( ! lpFunction && szProc ) /* try with ANSI suffix? */ + { + char * pszFuncName = hb_xstrcpy( NULL, szProc, "A", NULL ); + lpFunction = GetProcAddress( hDLL, pszFuncName ); + hb_xfree( pszFuncName ); + if( pbWIDE ) + *pbWIDE = HB_FALSE; + } +#endif + return lpFunction; +} + HB_FUNC( GETPROCADDRESS ) { HMODULE hDLL; diff --git a/harbour/contrib/hbwin/tests/testdll.prg b/harbour/contrib/hbwin/tests/testdll.prg deleted file mode 100644 index 70bd30e0bd..0000000000 --- a/harbour/contrib/hbwin/tests/testdll.prg +++ /dev/null @@ -1,108 +0,0 @@ -/* - * $Id$ - */ - -#include "simpleio.ch" - -/* - * Harbour Project source code: - * DLL call demonstration. - * - * Copyright 2008 Viktor Szakats (harbour.01 syenar.hu) - * www - http://www.harbour-project.org - * - */ - -#include "hbdyn.ch" - -#define MB_OK 0x00000000 -#define MB_OKCANCEL 0x00000001 -#define MB_ABORTRETRYIGNORE 0x00000002 -#define MB_YESNOCANCEL 0x00000003 -#define MB_YESNO 0x00000004 -#define MB_RETRYCANCEL 0x00000005 -#define MB_CANCELTRYCONTINUE 0x00000006 -#define MB_ICONHAND 0x00000010 -#define MB_ICONQUESTION 0x00000020 -#define MB_ICONEXCLAMATION 0x00000030 -#define MB_ICONASTERISK 0x00000040 -#define MB_USERICON 0x00000080 -#define MB_DEFBUTTON2 0x00000100 -#define MB_DEFBUTTON3 0x00000200 -#define MB_DEFBUTTON4 0x00000300 -#define MB_SYSTEMMODAL 0x00001000 -#define MB_TASKMODAL 0x00002000 -#define MB_HELP 0x00004000 -#define MB_NOFOCUS 0x00008000 -#define MB_SETFOREGROUND 0x00010000 -#define MB_DEFAULT_DESKTOP_ONLY 0x00020000 -#define MB_TOPMOST 0x00040000 -#define MB_RIGHT 0x00080000 -#define MB_RTLREADING 0x00100000 - -#define CSIDL_APPDATA 0x001a /* \Application Data */ -#define CSIDL_ADMINTOOLS 0x0030 /* \Start Menu\Programs\Administrative Tools */ - -#define MAX_PATH 260 - -PROCEDURE Main() - LOCAL hLib - LOCAL cData - - ? "MsgBox:", hb_dynCall( { "MessageBoxA", "user32.dll" }, 0, "Hello world!", "Harbour sez", hb_bitOr( MB_OKCANCEL, MB_ICONEXCLAMATION, MB_HELP ) ) - - IF hb_FileExists( "libcurl.dll" ) - hLib := hb_LibLoad( "libcurl.dll" ) - ? hb_dynCall( { "curl_version", hLib, HB_DYN_CTYPE_CHAR_PTR } ) - hb_LibFree( hLib ) - ? hb_dynCall( { "curl_version", "libcurl.dll", HB_DYN_CTYPE_CHAR_PTR } ) - ENDIF - - /* Force Windows not to show dragged windows contents */ - - #define SPI_SETDRAGFULLWINDOWS 37 - - ? "Full content drag: OFF" - ? hb_dynCall( { "SystemParametersInfo", "user32.dll" }, SPI_SETDRAGFULLWINDOWS, 0, 0, 0 ) - Inkey( 0 ) - - ? "Full content drag: ON" - ? hb_dynCall( { "SystemParametersInfo", "user32.dll" }, SPI_SETDRAGFULLWINDOWS, 1, 0, 0 ) - Inkey( 0 ) - - /* Get some standard Windows folders */ - - hLib := hb_LibLoad( "shell32.dll" ) - ? "ValType( hLib ): ", ValType( hLib ) - ? "------" - cData := Space( MAX_PATH ) - ? "HB_DYNCALL (BOOL retval): ", hb_dynCall( { "SHGetSpecialFolderPathA", hLib, HB_DYN_CTYPE_BOOL }, 0, @cData, CSIDL_APPDATA, 0 ) - ? "@cData: ", cData - ? "------" - cData := Space( MAX_PATH ) - ? "HB_DYNCALL (BOOL retval): ", hb_dynCall( { GetProcAddress( hLib, "SHGetSpecialFolderPathA" ), HB_DYN_CTYPE_BOOL }, 0, @cData, CSIDL_APPDATA, 0 ) - ? "@cData: ", cData - ? "------" - ? "HB_DYNCALL: ", hb_dynCall( { "SHGetFolderPathA", hLib }, 0, CSIDL_ADMINTOOLS, 0, 0, cData ) // WRONG - ? "cData:", cData - ? "------" - cData := Space( MAX_PATH ) - ? "HB_DYNCALL (PARAMS): ", hb_dynCall( { "SHGetSpecialFolderPathA", hLib, NIL, NIL, NIL, HB_DYN_CTYPE_BOOL }, 0, @cData, CSIDL_APPDATA, 0 ) - ? "@cData: ", cData - ? "------" - cData := Space( MAX_PATH ) - ? "HB_DYNCALL: ", hb_dynCall( { "SHGetFolderPathA", hLib }, 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) - ? "@cData: ", cData - ? "------" - cData := Space( MAX_PATH ) - ? "HB_DYNCALL: ", hb_dynCall( { "SHGetFolderPathW", hLib }, 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) - ? "@cData: ", cData - ? "------" - cData := Space( MAX_PATH ) - ? "cData BEFORE: ", cData - ? "HB_DYNCALL (MISSING @1): ", hb_dynCall( { "SHGetFolderPathA", hLib }, 0, CSIDL_ADMINTOOLS, 0, 0, cData ) - ? "cData AFTER: ", cData - ? "------" - hb_LibFree( hLib ) - - RETURN diff --git a/harbour/contrib/hbwin/tests/testdll1.prg b/harbour/contrib/hbwin/tests/testdll1.prg deleted file mode 100644 index b87ef7aadc..0000000000 --- a/harbour/contrib/hbwin/tests/testdll1.prg +++ /dev/null @@ -1,49 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * DLL call test. - * - * Copyright 2010 Viktor Szakats (harbour.01 syenar.hu) - * www - http://www.harbour-project.org - * - */ - -#include "simpleio.ch" - -#include "hbdyn.ch" - -#define _ISOK_( a, b ) iif( a == b, "OK", "WRONG" ) - -PROCEDURE Main() - LOCAL cFileName - LOCAL a, b - -#if defined( __ARCH64BIT__ ) - cFileName := "test_x64.dll" -#else - cFileName := "test_x86.dll" -#endif - - ? "-", cFileName - a := 567.89 ; ? ">", a, b := win_dllCall( { "TESTD" , cFileName, hb_bitOr( HB_DYN_CTYPE_DOUBLE , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_DOUBLE }, a ), _ISOK_( a, b ) - a := 567.89 ; ? ">", a, b := win_dllCall( { "TESTF" , cFileName, hb_bitOr( HB_DYN_CTYPE_FLOAT , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_FLOAT }, a ), _ISOK_( a, b ) - a := -( 2 ^ 7 ) ; ? ">", a, b := win_dllCall( { "TESTC" , cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_CHAR }, a ), _ISOK_( a, b ) - a := ( 2 ^ 8 ) - 1 ; ? ">", a, b := win_dllCall( { "TESTUC", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_CHAR_UNSIGNED }, a ), _ISOK_( a, b ) - a := -( 2 ^ 15 ) ; ? ">", a, b := win_dllCall( { "TESTS" , cFileName, hb_bitOr( HB_DYN_CTYPE_SHORT , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_SHORT }, a ), _ISOK_( a, b ) - a := ( 2 ^ 16 ) - 1 ; ? ">", a, b := win_dllCall( { "TESTUS", cFileName, hb_bitOr( HB_DYN_CTYPE_SHORT_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_SHORT_UNSIGNED }, a ), _ISOK_( a, b ) - a := -( 2 ^ 31 ) ; ? ">", a, b := win_dllCall( { "TESTI" , cFileName, hb_bitOr( HB_DYN_CTYPE_INT , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_INT }, a ), _ISOK_( a, b ) - a := ( 2 ^ 32 ) - 1 ; ? ">", a, b := win_dllCall( { "TESTUI", cFileName, hb_bitOr( HB_DYN_CTYPE_INT_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_INT_UNSIGNED }, a ), _ISOK_( a, b ) - a := -( 2 ^ 31 ) ; ? ">", a, b := win_dllCall( { "TESTL" , cFileName, hb_bitOr( HB_DYN_CTYPE_LONG , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LONG }, a ), _ISOK_( a, b ) - a := ( 2 ^ 32 ) - 1 ; ? ">", a, b := win_dllCall( { "TESTUL", cFileName, hb_bitOr( HB_DYN_CTYPE_LONG_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LONG_UNSIGNED }, a ), _ISOK_( a, b ) - a := -( 2 ^ 63 ) ; ? ">", a, b := win_dllCall( { "TEST6" , cFileName, hb_bitOr( HB_DYN_CTYPE_LLONG , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LLONG }, a ), _ISOK_( a, b ) - a := 18446744073709600000 ; ? ">", a, b := win_dllCall( { "TESTU6", cFileName, hb_bitOr( HB_DYN_CTYPE_LLONG_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LLONG_UNSIGNED }, a ), _ISOK_( a, b ) - a := "hello world!" ; ? ">", a, b := win_dllCall( { "TESTST", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR , HB_DYN_CALLCONV_CDECL ) }, a ), _ISOK_( a, b ) - ? "==" - - a := "hello world!" ; ? ">", a, win_dllCall( { "TESTST", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR , HB_DYN_CALLCONV_CDECL, HB_DYN_ENC_RAW ), hb_bitOr( HB_DYN_CTYPE_CHAR_PTR, HB_DYN_ENC_RAW ) }, a ) - a := "hello world!" ; ? ">", a, win_dllCallFoxPro( "DECLARE STRING TESTST IN " + cFileName + " STRING", a ) - - RETURN diff --git a/harbour/contrib/hbwin/win_misc.c b/harbour/contrib/hbwin/win_misc.c index b9ba82ce6c..3fc8ddb1c9 100644 --- a/harbour/contrib/hbwin/win_misc.c +++ b/harbour/contrib/hbwin/win_misc.c @@ -303,56 +303,3 @@ HB_FUNC( WIN_SYSREFRESH ) CloseHandle( hDummyEvent ); hb_retni( 0 ); } - -FARPROC hbwin_getprocaddress( HMODULE hDLL, PHB_ITEM pParam, HB_BOOL * pbWIDE ) -{ -#if defined( HB_OS_WIN_CE ) - void * hStr; - HB_SIZE nLen; - LPCWSTR szProc = hb_itemGetStrU16( pParam, HB_CDP_ENDIAN_NATIVE, &hStr, &nLen ); - FARPROC lpFunction = GetProcAddress( hDLL, szProc ? szProc : - ( LPCWSTR ) ( HB_PTRDIFF ) ( hb_itemGetNI( pParam ) & 0x0FFFF ) ); - - if( ! lpFunction && szProc ) /* try with WIDE suffix? */ - { - LPWSTR pszProcW = ( LPWSTR ) hb_xgrab( ( nLen + 2 ) * sizeof( WCHAR ) ); - memcpy( pszProcW, szProc, nLen * sizeof( WCHAR ) ); - pszProcW[ nLen++ ] = L'W'; - pszProcW[ nLen++ ] = 0; - lpFunction = GetProcAddress( hDLL, pszProcW ); - hb_xfree( pszProcW ); - } - hb_strfree( hStr ); - - if( pbWIDE ) - *pbWIDE = HB_TRUE; -#else - const char * szProc = hb_itemGetCPtr( pParam ); - FARPROC lpFunction = GetProcAddress( hDLL, szProc ? szProc : - ( LPCSTR ) ( HB_PTRDIFF ) ( hb_itemGetNI( pParam ) & 0x0FFFF ) ); - - if( pbWIDE ) - *pbWIDE = HB_FALSE; - -#if defined( UNICODE ) - if( ! lpFunction && szProc ) /* try with WIDE suffix? */ - { - char * pszFuncName = hb_xstrcpy( NULL, szProc, "W", NULL ); - lpFunction = GetProcAddress( hDLL, pszFuncName ); - hb_xfree( pszFuncName ); - if( pbWIDE ) - *pbWIDE = HB_TRUE; - } -#endif - - if( ! lpFunction && szProc ) /* try with ANSI suffix? */ - { - char * pszFuncName = hb_xstrcpy( NULL, szProc, "A", NULL ); - lpFunction = GetProcAddress( hDLL, pszFuncName ); - hb_xfree( pszFuncName ); - if( pbWIDE ) - *pbWIDE = HB_FALSE; - } -#endif - return lpFunction; -} diff --git a/harbour/contrib/xhb/Makefile b/harbour/contrib/xhb/Makefile index 2d0e10400d..b2f39e0ddc 100644 --- a/harbour/contrib/xhb/Makefile +++ b/harbour/contrib/xhb/Makefile @@ -49,6 +49,7 @@ PRG_SOURCES := \ dbgfx.prg \ decode.prg \ dirrec.prg \ + diskhb.prg \ dumpvar.prg \ hblog.prg \ hblognet.prg \ diff --git a/harbour/contrib/hbct/diskhb.prg b/harbour/contrib/xhb/diskhb.prg similarity index 100% rename from harbour/contrib/hbct/diskhb.prg rename to harbour/contrib/xhb/diskhb.prg diff --git a/harbour/contrib/xpp/Makefile b/harbour/contrib/xpp/Makefile index 704640af1d..f1713d6d51 100644 --- a/harbour/contrib/xpp/Makefile +++ b/harbour/contrib/xpp/Makefile @@ -38,9 +38,5 @@ PRG_HEADERS := \ dll.ch \ xpp.ch \ -ifneq ($(filter $(HB_PLATFORM),win wce),) - HB_INC_DEPEND := -I$(TOP)$(ROOT)contrib/hbwin -endif - include $(TOP)$(ROOT)config/header.mk include $(TOP)$(ROOT)config/lib.mk diff --git a/harbour/contrib/xpp/dllx.c b/harbour/contrib/xpp/dllx.c index d8805603aa..270ca3f306 100644 --- a/harbour/contrib/xpp/dllx.c +++ b/harbour/contrib/xpp/dllx.c @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * Windows DLL handling function (Xbase++ compatible) + * Dynamic library handling functions (Xbase++ compatible) * * Copyright 2010 Viktor Szakats (harbour.01 syenar.hu) * Copyright 2006 Paul Tucker @@ -56,10 +56,7 @@ #include "hbapierr.h" #include "hbapiitm.h" -#if defined( HB_OS_WIN ) - -#include "hbwin.h" -#include "hbdyn.h" +#include "hbdyn.ch" #include "dll.ch" @@ -221,13 +218,3 @@ HB_FUNC( DLLEXECUTECALL ) 2, NULL ); } - -#else - -HB_FUNC( DLLLOAD ) { hb_retnint( 0 ); } -HB_FUNC( DLLUNLOAD ) { hb_retl( HB_FALSE ); } -HB_FUNC( DLLCALL ) {} -HB_FUNC( DLLPREPARECALL ) {} -HB_FUNC( DLLEXECUTECALL ) {} - -#endif diff --git a/harbour/contrib/xpp/tests/testdll.prg b/harbour/contrib/xpp/tests/testdll.prg index 887664ad15..23063976e2 100644 --- a/harbour/contrib/xpp/tests/testdll.prg +++ b/harbour/contrib/xpp/tests/testdll.prg @@ -2,8 +2,6 @@ * $Id$ */ -#include "simpleio.ch" - /* * Harbour Project source code: * DLL call demonstration. @@ -13,33 +11,9 @@ * */ -#define MB_OK 0x00000000 -#define MB_OKCANCEL 0x00000001 -#define MB_ABORTRETRYIGNORE 0x00000002 -#define MB_YESNOCANCEL 0x00000003 -#define MB_YESNO 0x00000004 -#define MB_RETRYCANCEL 0x00000005 -#define MB_CANCELTRYCONTINUE 0x00000006 -#define MB_ICONHAND 0x00000010 -#define MB_ICONQUESTION 0x00000020 -#define MB_ICONEXCLAMATION 0x00000030 -#define MB_ICONASTERISK 0x00000040 -#define MB_USERICON 0x00000080 -#define MB_DEFBUTTON2 0x00000100 -#define MB_DEFBUTTON3 0x00000200 -#define MB_DEFBUTTON4 0x00000300 -#define MB_SYSTEMMODAL 0x00001000 -#define MB_TASKMODAL 0x00002000 -#define MB_HELP 0x00004000 -#define MB_NOFOCUS 0x00008000 -#define MB_SETFOREGROUND 0x00010000 -#define MB_DEFAULT_DESKTOP_ONLY 0x00020000 -#define MB_TOPMOST 0x00040000 -#define MB_RIGHT 0x00080000 -#define MB_RTLREADING 0x00100000 +#include "simpleio.ch" -#define CSIDL_APPDATA 0x001a /* \Application Data */ -#define CSIDL_ADMINTOOLS 0x0030 /* \Start Menu\Programs\Administrative Tools */ +#include "dll.ch" #define MAX_PATH 260 @@ -47,17 +21,19 @@ PROCEDURE Main() LOCAL hDLL LOCAL cData + #if defined( __PLATFORM__WINDOWS ) + IF hb_FileExists( "pscript.dll" ) hDLL := DllLoad( "pscript.dll" ) cData := Space( 24 ) - DllCall( hDll, NIL, "PSGetVersion", @cData ) + DllCall( hDll, DLL_OSAPI, "PSGetVersion", @cData ) ? ">" + cData + "<" DllUnload( hDLL ) // ; Testing failure 1 hDLL := DllLoad( "pscript.dll" ) cData := Space( 24 ) - DllCall( hDll, NIL, "PSGet__Version", @cData ) + DllCall( hDll, DLL_OSAPI, "PSGet__Version", @cData ) ? ">" + cData + "<" DllUnload( hDLL ) ENDIF @@ -69,28 +45,58 @@ PROCEDURE Main() ? cData DllUnload( hDLL ) - ? "MsgBox:", DllCall( "user32.dll", NIL, "MessageBoxA", 0, "Hello world!", "Harbour sez", hb_bitOr( MB_OKCANCEL, MB_ICONEXCLAMATION, MB_HELP ) ) + #define MB_OK 0x00000000 + #define MB_OKCANCEL 0x00000001 + #define MB_ABORTRETRYIGNORE 0x00000002 + #define MB_YESNOCANCEL 0x00000003 + #define MB_YESNO 0x00000004 + #define MB_RETRYCANCEL 0x00000005 + #define MB_CANCELTRYCONTINUE 0x00000006 + #define MB_ICONHAND 0x00000010 + #define MB_ICONQUESTION 0x00000020 + #define MB_ICONEXCLAMATION 0x00000030 + #define MB_ICONASTERISK 0x00000040 + #define MB_USERICON 0x00000080 + #define MB_DEFBUTTON2 0x00000100 + #define MB_DEFBUTTON3 0x00000200 + #define MB_DEFBUTTON4 0x00000300 + #define MB_SYSTEMMODAL 0x00001000 + #define MB_TASKMODAL 0x00002000 + #define MB_HELP 0x00004000 + #define MB_NOFOCUS 0x00008000 + #define MB_SETFOREGROUND 0x00010000 + #define MB_DEFAULT_DESKTOP_ONLY 0x00020000 + #define MB_TOPMOST 0x00040000 + #define MB_RIGHT 0x00080000 + #define MB_RTLREADING 0x00100000 + + ? "MsgBox:", DllCall( "user32.dll", DLL_OSAPI, "MessageBoxA", 0, "Hello world!", "Harbour sez", hb_bitOr( MB_OKCANCEL, MB_ICONEXCLAMATION, MB_HELP ) ) /* Force Windows not to show dragged windows contents */ #define SPI_SETDRAGFULLWINDOWS 37 ? "Full content drag: OFF" - ? DllCall( "user32.dll", NIL, "SystemParametersInfoA", SPI_SETDRAGFULLWINDOWS, 0, 0, 0 ) + ? DllCall( "user32.dll", DLL_OSAPI, "SystemParametersInfoA", SPI_SETDRAGFULLWINDOWS, 0, 0, 0 ) Inkey( 0 ) ? "Full content drag: ON" - ? DllCall( "user32.dll", NIL, "SystemParametersInfoA", SPI_SETDRAGFULLWINDOWS, 1, 0, 0 ) + ? DllCall( "user32.dll", DLL_OSAPI, "SystemParametersInfoA", SPI_SETDRAGFULLWINDOWS, 1, 0, 0 ) Inkey( 0 ) + #define CSIDL_APPDATA 0x001a /* \Application Data */ + #define CSIDL_ADMINTOOLS 0x0030 /* \Start Menu\Programs\Administrative Tools */ + ? "DLLCALL" cData := Space( MAX_PATH ) - ? DllCall( "shell32.dll", NIL, "SHGetFolderPathA", 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) + ? DllCall( "shell32.dll", DLL_OSAPI, "SHGetFolderPathA", 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) ? "REF:", cData ? "DLLCALL" cData := Space( MAX_PATH ) - ? DllCall( "shell32.dll", NIL, "SHGetFolderPathW", 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) + ? DllCall( "shell32.dll", DLL_OSAPI, "SHGetFolderPathW", 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) ? "REF:", cData + #endif + RETURN diff --git a/harbour/contrib/xpp/xpp.hbc b/harbour/contrib/xpp/xpp.hbc index 1bfbb09e7f..cb3dc3d59a 100644 --- a/harbour/contrib/xpp/xpp.hbc +++ b/harbour/contrib/xpp/xpp.hbc @@ -5,4 +5,3 @@ incpaths=. libs=xpp -{win}libs=hbwin diff --git a/harbour/include/Makefile b/harbour/include/Makefile index 9dbd7fbbfb..78d8ebc0d5 100644 --- a/harbour/include/Makefile +++ b/harbour/include/Makefile @@ -89,6 +89,7 @@ PRG_HEADERS := \ getexit.ch \ hbclass.ch \ hbdebug.ch \ + hbdyn.ch \ hbextcdp.ch \ hbextlng.ch \ hbextern.ch \ diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index c075f5dbc8..c0eb528928 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -1111,6 +1111,8 @@ extern HB_EXPORT HB_BOOL hb_libFree( PHB_ITEM pDynLib ); extern HB_EXPORT void * hb_libHandle( PHB_ITEM pDynLib ); extern HB_EXPORT void * hb_libSymAddr( PHB_ITEM pDynLib, const char * pszSymbol ); +extern HB_EXPORT void hb_dynCall( int iFuncFlags, void * pFunction, int iParams, int iFirst, int * piArgFlags ); + /* 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/contrib/hbwin/hbdyn.ch b/harbour/include/hbdyn.ch similarity index 97% rename from harbour/contrib/hbwin/hbdyn.ch rename to harbour/include/hbdyn.ch index bdce973ab7..17f73cff4a 100644 --- a/harbour/contrib/hbwin/hbdyn.ch +++ b/harbour/include/hbdyn.ch @@ -56,8 +56,8 @@ #define HBDYN_CH_ /* C calling conventions */ -#define HB_DYN_CALLCONV_STDCALL 0x000000 /* Windows API default */ -#define HB_DYN_CALLCONV_CDECL 0x100000 /* C default */ +#define HB_DYN_CALLCONV_CDECL 0x000000 /* C default */ +#define HB_DYN_CALLCONV_STDCALL 0x100000 /* Windows API default */ #define HB_DYN_CALLCONV_SYSCALL 0x200000 /* OS/2 32-bit default. */ /* String encodings */ diff --git a/harbour/src/rtl/Makefile b/harbour/src/rtl/Makefile index b2e0750996..7c558cbe51 100644 --- a/harbour/src/rtl/Makefile +++ b/harbour/src/rtl/Makefile @@ -74,6 +74,8 @@ C_SOURCES := \ hbbit.c \ hbbyte.c \ hbcrc.c \ + hbdyn.c \ + hbdynhb.c \ hbhex.c \ hbfeof.c \ hbmd5.c \ diff --git a/harbour/src/rtl/fstemp.c b/harbour/src/rtl/fstemp.c index 76afedf98a..617fac1057 100644 --- a/harbour/src/rtl/fstemp.c +++ b/harbour/src/rtl/fstemp.c @@ -145,38 +145,9 @@ HB_FHANDLE hb_fsCreateTempEx( char * pszName, const char * pszDir, const char * pszName[ 0 ] = '\0'; if( pszDir && pszDir[ 0 ] != '\0' ) - { hb_strncpy( pszName, pszDir, HB_PATH_MAX - 1 ); - } else - { -#if defined( HB_OS_WIN ) - TCHAR lpName[ HB_PATH_MAX ]; - - if( GetTempPath( HB_PATH_MAX, lpName ) ) - HB_TCHAR_GETFROM( pszName, lpName, HB_PATH_MAX ); - else - { - pszName[ 0 ] = '.'; - pszName[ 1 ] = '\0'; - } -#else - char * pszTmpDir = hb_getenv( "TMPDIR" ); - - if( !fsGetTempDirByCase( pszName, pszTmpDir ) ) - { -#ifdef P_tmpdir - if( !fsGetTempDirByCase( pszName, P_tmpdir ) ) -#endif - { - pszName[ 0 ] = '.'; - pszName[ 1 ] = '\0'; - } - } - if( pszTmpDir ) - hb_xfree( pszTmpDir ); -#endif - } + hb_fsTempDir( pszName ); if( pszName[ 0 ] != '\0' ) { diff --git a/harbour/contrib/hbwin/hbdyn.c b/harbour/src/rtl/hbdyn.c similarity index 99% rename from harbour/contrib/hbwin/hbdyn.c rename to harbour/src/rtl/hbdyn.c index e6e2006660..c05485a378 100644 --- a/harbour/contrib/hbwin/hbdyn.c +++ b/harbour/src/rtl/hbdyn.c @@ -57,7 +57,7 @@ #include "hbset.h" #include "hbstack.h" -#include "hbdyn.h" +#include "hbdyn.ch" #define _MASK_CALLCONV 0xF00000 #define _MASK_ENCODING 0x0F0000 diff --git a/harbour/contrib/hbwin/win_dllc.c b/harbour/src/rtl/hbdynhb.c similarity index 98% rename from harbour/contrib/hbwin/win_dllc.c rename to harbour/src/rtl/hbdynhb.c index 9d24420246..48c4f4dadf 100644 --- a/harbour/contrib/hbwin/win_dllc.c +++ b/harbour/src/rtl/hbdynhb.c @@ -52,13 +52,14 @@ #include "hbapi.h" #include "hbapiitm.h" -#include "hbdyn.h" + +#include "hbdyn.ch" HB_FUNC( HB_DYNCALL ) { PHB_ITEM pParam = hb_param( 1, HB_IT_POINTER | HB_IT_ARRAY ); int * piArgFlags = NULL; - int iFuncFlags = HB_DYN_CALLCONV_STDCALL; + int iFuncFlags = HB_DYN_CALLCONV_CDECL; PHB_ITEM pLibraryHandle = NULL; HB_BOOL bFreeLibrary = HB_FALSE; diff --git a/harbour/contrib/hbwin/tests/testdll.c b/harbour/tests/testdyn.c similarity index 58% rename from harbour/contrib/hbwin/tests/testdll.c rename to harbour/tests/testdyn.c index dd62c42681..d12f08c0b0 100644 --- a/harbour/contrib/hbwin/tests/testdll.c +++ b/harbour/tests/testdyn.c @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * DLL call test. + * Dynamic library call test. * * Copyright 2010 Viktor Szakats (harbour.01 syenar.hu) * www - http://www.harbour-project.org @@ -12,22 +12,22 @@ */ /* Build with: - hbmk2 -hbdyn testdll.c -otest_x86 - hbmk2 -hbdyn testdll.c -otest_x64 + hbmk2 -hbdyn testdyn.c -otest_x86 + hbmk2 -hbdyn testdyn.c -otest_x64 */ #include "hbapi.h" -HB_EXPORT double TESTD ( double value ) { printf( "DLL: %lf\n" , value ); return value; } -HB_EXPORT float TESTF ( float value ) { printf( "DLL: %f\n" , value ); return value; } -HB_EXPORT char TESTC ( char value ) { printf( "DLL: %d\n" , value ); return value; } -HB_EXPORT unsigned char TESTUC( unsigned char value ) { printf( "DLL: %d\n" , value ); return value; } -HB_EXPORT short TESTS ( short value ) { printf( "DLL: %hd\n" , value ); return value; } -HB_EXPORT unsigned short TESTUS( unsigned short value ) { printf( "DLL: %hu\n" , value ); return value; } -HB_EXPORT int TESTI ( int value ) { printf( "DLL: %d\n" , value ); return value; } -HB_EXPORT unsigned int TESTUI( unsigned int value ) { printf( "DLL: %u\n" , value ); return value; } -HB_EXPORT long TESTL ( long value ) { printf( "DLL: %ld\n" , value ); return value; } -HB_EXPORT unsigned long TESTUL( unsigned long value ) { printf( "DLL: %lu\n" , value ); return value; } -HB_EXPORT HB_LONGLONG TEST6 ( HB_LONGLONG value ) { printf( "DLL: %"PFLL"d\n" , value ); return value; } -HB_EXPORT HB_ULONGLONG TESTU6( HB_ULONGLONG value ) { printf( "DLL: %"PFLL"u\n" , value ); return value; } -HB_EXPORT char * TESTST( char * value ) { printf( "DLL: %s\n" , value ); return value; } +HB_EXPORT double TESTD ( double value ) { printf( "DYN: %lf\n" , value ); return value; } +HB_EXPORT float TESTF ( float value ) { printf( "DYN: %f\n" , value ); return value; } +HB_EXPORT char TESTC ( char value ) { printf( "DYN: %d\n" , value ); return value; } +HB_EXPORT unsigned char TESTUC( unsigned char value ) { printf( "DYN: %d\n" , value ); return value; } +HB_EXPORT short TESTS ( short value ) { printf( "DYN: %hd\n" , value ); return value; } +HB_EXPORT unsigned short TESTUS( unsigned short value ) { printf( "DYN: %hu\n" , value ); return value; } +HB_EXPORT int TESTI ( int value ) { printf( "DYN: %d\n" , value ); return value; } +HB_EXPORT unsigned int TESTUI( unsigned int value ) { printf( "DYN: %u\n" , value ); return value; } +HB_EXPORT long TESTL ( long value ) { printf( "DYN: %ld\n" , value ); return value; } +HB_EXPORT unsigned long TESTUL( unsigned long value ) { printf( "DYN: %lu\n" , value ); return value; } +HB_EXPORT HB_LONGLONG TEST6 ( HB_LONGLONG value ) { printf( "DYN: %"PFLL"d\n" , value ); return value; } +HB_EXPORT HB_ULONGLONG TESTU6( HB_ULONGLONG value ) { printf( "DYN: %"PFLL"u\n" , value ); return value; } +HB_EXPORT char * TESTST( char * value ) { printf( "DYN: %s\n" , value ); return value; } diff --git a/harbour/tests/testdyn.prg b/harbour/tests/testdyn.prg new file mode 100644 index 0000000000..2e0ac4a234 --- /dev/null +++ b/harbour/tests/testdyn.prg @@ -0,0 +1,108 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Dynamic library call demonstration. (on Windows) + * + * Copyright 2008 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + * + */ + +#include "simpleio.ch" + +#include "hbdyn.ch" + +#define MAX_PATH 260 + +PROCEDURE Main() + LOCAL hLib + LOCAL cData + + #if defined( __PLATFORM__WINDOWS ) + + #define MB_OK 0x00000000 + #define MB_OKCANCEL 0x00000001 + #define MB_ABORTRETRYIGNORE 0x00000002 + #define MB_YESNOCANCEL 0x00000003 + #define MB_YESNO 0x00000004 + #define MB_RETRYCANCEL 0x00000005 + #define MB_CANCELTRYCONTINUE 0x00000006 + #define MB_ICONHAND 0x00000010 + #define MB_ICONQUESTION 0x00000020 + #define MB_ICONEXCLAMATION 0x00000030 + #define MB_ICONASTERISK 0x00000040 + #define MB_USERICON 0x00000080 + #define MB_DEFBUTTON2 0x00000100 + #define MB_DEFBUTTON3 0x00000200 + #define MB_DEFBUTTON4 0x00000300 + #define MB_SYSTEMMODAL 0x00001000 + #define MB_TASKMODAL 0x00002000 + #define MB_HELP 0x00004000 + #define MB_NOFOCUS 0x00008000 + #define MB_SETFOREGROUND 0x00010000 + #define MB_DEFAULT_DESKTOP_ONLY 0x00020000 + #define MB_TOPMOST 0x00040000 + #define MB_RIGHT 0x00080000 + #define MB_RTLREADING 0x00100000 + + ? "MsgBox:", hb_dynCall( { "MessageBoxA", "user32.dll", HB_DYN_CALLCONV_STDCALL }, 0, "Hello world!", "Harbour sez", hb_bitOr( MB_OKCANCEL, MB_ICONEXCLAMATION, MB_HELP ) ) + + IF hb_FileExists( "libcurl.dll" ) + hLib := hb_LibLoad( "libcurl.dll" ) + ? hb_dynCall( { "curl_version", hLib, HB_DYN_CTYPE_CHAR_PTR } ) + hb_LibFree( hLib ) + ? hb_dynCall( { "curl_version", "libcurl.dll", HB_DYN_CTYPE_CHAR_PTR } ) + ENDIF + + /* Force Windows not to show dragged windows contents */ + + #define SPI_SETDRAGFULLWINDOWS 37 + + ? "Full content drag: OFF" + ? hb_dynCall( { "SystemParametersInfo", "user32.dll", HB_DYN_CALLCONV_STDCALL }, SPI_SETDRAGFULLWINDOWS, 0, 0, 0 ) + Inkey( 0 ) + + ? "Full content drag: ON" + ? hb_dynCall( { "SystemParametersInfo", "user32.dll", HB_DYN_CALLCONV_STDCALL }, SPI_SETDRAGFULLWINDOWS, 1, 0, 0 ) + Inkey( 0 ) + + /* Get some standard Windows folders */ + + #define CSIDL_APPDATA 0x001a /* \Application Data */ + #define CSIDL_ADMINTOOLS 0x0030 /* \Start Menu\Programs\Administrative Tools */ + + hLib := hb_LibLoad( "shell32.dll" ) + ? "ValType( hLib ): ", ValType( hLib ) + ? "------" + cData := Space( MAX_PATH ) + ? "HB_DYNCALL (BOOL retval): ", hb_dynCall( { "SHGetSpecialFolderPathA", hLib, hb_bitOr( HB_DYN_CALLCONV_STDCALL, HB_DYN_CTYPE_BOOL ) }, 0, @cData, CSIDL_APPDATA, 0 ) + ? "@cData: ", cData + ? "------" + ? "HB_DYNCALL: ", hb_dynCall( { "SHGetFolderPathA", hLib, HB_DYN_CALLCONV_STDCALL }, 0, CSIDL_ADMINTOOLS, 0, 0, cData ) // WRONG + ? "cData:", cData + ? "------" + cData := Space( MAX_PATH ) + ? "HB_DYNCALL (PARAMS): ", hb_dynCall( { "SHGetSpecialFolderPathA", hLib, HB_DYN_CALLCONV_STDCALL, NIL, NIL, HB_DYN_CTYPE_BOOL }, 0, @cData, CSIDL_APPDATA, 0 ) + ? "@cData: ", cData + ? "------" + cData := Space( MAX_PATH ) + ? "HB_DYNCALL: ", hb_dynCall( { "SHGetFolderPathA", hLib, HB_DYN_CALLCONV_STDCALL }, 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) + ? "@cData: ", cData + ? "------" + cData := Space( MAX_PATH ) + ? "HB_DYNCALL: ", hb_dynCall( { "SHGetFolderPathW", hLib, HB_DYN_CALLCONV_STDCALL }, 0, CSIDL_ADMINTOOLS, 0, 0, @cData ) + ? "@cData: ", cData + ? "------" + cData := Space( MAX_PATH ) + ? "cData BEFORE: ", cData + ? "HB_DYNCALL (MISSING @1): ", hb_dynCall( { "SHGetFolderPathA", hLib, HB_DYN_CALLCONV_STDCALL }, 0, CSIDL_ADMINTOOLS, 0, 0, cData ) + ? "cData AFTER: ", cData + ? "------" + hb_LibFree( hLib ) + + #endif + + RETURN diff --git a/harbour/tests/testdyn1.prg b/harbour/tests/testdyn1.prg new file mode 100644 index 0000000000..2da06ed2a0 --- /dev/null +++ b/harbour/tests/testdyn1.prg @@ -0,0 +1,49 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Dynamic library call test. + * + * Copyright 2010 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + * + */ + +#include "simpleio.ch" + +#include "hbdyn.ch" + +#define _ISOK_( a, b ) iif( a == b, "OK", "WRONG" ) + +PROCEDURE Main() + LOCAL cFileName + LOCAL a, b + +#if defined( __ARCH64BIT__ ) + cFileName := "test_x64.dll" +#else + cFileName := "test_x86.dll" +#endif + + ? "-", cFileName + a := 567.89 ; ? ">", a, b := hb_dynCall( { "TESTD" , cFileName, hb_bitOr( HB_DYN_CTYPE_DOUBLE , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_DOUBLE }, a ), _ISOK_( a, b ) + a := 567.89 ; ? ">", a, b := hb_dynCall( { "TESTF" , cFileName, hb_bitOr( HB_DYN_CTYPE_FLOAT , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_FLOAT }, a ), _ISOK_( a, b ) + a := -( 2 ^ 7 ) ; ? ">", a, b := hb_dynCall( { "TESTC" , cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_CHAR }, a ), _ISOK_( a, b ) + a := ( 2 ^ 8 ) - 1 ; ? ">", a, b := hb_dynCall( { "TESTUC", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_CHAR_UNSIGNED }, a ), _ISOK_( a, b ) + a := -( 2 ^ 15 ) ; ? ">", a, b := hb_dynCall( { "TESTS" , cFileName, hb_bitOr( HB_DYN_CTYPE_SHORT , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_SHORT }, a ), _ISOK_( a, b ) + a := ( 2 ^ 16 ) - 1 ; ? ">", a, b := hb_dynCall( { "TESTUS", cFileName, hb_bitOr( HB_DYN_CTYPE_SHORT_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_SHORT_UNSIGNED }, a ), _ISOK_( a, b ) + a := -( 2 ^ 31 ) ; ? ">", a, b := hb_dynCall( { "TESTI" , cFileName, hb_bitOr( HB_DYN_CTYPE_INT , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_INT }, a ), _ISOK_( a, b ) + a := ( 2 ^ 32 ) - 1 ; ? ">", a, b := hb_dynCall( { "TESTUI", cFileName, hb_bitOr( HB_DYN_CTYPE_INT_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_INT_UNSIGNED }, a ), _ISOK_( a, b ) + a := -( 2 ^ 31 ) ; ? ">", a, b := hb_dynCall( { "TESTL" , cFileName, hb_bitOr( HB_DYN_CTYPE_LONG , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LONG }, a ), _ISOK_( a, b ) + a := ( 2 ^ 32 ) - 1 ; ? ">", a, b := hb_dynCall( { "TESTUL", cFileName, hb_bitOr( HB_DYN_CTYPE_LONG_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LONG_UNSIGNED }, a ), _ISOK_( a, b ) + a := -( 2 ^ 63 ) ; ? ">", a, b := hb_dynCall( { "TEST6" , cFileName, hb_bitOr( HB_DYN_CTYPE_LLONG , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LLONG }, a ), _ISOK_( a, b ) + a := 18446744073709600000 ; ? ">", a, b := hb_dynCall( { "TESTU6", cFileName, hb_bitOr( HB_DYN_CTYPE_LLONG_UNSIGNED , HB_DYN_CALLCONV_CDECL ), HB_DYN_CTYPE_LLONG_UNSIGNED }, a ), _ISOK_( a, b ) + a := "hello world!" ; ? ">", a, b := hb_dynCall( { "TESTST", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR , HB_DYN_CALLCONV_CDECL ) }, a ), _ISOK_( a, b ) + ? "==" + + a := "hello world!" ; ? ">", a, hb_dynCall( { "TESTST", cFileName, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR , HB_DYN_CALLCONV_CDECL, HB_DYN_ENC_RAW ), hb_bitOr( HB_DYN_CTYPE_CHAR_PTR, HB_DYN_ENC_RAW ) }, a ) +// a := "hello world!" ; ? ">", a, hb_dynCallFoxPro( "DECLARE STRING TESTST IN " + cFileName + " STRING", a ) + + RETURN