Creation of xHarbour PCODE DLL succeeded

Creation of xHarbour PCODE DLL succeeded

Postby RAMESHBABU » Tue Nov 08, 2011 7:48 am

Dear Friends,

I could do some development with the creation of xHarbour's Pcode Dlls sucessfully.

The complete source code and the test is available for download here :

[url]
http://www.aksharasoft.com/pcodedll/MyM ... ce_Bin.rar
http://www.aksharasoft.com/pcodedll/MyMsgBox_Test.rar
http://www.aksharasoft.com/pcodedll/TerminalMode.rar
[/url]

For a detailed reference on the included MyMsgBox Function, please refer this link:

[url]
viewtopic.php?f=3&t=22834
[/url]

I welcome your suggestions.

Regards,

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Creation of xHarbour PCODE DLL succeeded

Postby Marco Turco » Tue Nov 08, 2011 12:05 pm

Hi Babu,
great work !!

Do you know if it is possible to access that xharbour dll from other windows apps (eg. a visual c++ app) ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Creation of xHarbour PCODE DLL succeeded

Postby RAMESHBABU » Tue Nov 08, 2011 1:58 pm

Mr.Marco,

Thanks for your comment.

Even I am trying for a similar solution you are looking for with xHarbour DLLs,
Callable from Windows Programming Languages.

Regards,

-Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Creation of xHarbour PCODE DLL succeeded

Postby Marco Turco » Tue Nov 08, 2011 2:24 pm

Hi Babu,
I don't know if this can help you however there is a Fw sample for harbour.
See testdll.prg and tutor01 into the fwh samples folder.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Creation of xHarbour PCODE DLL succeeded

Postby Antonio Linares » Tue Nov 08, 2011 6:15 pm

Marco,

In order to create a standalone DLL that can be used from any language, the virtual machine has to be included inside the DLL.

So it contains the same code as an EXE but built as a DLL. Everything inside it.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creation of xHarbour PCODE DLL succeeded

Postby RAMESHBABU » Wed Nov 09, 2011 1:08 am

Mr.Antonio,

the virtual machine has to be included inside the DLL.


Is it possible here, in our case ?

Please guide us.

Thanks,

-Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Creation of xHarbour PCODE DLL succeeded

Postby Antonio Linares » Wed Nov 09, 2011 7:14 am

Ramesh,

Please use this buildxd.bat

From FWH samples folder:
buildxd.bat babudll

Code: Select all  Expand view  RUN
@ECHO OFF
CLS
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ FiveWin for xHarbour 11.09 - Sep. 2011          xHarbour development power ³Ü
ECHO ³ (c) FiveTech, 1993-2011     for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7 ³Û
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ECHO ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST

ECHO Building self contained DLL
ECHO Compiling...

if "%FWDIR%" == "" set FWDIR=.\..\
if "%XHDIR%" == "" set XHDIR=c:\xharbour
rem if "%2" == "/b" set GT=gtwin
rem if not "%2" == "/b" set GT=gtgui
set GT=gtgui

set hdir=%XHDIR%
set hdirl=%hdir%\lib
set bcdir=c:\bcc582
set fwh=%FWDIR%

%hdir%\bin\harbour %1 /n /i%fwh%\include;%hdir%\include /w /p %2 %3 > comp.log
IF ERRORLEVEL 1 GOTO COMPILEERRORS
@type comp.log

echo -O2 -e%1.exe -I%hdir%\include -I%bcdir%\include %1.c > b32.bc
%bcdir%\bin\bcc32 -M -c -v @b32.bc
:ENDCOMPILE

IF EXIST %1.rc %bcdir%\bin\brc32 -r -I%bcdir%\include %1

echo %bcdir%\lib\c0w32.obj %hdir%\xharbour\obj\b32\maindll.obj + > b32.bc
echo %1.obj, + >> b32.bc
echo %1.dll, + >> b32.bc
echo %1.map, + >> b32.bc
echo %fwh%\lib\Fivehx.lib %fwh%\lib\FiveHC.lib + >> b32.bc
echo %hdirl%\rtl.lib + >> b32.bc
echo %hdirl%\vm.lib + >> b32.bc
echo %hdirl%\%GT%.lib + >> b32.bc
echo %hdirl%\lang.lib + >> b32.bc
echo %hdirl%\macro.lib + >> b32.bc
echo %hdirl%\rdd.lib + >> b32.bc
echo %hdirl%\dbfntx.lib + >> b32.bc
echo %hdirl%\dbfcdx.lib + >> b32.bc
echo %hdirl%\dbffpt.lib + >> b32.bc
echo %hdirl%\hbsix.lib + >> b32.bc
echo %hdirl%\debug.lib + >> b32.bc
echo %hdirl%\common.lib + >> b32.bc
echo %hdirl%\pp.lib + >> b32.bc
echo %hdirl%\pcrepos.lib + >> b32.bc
echo %hdirl%\ct.lib + >> b32.bc
echo %hdirl%\zlib.lib + >> b32.bc
echo %hdirl%\hbzip.lib + >> b32.bc

rem Uncomment these two lines to use Advantage RDD
rem echo %hdir%\lib\rddads.lib + >> b32.bc
rem echo %hdir%\lib\Ace32.lib + >> b32.bc

echo %bcdir%\lib\cw32.lib + >> b32.bc
echo %bcdir%\lib\import32.lib + >> b32.bc
echo %bcdir%\lib\uuid.lib + >> b32.bc
echo %bcdir%\lib\psdk\odbc32.lib + >> b32.bc
echo %bcdir%\lib\psdk\rasapi32.lib + >> b32.bc
echo %bcdir%\lib\psdk\nddeapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\msimg32.lib + >> b32.bc
echo %bcdir%\lib\psdk\psapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\gdiplus.lib + >> b32.bc
echo %bcdir%\lib\psdk\iphlpapi.lib, >> b32.bc

IF EXIST %1.res echo %1.res >> b32.bc

rem uncomment this line to use the debugger and comment the following one
rem if %GT% == gtwin %bcdir%\bin\ilink32 -Gn -Tpd -s -v @b32.bc
rem IF ERRORLEVEL 1 GOTO LINKERROR
if %GT% == gtgui %bcdir%\bin\ilink32 -Gn -aa -Tpd -s -v @b32.bc
IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * DLL successfully built *
GOTO EXIT
ECHO

rem delete temporary files
@del %1.c

:COMPILEERRORS
@type comp.log
ECHO * Compile errors *
GOTO EXIT

:LINKERROR
ECHO * Linking 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creation of xHarbour PCODE DLL succeeded

Postby Antonio Linares » Wed Nov 09, 2011 7:51 am

I am checking FWH samples babu.prg and babudll.prg and I noticed that HBDLLENTRY2 is not defined in xHarbour maindll.c. There is only a HBBDLLENTRY::

I have added the HB_EXPORT clause to it as the DLL must export it in order to use it:
Code: Select all  Expand view  RUN
void HB_EXPORT HBDLLENTRY( char * cProcName )
{
   hb_itemDoC( cProcName, 0, 0 );

   return 0;
}


Anyhow still we are missing something, as if I do:

impdef.exe babudll.def babudll.dll

HBDLLENTRY is not listed in babudll.def
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creation of xHarbour PCODE DLL succeeded

Postby Marco Turco » Mon Nov 14, 2011 11:47 am

Hi,
I made some tests linking bubudll as dll but babu still doen't runs (hx_xrealloc error). Any ideas ?
Thanks in advance.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Creation of xHarbour PCODE DLL succeeded

Postby Antonio Linares » Mon Nov 14, 2011 12:32 pm

Marco,

are you testing FWH samples\babu.prg and babudll.prg ?

How are you building them ? Are you using xHb.com or Borland ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creation of xHarbour PCODE DLL succeeded

Postby Marco Turco » Mon Nov 14, 2011 1:02 pm

Hi,
I'm using borland 582 and FWH 10.11,
I'm build babudll with your buildxd.bat and the maindllp.c provided in this thread (I hadn't a maindll.c in my xharbour\obj\bc32 folder) .
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Creation of xHarbour PCODE DLL succeeded

Postby Antonio Linares » Mon Nov 14, 2011 1:50 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creation of xHarbour PCODE DLL succeeded

Postby Marco Turco » Mon Nov 14, 2011 6:33 pm

Hi Antonio,
I tried but babu always return a nil msginfo now.
Any ideas ? Thanks in advance.

My tests on www.softwarexp.co.uk/beta/test.zip
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Creation of xHarbour PCODE DLL succeeded

Postby Antonio Linares » Mon Nov 14, 2011 11:53 pm

Marco, Babu,

I have modified FWH samples\babudll.prg to include the DLL required C source code, so now there is no need to link maindll.obj :-) Please remember to remove maindll.obj from buildhd.bat and also remove the -aa flag for ilink32.

I have tested it with Harbour and it is working fine. Next I will test it with xHarbour, though it should work fine also.

babudll.prg
Code: Select all  Expand view  RUN
// To build BabuDLL.dll do: buildhd.bat babuDLL

// To run this DLL, do buidh.bat Babu.prg

function Test()

   MsgInfo( "Hello from inside the DLL!" )
   
return nil  

function Test2( cMsg1, cMsg2 )

   MsgInfo( cMsg1, cMsg2 )

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( HB_FALSE );
           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 );
}  

void pascal __export HBDLLENTRY2( char * cProcName, PHB_ITEM pParam1, PHB_ITEM pParam2 )
{
   hb_itemDoC( cProcName, 2, pParam1, pParam2 );
}  

#pragma ENDDUMP


babu.prg:
Code: Select all  Expand view  RUN
// Using Harbour DLLs
// To build BabuDLL.dll do: buildhd.bat babuDLL

#include "FiveWin.ch"

static hDLL

function Main()

   local hItem1 := ItemNew( "Hello world!" )
   local hItem2 := ItemNew( "From a Harbour DLL" )

   hDLL = LoadLibrary( "babudll.dll" )

   HbDllEntry( "TEST" )

   HbDLLEntry2( "TEST2", hItem1, hItem2 )
   
   ItemRelease( hItem1 )
   ItemRelease( hItem2 )
   
   MsgInfo( "back from EXE" )
   
   FreeLibrary( hDLL )

return nil

DLL FUNCTION HBDLLENTRY( cProc AS LPSTR ) AS LONG PASCAL LIB hDLL

DLL FUNCTION HBDLLENTRY2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB hDLL

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>

HB_FUNC( ITEMNEW )
{
   hb_retnl( ( unsigned long ) hb_itemNew( hb_param( 1, HB_IT_ANY ) ) );
}

HB_FUNC( ITEMRELEASE )
{
   hb_retl( hb_itemRelease( ( PHB_ITEM ) hb_parnl( 1 ) ) );
}

#pragma ENDDUMP    


Please notice that in order to use "static hDLL" from babu.prg these changes are required in FWH dll.ch.
dll.ch:
Code: Select all  Expand view  RUN
// Copyright FiveTech 1993-2011

#ifndef _DLL_CH
#define _DLL_CH

#ifndef _C_TYPES
   #define _C_TYPES
   #define VOID     0
   #define BYTE     1
   #define CHAR     2
   #define WORD     3

#ifdef __CLIPPER__
   #define _INT     4         // conflicts with Clipper Int()
#else
   #define _INT     7
#endif

   #define BOOL     5
   #define HDC      6
   #define LONG     7
   #define STRING   8
   #define LPSTR    9
   #define PTR     10
   #define _DOUBLE 11         // conflicts with BORDER DOUBLE
   #define DWORD   12
#endif

#translate NOREF([@]<x>) => <x>

#ifndef __HARBOUR__
  #ifndef __XPP__
     #ifndef __CLIPPER__
        #ifndef __C3__
           #define __CLIPPER__
        #endif
     #endif
  #endif
#endif

#ifndef __CLIPPER__
   #translate DLL32 => DLL
#endif

//----------------------------------------------------------------------------//

#xcommand DLL [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
                                                     [, <uParamN> AS <typeN> ] ) ;
             AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
       => ;
          [<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
             local _hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLibrary( <(DllName)> ) ) ;;
             local uResult ;;
             local cFarProc ;;
             if Abs( _hDLL ) > 32 ;;
                cFarProc = GetProcAdd( _hDLL,;
                If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
                [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
                uResult = FWCallDLL( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
                If( ValType( <DllName> ) == "N",, FreeLibrary( _hDLL ) ) ;;
             else ;;
                MsgAlert( "Error code: " + LTrim( Str( _hDLL ) ) + " loading " + ;
                If( ValType( <DllName> ) == "C", <DllName>, Str( <DllName> ) ) ) ;;
             end ;;
          return uResult

//----------------------------------------------------------------------------//

#xcommand DLL32 [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
                                                      [, <uParamN> AS <typeN> ] ) ;
             AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
       => ;
          [<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
             local _hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLib32( <(DllName)> ) ) ;;
             local uResult ;;
             local cFarProc ;;
             if Abs( _hDLL ) <= 32 ;;
                MsgAlert( "Error code: " + LTrim( Str( _hDLL ) ) + " loading " + <DllName> ) ;;
             else ;;
                cFarProc = GetProc32( _hDLL,;
                If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
                [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
                uResult = FWCallDLL32( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
                If( ValType( <DllName> ) == "N",, FreeLib32( _hDLL ) ) ;;
             end ;;
          return uResult

#endif

//----------------------------------------------------------------------------//


You can download the source code, EXE and DLL from here:
http://code.google.com/p/fivewin-contributions/downloads/detail?name=babudll.zop&can=2&q=
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creation of xHarbour PCODE DLL succeeded

Postby RAMESHBABU » Tue Nov 15, 2011 5:37 am

Mr.Antonio,

Thank you very much for your continuous effort on xHarbour PCODE DLL

I could create BABUDLL.DLL with xHarbour with the changes you have suggested
in the BuildHd.bat and I could even build BABU.EXE.

But when I call BABU.DLL, it is calling TEST() sucessfully from the DLL.
But TEST2(...) with parameters is not called at all.

More over the the following messages are not shown when the newly compiled
dll is loaded:

MessageBox( 0, "DLL properly loaded", "DLL entry", 0 )
MessageBox( 0, "DLL unloaded", "DLL exit", 0 )
MsgInfo("back from EXE")

Since the new dll.ch is calling FWCALLDLL, I have useda older version of FWH only.

Regards,

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests