FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour PCode DLL
Posts: 116
Joined: Thu Oct 13, 2005 05:14 PM
PCode DLL
Posted: Fri Feb 06, 2009 06:58 PM

I use xharbour pcode dll and call dll function with HB_LibDo("MyFunc"). This
is ok.. but I would like to call MyFunc directly without HB_LibDo... can I
do it linking importing lib to my exe?
I tried creating mylib.lib from mylib.dll with no success.

Any hint?

Another question.. can I put fwh.lib and others libs in a standard.dll like harbour.dll. This can make my exe small so I can download it more quickly.

Thx,
Roberto Parisi

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 08:20 AM
Roberto,

This is the source code of function hb_LibDo(), as you see it uses the "extend system" not the standard C params:
/* Executes a Harbour pcode dynamically loaded DLL function or procedure
 * Syntax: HB_libDo( <cFuncName> [,<params...>] ) --> [<uResult>]
 */

HB_FUNC( HB_LIBDO )
{
   if( hb_parclen( 1 ) > 0 )
   {
      PHB_DYNS pDynSym = hb_dynsymFindName( hb_parc( 1 ) );

      if( pDynSym )
      {
         USHORT uiPCount = hb_pcount();
         USHORT uiParam;

         hb_vmPushSymbol( pDynSym->pSymbol );
         hb_vmPushNil();

         /* same logic here as from HB_FUNC( EVAL ) */
         for( uiParam = 2; uiParam <= uiPCount; uiParam++ )
         {
            hb_vmPush( hb_stackItemFromBase( uiParam ) );
         }

         hb_vmDo( ( USHORT ) ( uiPCount - 1 ) );
      }
   }
}

So if you want to call it directly from C, then you have to modify it. This is an example (for no parameters):
void __export__ LIBDO( char * cFuncName )
{
   PHB_DYNS pDynSym = hb_dynsymFindName( cFuncName );

   if( pDynSym )
   {
      hb_vmPushSymbol( pDynSym->pSymbol );
      hb_vmPushNil();
      hb_vmDo( 0 );
   }
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 116
Joined: Thu Oct 13, 2005 05:14 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 10:51 AM

Hi antonio, thx for your reply.

What I want to do is not call dll code from C.

I want to use dynamic DLL as static lib to call functions directly.

ex:

// TestEXE.prg
procedure main()
Test1()
return

// TestDLL.prg
procedure Test1()
Alert("Test1")
return

Regards,
Roberto Parisi

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 10:59 AM

Roberto,

Please try this:

impdef.exe mylib.def mylib.dll

mylib.def will be created (ascii file). Please post its contents here, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 116
Joined: Thu Oct 13, 2005 05:14 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 11:19 AM

Thx Antonio,
with impdef I found my mistake... I compile prg code without EXPORT so I got no exported functions.

Many thx for your fast and accurate help.

Is there a way to put fivehx.lib, fivehc.lib and other libraries inside a single dll fiveh.dll to link into my application with an import library fiveh.lib?

Regards,
Roberto Parisi

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 11:28 AM

Roberto,

> I compile prg code without EXPORT so I got no exported functions.

Thats why I wanted you to use impdef.exe, to check it :-)

>
Is there a way to put fivehx.lib, fivehc.lib and other libraries inside a single dll fiveh.dll to link into my application with an import library fiveh.lib?
>

You could try to build a pcode DLL using the libs.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 116
Joined: Thu Oct 13, 2005 05:14 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 12:18 PM

Antonio,
i tried with this:

ilink32.exe -C -Gn -Gi -Tpd -x -Lc:\apps\fwh901\lib;c:\apps\xharbour\lib;c:\apps\bcc55\lib -aa c0d32 maindllp cw32.lib import32.lib fivehx.lib fivehc.lib, fiveh.dll

my res dll is only 58Kb

Regards,
Roberto Parisi

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: PCode DLL
Posted: Sat Feb 07, 2009 02:37 PM

Roberto,

Please create the def file again from the DLL, and also the map file using ilink32

You need to link a module that forces the link of all other modules

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 116
Joined: Thu Oct 13, 2005 05:14 PM
Re: PCode DLL
Posted: Sun Feb 08, 2009 12:56 PM

Ok Antonio,
I don't know what functions will be used from the main app so I want to force linking of all functions inside lib files.
is there a way to go?

Regards,
Roberto Parisi

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: PCode DLL
Posted: Mon Feb 09, 2009 08:10 AM

Roberto,

Try to link TWindow, as it will links lots of classes and functions.

You may need to link others that may not be included.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 116
Joined: Thu Oct 13, 2005 05:14 PM
Re: PCode DLL
Posted: Mon Feb 09, 2009 08:56 AM

This is the def file linking TWindow. The file is only 100Kb

LIBRARY TESTDLL.DLL

EXPORTS
_HB_FUN_AREAD @8 ; _HB_FUN_AREAD
_HB_FUN_ASAVE @7 ; _HB_FUN_ASAVE
_HB_FUN_ATOTEXT @6 ; _HB_FUN_ATOTEXT
_HB_FUN_GETALLWIN @2 ; _HB_FUN_GETALLWIN
_HB_FUN_GETDROPINFO @14 ; _HB_FUN_GETDROPINFO
_HB_FUN_GETWNDDEFAULT @12 ; _HB_FUN_GETWNDDEFAULT
_HB_FUN_NWINDOWS @1 ; _HB_FUN_NWINDOWS
_HB_FUN_OREAD @9 ; _HB_FUN_OREAD
_HB_FUN_OWNDFROMHWND @18 ; _HB_FUN_OWNDFROMHWND
_HB_FUN_SETBALLOON @3 ; _HB_FUN_SETBALLOON
_HB_FUN_SETDROPINFO @13 ; _HB_FUN_SETDROPINFO
_HB_FUN_SETWNDDEFAULT @10 ; _HB_FUN_SETWNDDEFAULT
_HB_FUN_TWINDOW @4 ; _HB_FUN_TWINDOW
_HB_FUN_WNDCREATEERROR @5 ; _HB_FUN_WNDCREATEERROR
_HB_FUN_WNDMAIN @15 ; _HB_FUN_WNDMAIN
_HB_FUN_WNDPARENTS @17 ; _HB_FUN_WNDPARENTS
_HB_FUN__FWH @16 ; _HB_FUN__FWH
_HB_FUN__SETWNDDEFAUL @11 ; _HB_FUN__SETWNDDEFAUL
CPPdebugHook @19 ; CPPdebugHook

What about extract all obj from fivehx, fivehc and link into the dll?

Regards,
Roberto Parisi

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: PCode DLL
Posted: Mon Feb 09, 2009 09:06 AM

Roberto,

The problem is that you need to export all the functions and classes that you want to use from your EXE.

The def file is going to be huge, unless we find another solution.

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion