DLLs with Harbour vs xHarbour

DLLs with Harbour vs xHarbour

Postby TimStone » Fri Sep 13, 2013 9:44 pm

I am working with an online catalog system. They have an application running on the desktop, and procedures by which we can obtain the information and import it into my program. The company provides a .dll file with the commands necessary to access their data.

The tricky requirement is that we had to identify a memory location to register with their program to receive the data. The following functions perform all of the interface we need.

This code works fine with xHarbour builds. However, I'm now working with MSVC / Harbour. I created a .lib file from the .dll and linked it in ( just like the one we created for the xHarbour version ). It is built with Lib.exe from Visual Studio.

Here is the code used in xHarbour.


Code: Select all  Expand view


// Primary functions to use

void __declspec(dllexport) RcvProcedure( char * szXML, LONG lSize )
{
   hb_vmPushSymbol( hb_dynsymGetSymbol( "CALLEDBACK" ) ); // we push the symbol of the function to call
   hb_vmPushNil(); // we push nil for a function, a codeblock for Eval, an object for a method
   hb_vmPushString( szXML, strlen( szXML ) );
   hb_vmPushLong( lSize );
   hb_vmFunction( 2 ); // two parameters supplied to CallBack()
}

// Declare Sub WCAPRegisterReceive Lib "wcap.dll" _ (ByVal lpRcvProcedure As Long)
void pascal WCAPRegisterReceive( LONG );
HB_FUNC( REGISTER )
{
   WCAPRegisterReceive( ( LONG ) RcvProcedure );

}

// Function: WCAPConnectAs( Host:LPSTR, Port :UINT, Autostart :UINT ) :Bool
BOOL pascal WCAPConnectAS( LPSTR, LONG, LONG );
HB_FUNC( WPCONNECTAS )
{
    hb_retl( WCAPConnectAS( ( char * ) hb_parc( 1 ),  hb_parnl( 2 ),  hb_parnl( 3 ) ));
}


// Function: WCAPConnected :BOOl
BOOL pascal WCAPConnected( );
HB_FUNC( WPCONNECTED )
{
    hb_retl( WCAPConnected() );
}


// Function: WCAPDisconnect
void pascal WCAPDisconnect();
HB_FUNC( WPDISCONNECT )
{
      WCAPDisconnect() ;
}

// Function: WCAPSend(XMLDoc :LPSTR)
void pascal WCAPSend( LPSTR );
HB_FUNC( WPSEND )
{
    WCAPSend( ( char * ) hb_parc( 1 ) );
}

 


When trying to build with Harbour / MSVC, I get the following errors:

Code: Select all  Expand view



--------------------Configuration: ASW2013 - Release--------------------
FiveHC32.lib(MEM.obj) : warning LNK4006: _HB_FUN_NEXTMEM already defined in errsysw_.obj; second definition ignored
hbvm.lib(hvmall.obj) : warning LNK4006: _HB_FUN_HB_GCALL already defined in tCodeJock.obj; second definition ignored
   Creating library asw2012.lib and object asw2012.exp
wPac.obj : error LNK2019: unresolved external symbol "void __stdcall WCAPRegisterReceive(long)" (?WCAPRegisterReceive@@YGXJ@Z) referenced in function _HB_FUN_REGISTER
wPac.obj : error LNK2019: unresolved external symbol "int __stdcall WCAPConnectAS(char *,long,long)" (?WCAPConnectAS@@YGHPADJJ@Z) referenced in function _HB_FUN_WPCONNECTAS
wPac.obj : error LNK2019: unresolved external symbol "int __stdcall WCAPConnected(void)" (?WCAPConnected@@YGHXZ) referenced in function _HB_FUN_WPCONNECTED
wPac.obj : error LNK2019: unresolved external symbol "void __stdcall WCAPDisconnect(void)" (?WCAPDisconnect@@YGXXZ) referenced in function _HB_FUN_WPDISCONNECT
wPac.obj : error LNK2019: unresolved external symbol "void __stdcall WCAPSend(char *)" (?WCAPSend@@YGXPAD@Z) referenced in function _HB_FUN_WPSEND
asw2012.exe : fatal error LNK1120: 5 unresolved externals
MLS2013.EXE - 6 error(s), 2 warning(s)
 


Any ideas on how to get this to work would be greatly appreciated.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: DLLs with Harbour vs xHarbour

Postby Antonio Linares » Sat Sep 14, 2013 8:32 am

Tim,

Please create the DEF file from your DLL and post it here, thanks

impdef.exe yourdll.def yourdll.dll

The DEF file is an ascii file
regards, saludos

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

Re: DLLs with Harbour vs xHarbour

Postby Antonio Linares » Sat Sep 14, 2013 8:37 am

Tim,

I already know whats going on. For each sentence like this one that you have in your code:

BOOL pascal WCAPConnectAS( LPSTR, LONG, LONG );

change it this way:

extern "C"
{
BOOL pascal WCAPConnectAS( LPSTR, LONG, LONG );
}

please do it for each one of them.
regards, saludos

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

Re: DLLs with Harbour vs xHarbour

Postby TimStone » Mon Sep 16, 2013 6:14 pm

That didn't work.

Here are the contents of the .def file:

LIBRARY WCAP.DLL

EXPORTS
WCAPConnect @10 ; WCAPConnect
WCAPConnectAS @9 ; WCAPConnectAS
WCAPConnected @8 ; WCAPConnected
WCAPDebugEnable @3 ; WCAPDebugEnable
WCAPDebugEnabled @2 ; WCAPDebugEnabled
WCAPDebugWrite @1 ; WCAPDebugWrite
WCAPDisconnect @7 ; WCAPDisconnect
WCAPRegisterReceive @6 ; WCAPRegisterReceive
WCAPSend @5 ; WCAPSend
WCAPStartServer @4 ; WCAPStartServer
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: DLLs with Harbour vs xHarbour

Postby Antonio Linares » Mon Sep 16, 2013 9:20 pm

Tim,

That didn't work.


Why do you think so ? Please copy here the linker output that you get now, thanks :-)
regards, saludos

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

Re: DLLs with Harbour vs xHarbour

Postby TimStone » Mon Sep 16, 2013 10:35 pm

Here is the output:

Code: Select all  Expand view

--------------------Configuration: ASW2013 - Release--------------------
   Creating library asw2012.lib and object asw2012.exp
wPac2.obj : error LNK2019: unresolved external symbol _WCAPRegisterReceive@4 referenced in function _HB_FUN_REGISTER
wPac2.obj : error LNK2019: unresolved external symbol _WCAPConnectAS@12 referenced in function _HB_FUN_WPCONNECTAS
wPac2.obj : error LNK2019: unresolved external symbol _WCAPConnected@0 referenced in function _HB_FUN_WPCONNECTED
wPac2.obj : error LNK2019: unresolved external symbol _WCAPDisconnect@0 referenced in function _HB_FUN_WPDISCONNECT
wPac2.obj : error LNK2019: unresolved external symbol _WCAPSend@4 referenced in function _HB_FUN_WPSEND
asw2012.exe : fatal error LNK1120: 5 unresolved externals
MLS2013.EXE - 6 error(s), 0 warning(s)

 


Here is the modified code that generates this error set:
Code: Select all  Expand view


// Declare Sub WCAPRegisterReceive Lib "wcap.dll" _ (ByVal lpRcvProcedure As Long)
extern "C"
{
void pascal WCAPRegisterReceive( LONG );
}
HB_FUNC( REGISTER )
{
   WCAPRegisterReceive( ( LONG ) RcvProcedure );

}

// Function: WCAPConnectAs( Host:LPSTR, Port :UINT, Autostart :UINT ) :Bool
extern"C"
{
BOOL pascal WCAPConnectAS( LPSTR, LONG, LONG );
}
HB_FUNC( WPCONNECTAS )
{
    hb_retl( WCAPConnectAS( ( char * ) hb_parc( 1 ),  hb_parnl( 2 ),  hb_parnl( 3 ) ));
}


// Function: WCAPConnected :BOOl
extern "C"
{
BOOL pascal WCAPConnected( );
}
HB_FUNC( WPCONNECTED )
{
    hb_retl( WCAPConnected() );
}


// Function: WCAPDisconnect
extern "C"
{
void pascal WCAPDisconnect();
}
HB_FUNC( WPDISCONNECT )
{
      WCAPDisconnect() ;
}

// Function: WCAPSend(XMLDoc :LPSTR)
extern "C"
{
void pascal WCAPSend( LPSTR );
}
HB_FUNC( WPSEND )
{
    WCAPSend( ( char * ) hb_parc( 1 ) );
}

 
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: DLLs with Harbour vs xHarbour

Postby Antonio Linares » Tue Sep 17, 2013 9:23 am

Tim,

Please remove all "pascal" keyword from your C code and try it again, thanks
regards, saludos

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

Re: DLLs with Harbour vs xHarbour

Postby TimStone » Tue Sep 17, 2013 3:56 pm

That allowed it to build. Thank you. Now to do some testing ....
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 88 guests