create a harbour dll containing functions to be executed
-
- Posts: 17
- Joined: Thu Feb 28, 2008 6:56 pm
create a harbour dll containing functions to be executed
I am trying to run the sample harbour dll - testdll and tutor01. I am able to create the sample testdll.exe and tutor01.dll, however when executed a message is thrown - error code 0 loading tutor01.dll. Why does this simple sample not work?
Re: create a harbour dll containing functions to be executed
Last edited by Rochinha on Tue Sep 06, 2016 8:29 pm, edited 1 time in total.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
Perry,
Please modify tutor01.prg this way:
Please modify tutor01.prg this way:
Code: Select all
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
MsgInfo( "Hello world from Harbour and FWH!" )
return nil
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <windows.h>
#include <hbvm.h>
#include <hbapiitm.h>
BOOL WINAPI DllEntryPoint( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
HB_SYMBOL_UNUSED( hinstDLL );
HB_SYMBOL_UNUSED( fdwReason );
HB_SYMBOL_UNUSED( lpvReserved );
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
MessageBox( 0, "DLL properly loaded", "DLL entry", 0 );
hb_vmInit( 0 );
break;
case DLL_PROCESS_DETACH:
MessageBox( 0, "DLL unloaded", "DLL exit", 0 );
break;
}
return TRUE;
}
void pascal __export HBDLLENTRY( char * cProcName )
{
hb_itemDoC( cProcName, 0 );
}
#pragma ENDDUMP
-
- Posts: 17
- Joined: Thu Feb 28, 2008 6:56 pm
Re: create a harbour dll containing functions to be executed
Thank you Antonio, This now works, However now I am trying the sample testmydl and mydll which passes parameters to the dll. When I execute this test the following error is thrown: Error code 0 loading MYDLL.dll. Thank you in advance for your help in resolving this issue.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
Perry,
Try adding this code to mydll.prg
Try adding this code to mydll.prg
Code: Select all
BOOL WINAPI DllEntryPoint( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
HB_SYMBOL_UNUSED( hinstDLL );
HB_SYMBOL_UNUSED( fdwReason );
HB_SYMBOL_UNUSED( lpvReserved );
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
MessageBox( 0, "DLL properly loaded", "DLL entry", 0 );
hb_vmInit( 0 );
break;
case DLL_PROCESS_DETACH:
MessageBox( 0, "DLL unloaded", "DLL exit", 0 );
break;
}
return TRUE;
}
-
- Posts: 17
- Joined: Thu Feb 28, 2008 6:56 pm
Re: create a harbour dll containing functions to be executed
That works fine, Thank you Antonio.
One more item - we have the need to pass values back from the DLL to the calling EXE. Is this possible? Is pass by reference "@" a way to modify the value in the DLL and return to the EXE? Do you have to have the same number of parms for each function in the DLL?
One more item - we have the need to pass values back from the DLL to the calling EXE. Is this possible? Is pass by reference "@" a way to modify the value in the DLL and return to the EXE? Do you have to have the same number of parms for each function in the DLL?
Last edited by Perry Nichols on Wed Aug 31, 2016 7:42 pm, edited 2 times in total.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
Perry,
> we have the need to pass values back from the DLL to the calling EXE. Is this possible ?
Yes. What types of values do you need to pass back ? character, number, etc ? We need to know their types in advance.
> Is pass by reference "@" a way to modify the value in the DLL and return to the EXE ?
We can implement it in the function HBDLLENTRY() itself
> Do you have to have the same number of parms for each function in the DLL?
You can implement several functions for each number of params to pass:
void pascal __export HBDLLENTRY1( char * cProcName, PHB_ITEM pParam1 )
{
hb_itemDoC( cProcName, 1, pParam1 );
}
void pascal __export HBDLLENTRY2( char * cProcName, PHB_ITEM pParam1, PHB_ITEM pParam2 )
{
hb_itemDoC( cProcName, 2, pParam1, pParam2 );
}
etc.
> we have the need to pass values back from the DLL to the calling EXE. Is this possible ?
Yes. What types of values do you need to pass back ? character, number, etc ? We need to know their types in advance.
> Is pass by reference "@" a way to modify the value in the DLL and return to the EXE ?
We can implement it in the function HBDLLENTRY() itself
> Do you have to have the same number of parms for each function in the DLL?
You can implement several functions for each number of params to pass:
void pascal __export HBDLLENTRY1( char * cProcName, PHB_ITEM pParam1 )
{
hb_itemDoC( cProcName, 1, pParam1 );
}
void pascal __export HBDLLENTRY2( char * cProcName, PHB_ITEM pParam1, PHB_ITEM pParam2 )
{
hb_itemDoC( cProcName, 2, pParam1, pParam2 );
}
etc.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
> We can implement it in the function HBDLLENTRY() itself
void pascal __export HBDLLENTRY1( char * cProcName, PHB_ITEM pParam1 )
{
hb_itemDoC( cProcName, 1, pParam1 );
if( HB_ISBYREF( pParam1 ) )
hb_itemPutC( pParam1, hb_retc( -1 ) ); // -1 mean the value returned from cProcName
}
void pascal __export HBDLLENTRY1( char * cProcName, PHB_ITEM pParam1 )
{
hb_itemDoC( cProcName, 1, pParam1 );
if( HB_ISBYREF( pParam1 ) )
hb_itemPutC( pParam1, hb_retc( -1 ) ); // -1 mean the value returned from cProcName
}
-
- Posts: 17
- Joined: Thu Feb 28, 2008 6:56 pm
Re: create a harbour dll containing functions to be executed
Antonio, Thank you for the info - much appreciated.
Regarding passing parameters -
> You can implement several functions for each number of params to pass:
does each parm have to be the same data type in all functions?
Also, I am looking at the samples in FWH64 v1605 and the buildhd.bat looks like a 32 bit build for borland - is there a bat to build a 64bit dll?
Regarding passing parameters -
> You can implement several functions for each number of params to pass:
does each parm have to be the same data type in all functions?
Also, I am looking at the samples in FWH64 v1605 and the buildhd.bat looks like a 32 bit build for borland - is there a bat to build a 64bit dll?
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
Perry,
> does each parm have to be the same data type in all functions?
They have to be Harbour "items", thats why you need to use the function ItemNew():
http://forums.fivetechsupport.com/viewt ... 5&start=15
> Also, I am looking at the samples in FWH64 v1605 and the buildhd.bat looks like a 32 bit build for borland - is there a bat to build a 64bit dll?
We have not created it yet. I am going to try to create it
Please keep in mind that if you use a 64 bits DLL then you must use a 64 bits EXE to call it
> does each parm have to be the same data type in all functions?
They have to be Harbour "items", thats why you need to use the function ItemNew():
http://forums.fivetechsupport.com/viewt ... 5&start=15
> Also, I am looking at the samples in FWH64 v1605 and the buildhd.bat looks like a 32 bit build for borland - is there a bat to build a 64bit dll?
We have not created it yet. I am going to try to create it
Please keep in mind that if you use a 64 bits DLL then you must use a 64 bits EXE to call it
-
- Posts: 17
- Joined: Thu Feb 28, 2008 6:56 pm
Re: create a harbour dll containing functions to be executed
can we execute a 32 bit dll from a 64 bit exe?
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
Perry,
> can we execute a 32 bit dll from a 64 bit exe?
No, as far as I know
> can we execute a 32 bit dll from a 64 bit exe?
No, as far as I know
Re: create a harbour dll containing functions to be executed
I have FWH 16.02 & Harbour 3.2.0dev
I tried my original MYDLL.PRG with BUILDHD,bat, but i got many errors :
Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
Error: Unresolved external '_HB_FUN_CTOT' referenced from C:\FWH7\LIB\FIVEH.LIB|VALBLANK
Error: Unresolved external '_HB_FUN_HB_COMPILEFROMBUF' referenced from C:\FWH7\LIB\FIVEH.LIB|HARBOUR
Error: Unresolved external '_HB_FUN_TOLEAUTO' referenced from C:\FWH7\LIB\FIVEH.LIB|HARBOUR
Error: Unresolved external '_HB_FUN_HHASKEY' referenced from C:\FWH7\LIB\FIVEH.LIB|FWDECODE
Error: Unresolved external '_HB_FUN_OS_ISWTSCLIENT' referenced from C:\FWH7\LIB\FIVEH.LIB|MENU
Error: Unresolved external '_HB_FUN_NUMAT' referenced from C:\FWH7\LIB\FIVEH.LIB|MENUITEM
.
.
and many other
************
I inserted in MYDLL.PRG the:
BOOL WINAPI DllEntryPoint( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
HB_SYMBOL_UNUSED( hinstDLL );
HB_SYMBOL_UNUSED( fdwReason );
HB_SYMBOL_UNUSED( lpvReserved );
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
MessageBox( 0, "DLL properly loaded", "DLL entry", 0 );
hb_vmInit( 0 );
break;
case DLL_PROCESS_DETACH:
MessageBox( 0, "DLL unloaded", "DLL exit", 0 );
break;
}
return TRUE;
BUT I GOT THIS ERROR:
mydll.prg(22) Error E0030 Syntax error "syntax error at 'WINAPI'"
mydll.prg(24) Error E0020 Incomplete statement or unbalanced delimiters
mydll.prg(28) Error E0030 Syntax error "syntax error at '('"
mydll.prg(30) Error E0020 Incomplete statement or unbalanced delimiters
mydll.prg(31) Error E0020 Incomplete statement or unbalanced delimiters
mydll.prg(35) Error E0030 Syntax error "syntax error at 'HB_VMINIT'"
mydll.prg(36) Error E0030 Syntax error "syntax error at 'CASE'"
mydll.prg(39) Error E0030 Syntax error "syntax error at 'BREAK'"
mydll.prg(42) Warning W0001 Ambiguous reference 'TRUE'
mydll.prg(43) Error E0030 Syntax error "syntax error at '}'"
mydll.prg(44) Error E0017 Unclosed control structure 'SWITCH'
Any help ?
I tried my original MYDLL.PRG with BUILDHD,bat, but i got many errors :
Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
Error: Unresolved external '_HB_FUN_CTOT' referenced from C:\FWH7\LIB\FIVEH.LIB|VALBLANK
Error: Unresolved external '_HB_FUN_HB_COMPILEFROMBUF' referenced from C:\FWH7\LIB\FIVEH.LIB|HARBOUR
Error: Unresolved external '_HB_FUN_TOLEAUTO' referenced from C:\FWH7\LIB\FIVEH.LIB|HARBOUR
Error: Unresolved external '_HB_FUN_HHASKEY' referenced from C:\FWH7\LIB\FIVEH.LIB|FWDECODE
Error: Unresolved external '_HB_FUN_OS_ISWTSCLIENT' referenced from C:\FWH7\LIB\FIVEH.LIB|MENU
Error: Unresolved external '_HB_FUN_NUMAT' referenced from C:\FWH7\LIB\FIVEH.LIB|MENUITEM
.
.
and many other
************
I inserted in MYDLL.PRG the:
BOOL WINAPI DllEntryPoint( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
HB_SYMBOL_UNUSED( hinstDLL );
HB_SYMBOL_UNUSED( fdwReason );
HB_SYMBOL_UNUSED( lpvReserved );
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
MessageBox( 0, "DLL properly loaded", "DLL entry", 0 );
hb_vmInit( 0 );
break;
case DLL_PROCESS_DETACH:
MessageBox( 0, "DLL unloaded", "DLL exit", 0 );
break;
}
return TRUE;
BUT I GOT THIS ERROR:
mydll.prg(22) Error E0030 Syntax error "syntax error at 'WINAPI'"
mydll.prg(24) Error E0020 Incomplete statement or unbalanced delimiters
mydll.prg(28) Error E0030 Syntax error "syntax error at '('"
mydll.prg(30) Error E0020 Incomplete statement or unbalanced delimiters
mydll.prg(31) Error E0020 Incomplete statement or unbalanced delimiters
mydll.prg(35) Error E0030 Syntax error "syntax error at 'HB_VMINIT'"
mydll.prg(36) Error E0030 Syntax error "syntax error at 'CASE'"
mydll.prg(39) Error E0030 Syntax error "syntax error at 'BREAK'"
mydll.prg(42) Warning W0001 Ambiguous reference 'TRUE'
mydll.prg(43) Error E0030 Syntax error "syntax error at '}'"
mydll.prg(44) Error E0017 Unclosed control structure 'SWITCH'
Any help ?
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: create a harbour dll containing functions to be executed
Please use this buildhd.bat file:
Code: Select all
@ECHO OFF
CLS
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ FiveWin for Harbour 16.06 - Jun. 2016 Harbour development power ³Ü
ECHO ³ (c) FiveTech, 1993-2016 for Microsoft Windows 9x/NT/2000/ME/XP/Vista/7/8 ³Û
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ECHO ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST
if "%FWDIR%" == "" set FWDIR=.\..
if "%HBDIR%" == "" set HBDIR=c:\harbour
rem if "%2" == "/b" set GT=gtwin
rem if not "%2" == "/b" set GT=gtgui
set GT=gtgui
ECHO Compiling...
set hdir=%HBDIR%
set hdirl=%hdir%\lib
set fwh=%FWDIR%
if exist c:\bcc7 set bcdir=c:\bcc7
if exist c:\bcc64 set bcdir=c:\bcc64
%hdir%\bin\harbour %1 /n /i..\include;%hdir%\include /w /p %2 %3 > clip.log 2> warnings.log
@type clip.log
@type warnings.log
IF ERRORLEVEL 1 PAUSE
IF ERRORLEVEL 1 GOTO EXIT
echo -O2 -I%hdir%\include %1.c > b32.bc
%bcdir%\bin\bcc32 -M -c @b32.bc
:ENDCOMPILE
IF EXIST %1.rc %bcdir%\bin\brc32 -r %1
echo c0d32.obj + > b32.bc
echo %1.obj, + >> b32.bc
echo %1.dll, + >> b32.bc
echo %1.map, + >> b32.bc
echo ..\lib\FiveH.lib ..\lib\FiveHC.lib + >> b32.bc
echo %hdirl%\hbwin.lib + >> b32.bc
echo %hdirl%\gtgui.lib + >> b32.bc
echo %hdirl%\hbrtl.lib + >> b32.bc
echo %hdirl%\hbvm.lib + >> b32.bc
echo %hdirl%\hblang.lib + >> b32.bc
echo %hdirl%\hbmacro.lib + >> b32.bc
echo %hdirl%\hbrdd.lib + >> b32.bc
echo %hdirl%\rddntx.lib + >> b32.bc
echo %hdirl%\rddcdx.lib + >> b32.bc
echo %hdirl%\rddfpt.lib + >> b32.bc
echo %hdirl%\hbsix.lib + >> b32.bc
echo %hdirl%\hbdebug.lib + >> b32.bc
echo %hdirl%\hbcommon.lib + >> b32.bc
echo %hdirl%\hbpp.lib + >> b32.bc
echo %hdirl%\hbcpage.lib + >> b32.bc
echo %hdirl%\hbcplr.lib + >> b32.bc
echo %hdirl%\hbct.lib + >> b32.bc
echo %hdirl%\hbpcre.lib + >> b32.bc
echo %hdirl%\xhb.lib + >> b32.bc
echo %hdirl%\hbziparc.lib + >> b32.bc
echo %hdirl%\hbmzip.lib + >> b32.bc
echo %hdirl%\hbzlib.lib + >> b32.bc
echo %hdirl%\minizip.lib + >> b32.bc
echo %hdirl%\png.lib + >> b32.bc
echo %hdirl%\hbusrrdd.lib + >> b32.bc
echo %hdirl%\hbtip.lib + >> b32.bc
rem Uncomment these two lines to use Advantage RDD
rem echo %hdir%\lib\b32\rddads.lib + >> b32.bc
rem echo ..\lib\Ace32.lib + >> b32.bc
echo %bcdir%\lib\cw32.lib + >> b32.bc
echo %bcdir%\lib\uuid.lib + >> b32.bc
echo %bcdir%\lib\import32.lib + >> b32.bc
echo %bcdir%\lib\ws2_32.lib + >> b32.bc
echo %bcdir%\lib\psdk\odbc32.lib + >> b32.bc
echo %bcdir%\lib\psdk\nddeapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\iphlpapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\msimg32.lib + >> b32.bc
echo %bcdir%\lib\psdk\psapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\rasapi32.lib + >> b32.bc
echo %bcdir%\lib\psdk\gdiplus.lib + >> b32.bc
echo %bcdir%\lib\psdk\shell32.lib, >> b32.bc
IF EXIST %1.res echo %1.res >> b32.bc
%bcdir%\bin\ilink32 -Tpd @b32.bc
IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * self contained DLL successfully built
GOTO EXIT
ECHO
rem delete temporary files
@del %1.c
@del %1.il?
:LINKERROR
ECHO * There are errors
GOTO EXIT
:SINTAX
ECHO SYNTAX: Build [Program] {-- No especifiques la extensi¢n PRG
ECHO {-- Don't specify .PRG extension
GOTO EXIT
:NOEXIST
ECHO The specified PRG %1 does not exist
:EXIT
Re: create a harbour dll containing functions to be executed
Now the MYDLL.DLL has been created with your new buildhd.bat and (usin the original mydll.prg)
But using the
BUILDH.BAT TESTMYDL.PRG and running the TESTMYDL.EXE it gives:
Error code: 0 loading MYDLL.dll
Ops !!!
But using the
BUILDH.BAT TESTMYDL.PRG and running the TESTMYDL.EXE it gives:
Error code: 0 loading MYDLL.dll
Ops !!!