Creating a LIB or DLL

Post Reply
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

To make sure I am not picking up something unexpected I copied my code over to a test folder

Code: Select all

 Directory of C:\test1

03/31/2009  08:28 AM    <DIR>          .
03/31/2009  08:28 AM    <DIR>          ..
03/31/2009  08:23 AM               769 b32.bc
03/31/2009  08:11 AM             4,043 babu.c
03/31/2009  08:11 AM         1,492,992 babu.exe
03/31/2009  08:11 AM           403,310 babu.map
03/31/2009  08:11 AM             1,886 babu.ppo
09/23/2008  11:14 AM               750 babu.prg
03/31/2009  08:11 AM           524,288 babu.tds
03/31/2009  08:23 AM             1,295 babudll.c
03/31/2009  08:23 AM         1,490,944 babudll.dll
03/31/2009  08:23 AM         1,376,256 babudll.ilc
03/31/2009  08:23 AM           917,504 babudll.ild
03/31/2009  08:23 AM         2,228,224 babudll.ilf
03/31/2009  08:23 AM         1,900,544 babudll.ils
03/31/2009  08:23 AM               276 babudll.map
03/31/2009  08:23 AM             1,513 babudll.obj
03/31/2009  08:23 AM               132 babudll.ppo
03/28/2009  05:29 PM               219 babudll.prg
03/31/2009  08:23 AM           524,288 babudll.tds
03/29/2009  05:45 PM             2,943 Buildh.bat
03/31/2009  08:18 AM             2,110 BUILDHD.BAT
03/31/2009  08:23 AM                 0 clip.log
03/31/2009  08:11 AM                 0 comp.log
03/30/2009  06:05 PM             4,135 maindll.c
03/31/2009  08:23 AM             4,273 maindll.obj
03/31/2009  08:22 AM         3,755,480 MYTEST1.ZIP
03/31/2009  08:28 AM                 0 test.txt
              26 File(s)     14,638,174 bytes

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


Also to be sure I am using the correct harbour.exe that you gave me,

I posted it here:

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

I mentioned before the map of the babudll being so small, is it ok?

I will go over my bcc folders to make sure there is nothing wrong being picked up there.

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
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

Given some of the changes in harbour . Is it possible that my FWH lib's need to be updated? :)

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Are you using the modified hbvm.lib that I provided you ?

I have tested your files here, rebuilt the DLL, and works fine.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

I used this as my c:\harbour folder.

http://www.mediafire.com/?sharekey=414c ... 0a1ae8665a

I also tried fresh install on new PC, also tried new BCC55.

It is good to hear my code runs there.

I will continue to test :)

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

if you want we can have a "TeamViewer" session, so I build the DLL in your own computer and we test it together :-)

www.teamviewer.com
regards, saludos

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

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Just to double check it, please overwrite your hbvm.lib with this one:

http://www.mediafire.com/?sharekey=414c ... 0a1ae8665a
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

The new hbvm.lib did the trick!

It works Great :D

Thanks a lot for all the help.
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

So glad to hear this!!! :D
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

I appreciate all your help as well as the help from everyone else.

I have built a test panel to help me test some code with the dll.

I was wondering if i can return a string value from my dll to my calling EXE
If so what is the best way to do it? Any advice. :)

Here is the main calling program testdll.prg

Code: Select all

// Using Harbour DLLs

#include "FiveWin.ch"

function Main()
local odlg
local obtn
local xcmd:=""

**********************************
define dialog odlg;
 from 1, 1 to 400,600;
 pixel;
 title "DLL Test Panel"
*********************************
@ 1, 42 BUTTON "Exit";
        size 30,12;
        ACTION oDlg:End()
*******
@ 1, 1 BUTTON "Edit TESTDLL.PRG";
       size 70,12;
       ACTION (xcmd:=getwindir()+"\notepad.exe testdll.prg",;
       winexec(xcmd))
*******
@ 1, 15 BUTTON "Build TESTDLL";
       size 50,12
*******
@ 3, 1 BUTTON "Edit DLL2TEST.PRG";
       size 70,12;
       ACTION (xcmd:=getwindir()+"\notepad.exe dll2test.prg",;
        winexec(xcmd))
*******
@ 3, 15 BUTTON "Build DLL2TEST";
       size 50,12;
       ACTION (xcmd:="buildhd.bat dll2test > dllcomp.log",;
       waitrun(xcmd,1))
*******
@ 3, 26 BUTTON "DLL Compile Log";
       size 50,12;
       ACTION (xcmd:=getwindir()+"\notepad.exe dllcomp.log",;
        winexec(xcmd))
*******
@ 4, 1 BUTTON "Edit MAINDLL.C";
       size 70,12;
       ACTION (xcmd:=getwindir()+"\notepad.exe maindll.c",;
        winexec(xcmd))




*******
@ 6, 1 BUTTON "Hello World";
       size 70,12;
       ACTION test1()
*******
@ 7, 1 BUTTON "Hello World Back";
       size 70,12;
       ACTION test2()
*******
@ 8, 1 BUTTON "DoSum";
       size 70,12;
       ACTION MsgInfo( DoSum( 2, 3 ) )
********************************************
activate dialog odlg;
centered

return(nil)

************************** Test 1 Hello World
function test1()
   local cr:=chr(13)
   local hItem1 := ItemNew( "The Message is : Hello world!"+cr+"       Test 1" )
   local hItem2 := ItemNew( "This is the Title for the Harbour DLL" )

   HbDLLEntry2( "TEST1", hItem1, hItem2 )
   
   ItemRelease( hItem1 )
   ItemRelease( hItem2 )
   
   MsgInfo( "OK! We are back to the EXE." )

return nil

************************** Test 2 Hello World
function test2()
   local cr:=chr(13)
   local hItem1 := ItemNew( "The Message is : Hello world!"+cr+"       Test 2" )
   local hItem2 := ItemNew( "This is the Title for the Harbour DLL" )

************************** for return string from dll
   local rtnitem:="Return Value not set yet." 
   
   ?HbDLLEntry2( "TEST2", hItem1, hItem2 )

   ItemRelease( hItem1 )
   ItemRelease( hItem2 )

   

   MsgInfo( rtnitem+cr+"OK! We are back to the EXE." )

return nil


************************ DLL Call to DLL2TEST
DLL FUNCTION HBDLLENTRY2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB "dll2test.dll"



*********************************************


#pragma BEGINDUMP

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

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

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

HB_FUNC( DOSUM )
{
   hb_retnl( hb_parnl( 1 ) + hb_parnl( 2 ) );
}

#pragma ENDDUMP    

Here is my DLL2TEST.prg

Code: Select all

*********************** Dll2test
***********************

extern LoadLibrary, FreeLibrary, AnsiToWide

********************************** Test 1 Hello World
function Test1( cMsg1, cMsg2 )

   MsgInfo( cMsg1, cMsg2 )

return nil

********************************** Test 2 Hello World Back
function Test2( cMsg1, cMsg2 )
local cr:=chr(13)

   cMsg1:=cMsg1+cr+"This is being added on in the DLL."
   cMsg1:=cMsg1+cr+"     So Far so good."
   cMsg1:=cMsg1+cr+"Time to send this message"
   cMsg1:=cMsg1+cr+"back the TESTDLL.EXE."

   MsgInfo( cMsg1, cMsg2 )

return (cMsg1)

 
Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Please include this function in maindll.c:

Code: Select all

LPSTR PASCAL __extern HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
{
   hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );

   return hb_parc( -1 );
}
 
And then declare it this way from your PRG:

Code: Select all

DLL FUNCTION HBDLLSTRING2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LPSTR PASCAL LIB "dll2test.dll"
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

I am getting this from my dll compile

Compiling...
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
maindll.c:
Error E2141 maindll.c 114: Declaration syntax error
*** 1 errors in Compile ***
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
dll2test.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_HB_FUN_HBDLLSTRING2' referenced from H:\TESTDLL\DLL2TEST.OBJ
* There are errors


my maindll.c

Code: Select all


#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 );


   switch( fdwReason )
   {
      case DLL_PROCESS_ATTACH:
           hb_vmInit( FALSE );  /* Don't execute first linked symbol */
           break;
      case DLL_PROCESS_DETACH:
           hb_vmQuit();
           break;
   }

 
   return TRUE;
}

LONG PASCAL _export HBDLLENTRY( char * cProcName )
{

   hb_itemDoC( cProcName, 0, 0 );

   return 0;
}

LONG PASCAL _export HBDLLENTRY1( char * cProcName, LONG pItem )
{

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

   return 0;
}

LONG PASCAL _export HBDLLENTRY2( char * cProcName, LONG pItem1, LONG pItem2 )
{

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

   return 0;
  
}

LPSTR PASCAL __extern HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
{
   hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );

   return hb_parc( -1 );
}
#endif
Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

> Error E2141 maindll.c 114: Declaration syntax error

What source code do you have in maindll.c 114 ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

I copied back my original, added code and recompile same result

Code: Select all

/*
 * $Id: maindll.c 6764 2006-07-18 01:30:23Z druzus $
 */

/*
 * 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)

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

   switch( fdwReason )
   {
      case DLL_PROCESS_ATTACH:
           hb_vmInit( FALSE );  /* Don't execute first linked symbol */
           break;

      case DLL_PROCESS_DETACH:
           hb_vmQuit();
           break;
   }

   return TRUE;
}

LPSTR PASCAL __extern HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
{
   hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );

   return hb_parc( -1 );
}
    
HB_EXPORT LONG PASCAL HBDLLENTRY( char * cProcName )
{
   hb_itemDoC( cProcName, 0, 0 );

   return 0;
}

HB_EXPORT LONG PASCAL HBDLLENTRY1( char * cProcName, LONG pItem )
{
   hb_itemDoC( cProcName, 1, ( PHB_ITEM ) pItem, 0 );

   return 0;
}

HB_EXPORT LONG PASCAL HBDLLENTRY2( char * cProcName, LONG pItem1, LONG pItem2 )
{
   hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );

   return 0;
}

#endif
 
Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Change this line this way:

HB_EXPORT char * PASCAL HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

I compile ok now, however my test2 no longer displays in dll and returns nil

Here is how I call test2 dll from my code

Code: Select all

************************** Test 2 Hello World
function test2()
   local cr:=chr(13)
   local hItem1 := ItemNew( "The Message is : Hello world!"+cr+"       Test 2" )
   local hItem2 := ItemNew( "This is the Title for the Harbour DLL" )

************************** for return string from dll
   local rtnitem:="Return Value not set yet." 
   
   ?HbDLLstring2( "TEST2", hItem1, hItem2 )

   ItemRelease( hItem1 )
   ItemRelease( hItem2 )

   MsgInfo( rtnitem+cr+"OK! We are back to the EXE." )

return nil
 




Here is my new maindll.c

Code: Select all

/*
 * $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 );


   switch( fdwReason )
   {
      case DLL_PROCESS_ATTACH:
           hb_vmInit( FALSE );  /* Don't execute first linked symbol */
           break;
      case DLL_PROCESS_DETACH:
           hb_vmQuit();
           break;
   }

 
   return TRUE;
}

LONG PASCAL _export HBDLLENTRY( char * cProcName )
{

   hb_itemDoC( cProcName, 0, 0 );

   return 0;
}

LONG PASCAL _export HBDLLENTRY1( char * cProcName, LONG pItem )
{

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

   return 0;
}

LONG PASCAL _export HBDLLENTRY2( char * cProcName, LONG pItem1, LONG pItem2 )
{

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

   return 0;
}
HB_EXPORT char * PASCAL HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
{
   hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );

   return hb_parc( -1 );
}

#endif
 

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Post Reply