Page 1 of 3

Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 10:01 am
by gkuhnert
Hello,

for new SEPA transactions I want to embed a 3rd party .dll.
Like in this topic: http://forums.fivetechsupport.com/viewt ... LL#p103913 there are functions with a STRUCT as parameter.
Functions calls like:

Code: Select all

int SepaTools_SetOptions(XMLOptionStruct *OptionStruct)
with

Code: Select all

struct XMLInfoStruct
{
    int FullNameSpace
    char ConvertFile[255+1]
    int ConvertFlag
    int UebwSicht
    int EilUebw
    int NumsMsgID
    char Reserve[992]
} 
Also, I have to call some functions with parameter per reference as the parameter gets changed and I need the newly changed parameter.

The DLL comes from this site: http://www.sepa-tools.de/download-dll-version.html
And the documentation can be downloaded here: http://www.sepa-tools.de/files/API-Doku ... LL-Eng.pdf

As recommended in the linked topic on this forum I tried to import the dll with implib, but the outcome is, that the dll, size 2mb, gets reduced to a 7kb lib-file. When including this lib I get an 'unresolved external' message about the dll/lib-contained functions while compiling.

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 1:44 pm
by Antonio Linares
Gilbert,
I get an 'unresolved external' message about the dll/lib-contained functions while compiling
Surely you meant when linking. Please write here the exact message that you get, thanks

Have you already implemented some C code for it ? Could you post it here ? thanks

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 1:54 pm
by gkuhnert
Antonio,
Antonio Linares wrote:Surely you meant when linking. Please write here the exact message that you get, thanks
of course I meant while linking, this is the message I get:

Code: Select all

    \prog\bcc582\BIN\ilink32 -L\prog\xharbour1201\lib;\prog\fwh1202\lib;\prog\bcc582\LIB\PSDK /Gn/aa/Tpe/s @objs1202.bc,eho.exe,eho.map, FiveHx.lib  FiveHC.lib  rtl.lib  vm.lib  gtGUI.lib  lang.lib  macro.lib  rdd.lib  dbfcdx.lib  dbffpt.lib  debug.lib  common.lib  pp.lib  codepage.lib  cw32.lib  import32.lib  nddeapi.lib  iphlpapi.lib  rasapi32.lib  pcrepos.lib  hbsix.lib  dbfntx.lib  hbzip.lib  zlib.lib  ct.lib  uuid.lib  psapi.lib  SepaTools.lib  libnf.lib  ct.lib,, eho.res
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
Error: Unresolved external '_SepaTools_Init' referenced from D:\PROG\PRGS\EHO32\PRG\SEPATOOL.OBJ
Antonio Linares wrote:Have you already implemented some C code for it ? Could you post it here ? thanks
my code is (at the moment only for the function sepatools_init):

Code: Select all

#pragma BEGINDUMP
    #include <windows.h>
    #include <hbapi.h>

    HB_FUNC(SEPATOOLS_INIT)
    {
        hb_retni( SepaTools_Init( ( char * ) hb_parc( 1 ), ( char * ) hb_parc( 2 ), ( char * ) hb_parc( 3 ), ( char * ) hb_parc( 4 ), ( char * ) hb_parc( 5 ) ) );
    }

#pragma ENDDUMP
SepaTools_init is defined:

Code: Select all

int SepaTools_Init(const char *DataPath, const char *TempPath, const char *UserPath, const char *Lizenz, int Netz)

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 2:07 pm
by Antonio Linares
Gilbert,

Please try it this way:

Code: Select all

#pragma BEGINDUMP
    #include <windows.h>
    #include <hbapi.h>

   int pascal SepaTools_Init(const char *DataPath, const char *TempPath, const char *UserPath, const char *Lizenz, int Netz);

    HB_FUNC( SEPATOOLS_INIT )
    {
        hb_retni( SepaTools_Init( hb_parc( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parni( 5 ) ) );
    }

#pragma ENDDUMP

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 2:16 pm
by gkuhnert
Antonio,

great, now it works fine. I'll test with the functions needing a struct and if necessary I'll post upcoming questions in this thread.
Thanks a lot for your quick and good working response!

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 2:18 pm
by Antonio Linares
Gilbert,

You are welcome :-)

Surely other FWH users will benefit from this

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 2:56 pm
by gkuhnert
Now I try to use the following function from the dll as referred to above:

Code: Select all

int SepaTools_SetOptions(XMLOptionStruct *OptionStruct)
with

Code: Select all

struct XMLInfoStruct
{
    int FullNameSpace
    char ConvertFile[255+1]
    int ConvertFlag
    int UebwSicht
    int EilUebw
    int NumsMsgID
    char Reserve[992]
}
my code is

Code: Select all

    typedef struct
    {
        int FullNameSpace;
        char    ConvertFile[255+1];
        int ConvertFlag;
        int UebwSicht;
        int EilUebw;
        int NumMsgID;
        char    Reserve[992];
    } XMLInfoStruct;

    int pascal SepaTools_SetOptions(XMLInfoStruct *OptionStruct);

    HB_FUNC( SEPATOOLS_SETOPTIONS )
    {
        XMLInfoStruct aXMLInfoStruct;
        aXMLInfoStruct.FullNameSpace =  hb_parni( 1, 1 );
        aXMLInfoStruct.ConvertFile =        hb_parc( 1, 2 ); // Line 33, 1 Error
        aXMLInfoStruct.ConvertFlag =        hb_parni( 1, 3 );
        aXMLInfoStruct.UebwSicht =      hb_parni( 1, 4 );
        aXMLInfoStruct.EilUebw =            hb_parni( 1, 5 );
        aXMLInfoStruct.NumMsgID =           hb_parni( 1, 6 );
        aXMLInfoStruct.Reserve =            hb_parc( 1, 7 ); // Line 38, 1 Error
        hb_retni( SepaTools_SetOptions( &aXMLInfoStruct ) );
    }
 
the error I get here is:
sepatool.c:
Error E2277 sepatool.prg 33: Lvalue required in function HB_FUN_SEPATOOLS_SETOPTIONS
Error E2277 sepatool.prg 38: Lvalue required in function HB_FUN_SEPATOOLS_SETOPTIONS
*** 2 errors in Compile ***
thanks in advance for your help :)

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 3:20 pm
by Antonio Linares
Gilbert,

You could store those values in the array elements that you are supplying or as in this code, I return a new array:

Code: Select all

HB_FUNC( SEPATOOLS_SETOPTIONS )
    {
        XMLInfoStruct aXMLInfoStruct;

        aXMLInfoStruct.FullNameSpace =  hb_parni( 1, 1 );
        aXMLInfoStruct.ConvertFile =  ( char* ) hb_parc( 1, 2 ); // Line 33, 1 Error
        aXMLInfoStruct.ConvertFlag =        hb_parni( 1, 3 );
        aXMLInfoStruct.UebwSicht =      hb_parni( 1, 4 );
        aXMLInfoStruct.EilUebw =            hb_parni( 1, 5 );
        aXMLInfoStruct.NumMsgID =           hb_parni( 1, 6 );
        aXMLInfoStruct.Reserve =       ( char * ) hb_parc( 1, 7 ); // Line 38, 1 Error

        SepaTools_SetOptions( &aXMLInfoStruct );

        hb_reta( 7 );
        hb_storvni( aXMLInfoStruct.FullNameSPace, -1, 1 );
        hb_storvc( aXMLInfoStruct.ConvertFile, -1, 2 );
        ...
    }

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 3:38 pm
by gkuhnert
Antonio,

now I got some more errors:

Code: Select all

    HB_FUNC( SEPATOOLS_SETOPTIONS )
    {
        XMLInfoStruct aXMLInfoStruct;
        aXMLInfoStruct.FullNameSpace =  hb_parni( 1, 1 );
        aXMLInfoStruct.ConvertFile =        ( char* ) hb_parc( 1, 2 ); // Line 33
        aXMLInfoStruct.ConvertFlag =        hb_parni( 1, 3 );
        aXMLInfoStruct.UebwSicht =      hb_parni( 1, 4 );
        aXMLInfoStruct.EilUebw =            hb_parni( 1, 5 );
        aXMLInfoStruct.NumMsgID =           hb_parni( 1, 6 );
        aXMLInfoStruct.Reserve =            ( char * ) hb_parc( 1, 7 );
        //hb_retni( SepaTools_SetOptions( &aXMLInfoStruct ) );
        SepaTools_SetOptions( &aXMLInfoStruct ) ;

        hb_reta( 7 );
        hb_storvni( aXMLInfoStruct.FullNameSpace, -1, 1 ); // Line 43
        hb_storvc( aXMLInfoStruct.ConvertFile, -1, 2 );
        hb_storvni( aXMLInfoStruct.ConvertFlag, -1, 3 );
        hb_storvni( aXMLInfoStruct.UebwSicht, -1, 4 );
        hb_storvni( aXMLInfoStruct.EilUebw, -1, 5 );
        hb_storvni( aXMLInfoStruct.NumMsgID, -1, 6 );
        hb_storvc( aXMLInfoStruct.Reserve, -1, 7 );
    }
 
Error E2277 sepatool.prg 33: Lvalue required in function HB_FUN_SEPATOOLS_SETOPTIONS
Error E2277 sepatool.prg 38: Lvalue required in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 43: Call to function 'hb_storvni' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 44: Call to function 'hb_storvc' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 45: Call to function 'hb_storvni' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 46: Call to function 'hb_storvni' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 47: Call to function 'hb_storvni' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 48: Call to function 'hb_storvni' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS
Warning W8065 sepatool.prg 49: Call to function 'hb_storvc' with no prototype in function HB_FUN_SEPATOOLS_SETOPTIONS

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 5:51 pm
by Antonio Linares
Gilbert,

This line:

aXMLInfoStruct.ConvertFile = ( char * ) hb_parc( 1, 2 );

has to be changed this way:

strcpy( aXMLInfoStruct.ConvertFile, ( char * ) hb_parc( 1, 2 ) );

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 5:53 pm
by Antonio Linares
Gilbert,

Are you using Harbour or xHarbour ?

If you are using xHarbour please remove the "v" from the hb_stor... calls

Re: Embedding a 3rd party .dll

Posted: Tue Sep 24, 2013 6:38 pm
by gkuhnert
Antonio,
Antonio Linares wrote:Are you using Harbour or xHarbour ?
If you are using xHarbour please remove the "v" from the hb_stor... calls
I'm using xHarbour. I'll try it first thing in the morning tomorrow. Thanks a lot again :)

Re: Embedding a 3rd party .dll

Posted: Wed Sep 25, 2013 9:21 am
by gkuhnert
Antonio,

your suggestions work fine, thanks a lot :)

1) Warning
After implementing a call to a simple function without return value I get a warning. I don't know if it is my code or a problem with the lib/dll:

Definition:

Code: Select all

void SepaTools_Free()
My code:

Code: Select all

    void pascal SepaTools_Free();

    HB_FUNC( SEPATOOLS_FREE )
    {
        SepaTools_Free(); // Line 23
        //hb_ret();
    }
 
the warning I get:
Warning W8065 sepatool.prg 23: Call to function 'SepaTools_Free' with no prototype in function HB_FUN_SEPATOOLS_FREE
Maybe you've got an idea?

2) error
With the defined function

Code: Select all

int SepaTools_XMLGetData( char *Data, int *Size )
andy my code

Code: Select all

    int pascal SepaTools_XMLGetData( char *Data, int *Size );

    HB_FUNC( SEPATOOLS_XMLGETDATA )
    {
        hb_retni( SepaTools_XMLGetData( hb_parc( 1 ), hb_parni( 2 ) ) );
    }
 
I get following error:
Warning W8075 sepatool.prg 92: Suspicious pointer conversion in function HB_FUN_SEPATOOLS_XMLGETDATA
Error E2342 sepatool.prg 92: Type mismatch in parameter 'Size' (wanted 'int *', got 'int') in function HB_FUN_SEPATOOLS_XMLGETDATA
Maybe you can tell me the right solution here too?

Re: Embedding a 3rd party .dll

Posted: Wed Sep 25, 2013 7:17 pm
by Antonio Linares
Gilbert,

If there are no parameters, then void has to be used or the compiler may default to int:

Code: Select all

void pascal SepaTools_Free( void );

    HB_FUNC( SEPATOOLS_FREE )
    {
        SepaTools_Free(); // Line 23
        //hb_ret();
    }
 

Re: Embedding a 3rd party .dll

Posted: Thu Sep 26, 2013 6:55 am
by gkuhnert
Antonio,

thanks, that works too.
Do you have an idea on my 2nd error I posted in my previous post? I don't know how to handle a given parameter int *Param (yet). I guess you've got the right solution here too :)

When everything works fine, I'd like to give a résumé so others don't have to read every single post.