Page 1 of 1

PCode DLL

Posted: Fri Feb 06, 2009 6:58 pm
by Roberto Parisi
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

Re: PCode DLL

Posted: Sat Feb 07, 2009 8:20 am
by Antonio Linares
Roberto,

This is the source code of function hb_LibDo(), as you see it uses the "extend system" not the standard C params:

Code: Select all

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

Code: Select all

void __export__ LIBDO( char * cFuncName )
{
   PHB_DYNS pDynSym = hb_dynsymFindName( cFuncName );

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

Re: PCode DLL

Posted: Sat Feb 07, 2009 10:51 am
by Roberto Parisi
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

Re: PCode DLL

Posted: Sat Feb 07, 2009 10:59 am
by Antonio Linares
Roberto,

Please try this:

impdef.exe mylib.def mylib.dll

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

Re: PCode DLL

Posted: Sat Feb 07, 2009 11:19 am
by Roberto Parisi
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

Re: PCode DLL

Posted: Sat Feb 07, 2009 11:28 am
by Antonio Linares
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.

Re: PCode DLL

Posted: Sat Feb 07, 2009 12:18 pm
by Roberto Parisi
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

Re: PCode DLL

Posted: Sat Feb 07, 2009 2:37 pm
by Antonio Linares
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

Re: PCode DLL

Posted: Sun Feb 08, 2009 12:56 pm
by Roberto Parisi
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

Re: PCode DLL

Posted: Mon Feb 09, 2009 8:10 am
by Antonio Linares
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.

Re: PCode DLL

Posted: Mon Feb 09, 2009 8:56 am
by Roberto Parisi
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

Re: PCode DLL

Posted: Mon Feb 09, 2009 9:06 am
by Antonio Linares
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.