Creating a LIB or DLL

Re: Creating a LIB or DLL

Postby Antonio Linares » Sat Mar 28, 2009 2:58 pm

Dave,

Please build FWH\samples\tutor01.prg and check if you get the first MessageBox() from hb_vmInit()

FWH\samples\buildh.bat tutor01

Here it shows fine.
regards, saludos

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

Re: Creating a LIB or DLL

Postby Dave Zowasky » Sat Mar 28, 2009 3:25 pm

Antonio,

I created a new folder called HS2 and did my checkout in to it.

I copied over my makeb32.bat, make_b32.bat, make_b32.mak. and common.mak

My makeb32.bat
Code: Select all  Expand view  RUN

    del \harbour\bin\*.exe
    del \hs2\harbour\bin\*.exe

    SET LIB=c:\bcc55\lib
    SET INCLUDE=c:\bcc55\include
    SET PATH=c:\bcc55\bin;%PATH%

    SET HB_CC_NAME=b32
    SET HB_ARCHITECTURE=w32
    SET HB_GT_LIB=gtgui
    SET HB_GT_DEFAULT=gui
    SET HB_BUILD_MODE=c
    SET C_USR= -DHARBOUR_MAIN_WIN -DHB_DYNLIB -DHB_FM_STATISTICS_OFF -d -a8 -OS -O2 -5 -6
    SET HB_BUILD_DLL=no
    SET HB_MAKE_PROGRAM=c:\bcc55\bin\make.exe

    make_b32
     
    copy \hs2\harbour\bin\*.exe \harbour\bin
 




My make_b32.bat
Code: Select all  Expand view  RUN
@echo off
rem
rem $Id: make_b32.bat 9312 2008-09-05 00:08:34Z vszakats $
rem

rem ---------------------------------------------------------------
rem This is a generic template file, if it doesn't fit your own needs
rem please DON'
T MODIFY IT.
rem
rem Instead, make a local copy and modify that one, or make a call to
rem this batch file from your customized one. [vszakats]
rem
rem Set any of the below settings to customize your build process:
   set HB_BUILD_DLL=yes
rem    set HB_BUILD_DEBUG=yes
rem    set HB_BUILD_VERBOSE=yes
rem    set HB_REBUILD_PARSER=yes
rem    set HB_MAKE_PROGRAM=
rem    set HB_SHOW_ERRORS=
rem    set HB_MAKE_FLAGS=
rem ---------------------------------------------------------------

set _HB_CC_NAME=%HB_CC_NAME%
set _HB_MAKE_PROGRAM=%HB_MAKE_PROGRAM%

if "%_HB_CC_NAME%"      == "" set _HB_CC_NAME=b32
if "%_HB_MAKE_PROGRAM%" == "" set _HB_MAKE_PROGRAM=make.exe

set _HB_MAKEFILE=make_b32.mak
set HB_EXIT_LEVEL=

rem ---------------------------------------------------------------

rem Save the user value, force silent file overwrite with COPY
rem (not all Windows versions support the COPY /Y flag)
set HB_ORGENV_COPYCMD=%COPYCMD%
set COPYCMD=/Y

rem ---------------------------------------------------------------

if "%1" == "clean" goto CLEAN
if "%1" == "Clean" goto CLEAN
if "%1" == "CLEAN" goto CLEAN
if "%1" == "install" goto INSTALL
if "%1" == "Install" goto INSTALL
if "%1" == "INSTALL" goto INSTALL

:BUILD

   %_HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %_HB_MAKEFILE% %1 %2 %3 > make_%_HB_CC_NAME%.log
   if errorlevel 1 set HB_EXIT_LEVEL=1
   if errorlevel 1 if not "%HB_SHOW_ERRORS%" == "no" notepad make_%_HB_CC_NAME%.log
   goto EXIT

:CLEAN

   %_HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %_HB_MAKEFILE% CLEAN > make_%_HB_CC_NAME%.log
   if errorlevel 1 set HB_EXIT_LEVEL=1
   if errorlevel 1 goto EXIT
   if exist make_%_HB_CC_NAME%.log del make_%_HB_CC_NAME%.log > nul
   if exist inst_%_HB_CC_NAME%.log del inst_%_HB_CC_NAME%.log > nul
   goto EXIT

:INSTALL

   %_HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %_HB_MAKEFILE% INSTALL > nul
   if errorlevel 1 set HB_EXIT_LEVEL=1
   goto EXIT

:EXIT

rem ---------------------------------------------------------------

rem Restore user value
set COPYCMD=%HB_ORGENV_COPYCMD%

set _HB_CC_NAME=
set _HB_MAKE_PROGRAM=
set _HB_MAKEFILE=

if exist hbpostmk.bat call hbpostmk.bat
 



My error again:
Code: Select all  Expand view  RUN

MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
source\common\expropt1.c:
source\common\expropt2.c:
source\common\hbarch.c:
source\common\hbfsapi.c:
source\common\hbfopen.c:
source\common\hbgete.c:
source\common\hbwince.c:
source\common\hbhash.c:
source\common\hbdate.c:
source\common\hbstr.c:
source\common\hbtrace.c:
source\common\hbver.c:
source\common\hbverdsp.c:
source\common\reserved.c:
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
+obj\b32\expropt1.obj &
+obj\b32\expropt2.obj &
+obj\b32\hbarch.obj &
+obj\b32\hbfsapi.obj &
+obj\b32\hbfopen.obj &
+obj\b32\hbgete.obj &
+obj\b32\hbwince.obj &
+obj\b32\hbhash.obj &
+obj\b32\hbdate.obj &
+obj\b32\hbstr.obj &
+obj\b32\hbtrace.obj &
+obj\b32\hbver.obj &
+obj\b32\hbverdsp.obj &
+obj\b32\reserved.obj &
+
source\pp\hbpp.c:
Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_hb_snprintf' referenced from C:\HS2\HARBOUR\LIB\B32\HBCOMMON.LIB|hbver

** error 1 ** deleting bin\b32\hbpp.exe
 


I tried to post my .mak files. and got:

Your message contains 65894 characters. The maximum number of allowed characters is 60000 :)



Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Sat Mar 28, 2009 3:36 pm

Dave,

I think I have found where the exception is coming from. It is a Harbour bug.

Please make this change in harbour\source\vm\hvm.c function hb_vmInit():
Code: Select all  Expand view  RUN

   if( bStartMainProc )   // new !!!
      hb_cmdargUpdate();
 

Now there is no exception though the DLL function is not working yet. I keep doing tests.
regards, saludos

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

Re: Creating a LIB or DLL

Postby Antonio Linares » Sat Mar 28, 2009 3:39 pm

Dave,

Please use this makeb32.bat:
Code: Select all  Expand view  RUN

@ ECHO OFF
SET PATH=c:\bcc55\bin;c:\mingw\bin;%PATH%
SET HB_COMPILER=bcc
SET HB_USER_CFLAGS=-DHB_FM_STATISTICS_OFF
make_gnu clean install > make_gnu.log 2>&1
 

It is the one that Enrico provided to us and it works fine :-)
regards, saludos

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

Re: Creating a LIB or DLL

Postby Antonio Linares » Sat Mar 28, 2009 3:50 pm

The Harbour bug comes from here:

In harbour\source\vm\cmdarg.c function hb_cmdargUpdate() s_argv[ 0 ] is used:
s_argv[ 0 ] = s_szAppName;
but it is not initialized for a DLL.

We are going to report it to the Harbour devel mailing list.
regards, saludos

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

Re: Creating a LIB or DLL

Postby Antonio Linares » Sat Mar 28, 2009 8:03 pm

Dave,

The DLL is properly working (once the bug fix that I described is applied). I just missed to use __export in maindll.c :-)

LONG PASCAL __export HBDLLENTRY2( char * cProcName, LONG pItem1, LONG pItem2 )

Here you have the DLL to test it (using FWH\samples\babu.prg):
http://www.mediafire.com/?sharekey=d045 ... eaa7bc68bc
regards, saludos

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

Re: Creating a LIB or DLL

Postby Dave Zowasky » Mon Mar 30, 2009 1:43 pm

Antonio,

I downloaded the DLL and it works perfect.

I applied the code you described to

my \hs1\harbour\source\vm\hvm.c

Code: Select all  Expand view  RUN
  {
      HB_STACK_TLS_PRELOAD
      s_main_thread = hb_stackId();
      /* _SET_* initialization */
      hb_setInitialize( hb_stackSetStruct() );
   }
 if( bStartMainProc )
   hb_cmdargUpdate();

   hb_clsInit();              /* initialize Classy/OO system */
   hb_errInit();

   /* initialize dynamic symbol for evaluating codeblocks */
   hb_symEval.pDynSym = hb_dynsymGetCase( hb_symEval.szName );

   hb_conInit();


I am using my makegnu.bat and it looks like it compiles fine however I am still getting exception.

Any possibility of getting a copy of the harbour.exe that you used to compile the babudll? :)

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Mon Mar 30, 2009 2:47 pm

Dave,

> Any possibility of getting a copy of the harbour.exe that you used to compile the babudll?

Here you have it :-)
http://www.mediafire.com/?sharekey=414c ... 0a1ae8665a
regards, saludos

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

Re: Creating a LIB or DLL

Postby Dave Zowasky » Mon Mar 30, 2009 3:17 pm

Antonio,

I downloaded tried with new harbour.exe and same problem

here is mine from last create.

Just exe:
http://com1software.com/products/professional/harbour

This file contains:
BABU.EXE
BABU.PRG
BABUDLL.DLL
BABUDLL.PRG
BUILDHD.BAT
HARBOUR.EXE
MAINDLL.C

http://com1software.com/products/profes ... arbdll.zip

I will be running some more tests

Thanks :)
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Mon Mar 30, 2009 3:26 pm

Dave,

Please check that you are using the Harbour that I have provided you and not another one
regards, saludos

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

Re: Creating a LIB or DLL

Postby Dave Zowasky » Mon Mar 30, 2009 10:31 pm

Antonio,

Yes, I have made very sure to get the correct harbor installed.

I have been looking close at the maindll.c

Code: Select all  Expand view  RUN
/*
 * $Id: maindll.c 10658 2009-03-19 18:13:33Z vszakats $
 */


/*
 * Harbour Project source code:
 * Windows self-contained DLL entry point
 *
 * Copyright 1999 Antonio Linares <alinares@fivetech.com>
 * 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.
 *
 */


#define HB_OS_WIN_32_USED

#include "hbvm.h"
#include "hbapiitm.h"

#if defined(HB_OS_WIN_32)

BOOL WINAPI _export 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 );

   MessageBox( 0, "Inside DllEntryPoint", "1", 0 );

   switch( fdwReason )
   {
      case DLL_PROCESS_ATTACH:
           MessageBox( 0, "Inside DllEntryPoint", "2", 0 );
           hb_vmInit( FALSE );  /* Don't execute first linked symbol */
           MessageBox( 0, "Inside DllEntryPoint", "2", 0 );
           break;

      case DLL_PROCESS_DETACH:
           hb_vmQuit();
           break;
   }

   MessageBox( 0, "Inside DllEntryPoint", "3", 0 );
 
   return TRUE;
}

LONG PASCAL _export HBDLLENTRY( char * cProcName )
{
   MessageBox( 0, "Inside HBDLLENTRY", "1", 0 );

   hb_itemDoC( cProcName, 0, 0 );

   return 0;
}

LONG PASCAL _export HBDLLENTRY1( char * cProcName, LONG pItem )
{
   MessageBox( 0, "Inside HBDLLENTRY1", "1", 0 );

   hb_itemDoC( cProcName, 1, ( PHB_ITEM ) pItem, 0 );

   return 0;
}

LONG PASCAL _export HBDLLENTRY2( char * cProcName, LONG pItem1, LONG pItem2 )
{
   MessageBox( 0, "Inside HBDLLENTRY2", "1", 0 );

   hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );

   return 0;
}

#endif
 



and my buildhd.bat

Code: Select all  Expand view  RUN
@ECHO OFF
CLS

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

ECHO Compiling...

set hdir=c:\harbour
set bcdir=c:\bcc55
%bcdir%\bin\bcc32 -c -DHB_DYNLIB -I%hdir%\include;%bcdir%\include -L%bcdir%\..\lib maindll.c


%hdir%\bin\harbour %1 /n /i..\include;%hdir%\include /w /p %2 %3 > clip.log
@type clip.log
IF ERRORLEVEL 1 PAUSE
IF ERRORLEVEL 1 GOTO EXIT

echo -O2 -I%hdir%\include;%bcdir%\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 + %hdir%\obj\b32\maindll.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 %hdir%\lib\hbrtl.lib + >> b32.bc
ECHO %hdir%\lib\hbvm.lib + >> b32.bc
ECHO %hdir%\lib\gtgui.lib + >> b32.bc
ECHO %hdir%\lib\hblang.lib + >> b32.bc
ECHO %hdir%\lib\hbmacro.lib + >> b32.bc
ECHO %hdir%\lib\hbrdd.lib + >> b32.bc
ECHO %hdir%\lib\rddntx.lib + >> b32.bc
ECHO %hdir%\lib\rddcdx.lib + >> b32.bc
ECHO %hdir%\lib\hbdebug.lib + >> b32.bc
ECHO %hdir%\lib\hbcommon.lib + >> b32.bc
ECHO %hdir%\lib\hbpp.lib + >> b32.bc
ECHO %hdir%\lib\hbmzip.lib + >> b32.bc
echo %hdir%\lib\hbwin.lib + >> b32.bc
ECHO %hdir%\lib\hbsix.lib + >> b32.bc
ECHO %hdir%\lib\rddfpt.lib + >> b32.bc
ECHO %bcdir%\lib\cw32.lib + >> b32.bc
ECHO %bcdir%\lib\import32.lib + >> b32.bc
ECHO %bcdir%\lib\psdk\odbc32.lib + >> b32.bc
ECHO %bcdir%\lib\uuid.lib + >> b32.bc
echo %bcdir%\lib\psdk\msimg32.lib + >> b32.bc
echo %bcdir%\lib\psdk\rasapi32.lib, >> b32.bc
IF EXIST %1.res echo %1.res >> b32.bc
%bcdir%\bin\ilink32 -Tpd -aa -L%bcdir%\lib;%hdir%\lib @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



I was looking at the map produced from babudll.prg
Kind of small?
Code: Select all  Expand view  RUN

 Start         Length     Name                   Class
 0001:00401000 0000B9940H _TEXT                  CODE
 0002:004BB000 0000A139CH _DATA                  DATA
 0003:0055C39C 0000036D4H _BSS                   BSS
 0004:00000000 00000009CH _TLS                   TLS
 





Also this is the impdef of your good dll

Code: Select all  Expand view  RUN
LIBRARY     BABUDLL.DLL

EXPORTS
    HBDLLENTRY2                    @1   ; HBDLLENTRY2
    __DbgWndProc                   @3   ; __DbgWndProc
    __WndProc                      @2   ; __WndProc
    ___CPPdebugHook                @4   ; ___CPPdebugHook
 



Here is my bad impdef.

Code: Select all  Expand view  RUN
LIBRARY     BABUDLL.DLL

EXPORTS
    DllEntryPoint                  @1   ; DllEntryPoint
    HBDLLENTRY                     @2   ; HBDLLENTRY
    HBDLLENTRY1                    @3   ; HBDLLENTRY1
    HBDLLENTRY2                    @4   ; HBDLLENTRY2
    __DbgWndProc                   @6   ; __DbgWndProc
    __WndProc                      @5   ; __WndProc
    ___CPPdebugHook                @7   ; ___CPPdebugHook
 


Any Ideas?

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Tue Mar 31, 2009 7:22 am

Dave,

Everything seems ok. In maindll.c I just exported HBDLLENTRY2 and it was enough.

If you build babu.exe, are you able to manage my babudll.dll ?
regards, saludos

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

Re: Creating a LIB or DLL

Postby Antonio Linares » Tue Mar 31, 2009 7:28 am

Dave,

Don't use -DHB_DYNLIB here:

%bcdir%\bin\bcc32 -c -DHB_DYNLIB -I%hdir%\include;%bcdir%\include -L%bcdir%\..\lib maindll.c
regards, saludos

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

Re: Creating a LIB or DLL

Postby Dave Zowasky » Tue Mar 31, 2009 12:07 pm

Antonio,

Yes, babu.exe manages your babudll.dll very good.



Don't use -DHB_DYNLIB here:

%bcdir%\bin\bcc32 -c -DHB_DYNLIB -I%hdir%\include;%bcdir%\include -L%bcdir%\..\lib maindll.c



What should this line look like?


Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Tue Mar 31, 2009 12:15 pm

Dave,

> What should this line look like?

%bcdir%\bin\bcc32 -c -I%hdir%\include;%bcdir%\include -L%bcdir%\..\lib maindll.c
regards, saludos

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

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 100 guests