FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour OT: .DLL interface
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 05:09 PM

Tim,

For Microsoft and PellesC, please replace _export with __declspec(dllexport) and try to build it again, thanks :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 05:30 PM
Here is the exact code I'm using:

Code (fw): Select all Collapse
#INCLUDE "Fivewin.CH"

#pragma BEGINDUMP

// Declare Sub WCAPRegisterReceive Lib "wcap.dll" _ (ByVal lpRcvProcedure As Long)

#include <windows.h>

void __declspec(dllexport) RcvProcedure( char * szXML, LONG lSize );
{
   MessageBox( 0, "It is working", szXML, 0 );
}

HB_FUNC( REGISTER )
{
   WCAPRegisterReceive( ( LONG ) RcvProcedure );
} 

#pragma ENDDUMP
 


FUNCTION main  //  wpac

  LOCAL pFunc := HB_FuncPtr( "CalledBack" )
    //PRIVATE wcap := LoadLibrary( "wcap.dll" )
    PRIVATE cXMLDoc := ""
    
  // Register the procedure
  Register( )
    
    // Connect to the server
    WCAPConnectAs( 'localhost', 17943, 1 )
    
    WCAPConnected()
    MsgInfo( "Got Here" )
        
    WCAPDisconnect( )
    FreeLibrary( wcap ) 
    QUIT
    
RETURN NIL


FUNCTION CalledBack( PC )

cXMLDoc := PC

RETURN NIL



Here is the error response:

Code (fw): Select all Collapse
Type: C >>>xhb.exe -o"WPAC\wPac.c" -m -n -pOWPAC\ -q -gc0   -I"C:\fwh\include" -I"C:\xHB\include" -I"C:\xHB\include\w32" "C:\xHB\ASW90\wPac.prg"<<<

xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6726)
Copyright 1999-2010, http://www.xharbour.org <!-- m --><a class="postlink" href="http://www.harbour-project.org/">http://www.harbour-project.org/</a><!-- m -->
Generating object output to 'WPAC\wPac.obj'...
C:\\xHB\\ASW90\\wPac.prg(10): error: Unrecognized declaration.

C:\\xHB\\ASW90\\wPac.prg(11): warning: Missing type specifier.

C:\\xHB\\ASW90\\wPac.prg(11): error: Syntax error; found '0' expecting ')'.

C:\\xHB\\ASW90\\wPac.prg(11): error: Redeclaration of 'MessageBoxA' previously declared at C:\xHB\c_include\win\winuser.h(4283): found 'int __cdecl function' expected 'int __stdcall function(struct HWND__ *, const char *, const char *, unsigned int)'.

C:\\xHB\\ASW90\\wPac.prg(12): error: Unrecognized declaration.

C:\\xHB\\ASW90\\wPac.prg(16): warning: Missing prototype for 'WCAPRegisterReceive'.


Type: C >>>Couldn't build: wPac.obj<<<
Type: C >>>TMAKEOBJECT<<<
Type: C >>>TMAKEOBJECT:REFRESH<<<
Type: N >>>      1423<<<
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 07:38 PM
Tim,

You have an extra ";" here, that has to be removed:
void __declspec(dllexport) RcvProcedure( char * szXML, LONG lSize );

Also you have to add:
void WCAPRegisterReceive( LONG );
after #include <windows.h>
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 09:44 PM

I assumed the other functions would work since they are in the lib, but they are not seen. Without using them I do get an .exe. However, I do not get the message box you included which says it is working.

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 11:45 PM
Tim,

You have to implement the other missing functions:
Code (fw): Select all Collapse
void WCAPConnectAs( char *, LONG, LONG ); // I have assumed this prototype, please check that it is correct

HB_FUNC( WCAPCONNECTAS )
{
   WCAPConnectAs( hb_parc( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 04:59 PM
Here is the current code using your model:

Code (fw): Select all Collapse
#INCLUDE "Fivewin.CH"


#pragma BEGINDUMP

#include <windows.h>

void __declspec(dllexport) RcvProcedure( char * szXML, LONG lSize )
{
   MessageBox( 0, "It is working", szXML, 0 );
}

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

 
// Function: WCAPConnectAs( Host:LPSTR, Port :UINT, Autostart :UINT ) :Bool
void WCAPConnectAs( LPSTR, LONG, LONG ); 
HB_FUNC( WPCONNECTAS )
{
   WCAPConnectAs(  hb_parc(1),  hb_parl(2), hb_parl(3) );
}
 

// Function: WCAPConnected :BOOl
void WCAPConnected( ); 
HB_FUNC( WPCONNECTED )
{
   WCAPConnected( );
}


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

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


#pragma ENDDUMP



FUNCTION main  //  wpac

  LOCAL pFunc := HB_FuncPtr( "CalledBack" )
    PRIVATE cXMLDoc := ""
    
  // Register the procedure
  Register( )
    
    // Connect to the server
    WConnectAs( 'localhost', 17943, 1 )
    
    // WCAPConnected()
    MsgInfo( "Got Here" )
        
    // WCAPDisconnect( )
    QUIT
    
RETURN NIL


FUNCTION CalledBack( PC )

cXMLDoc := PC

RETURN NIL



And I'm getting the following errors:

C:\\xHB\\ASW90\\wPac.prg(25): error: Type error in argument 1 to 'WCAPConnectAs'; found 'const char *' expected 'char *'.

C:\\xHB\\ASW90\\wPac.prg(48): error: Type error in argument 1 to 'WCAPSend'; found 'const char *' expected 'char *'.

I apparently am having a problem with the character type
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 05:06 PM
Tim,

Some changes are required. Please try it this way:
Code (fw): Select all Collapse
#INCLUDE "Fivewin.CH"

#pragma BEGINDUMP

#include <windows.h>

void __declspec(dllexport) RcvProcedure( char * szXML, LONG lSize )
{
   MessageBox( 0, "It is working", szXML, 0 );
}

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

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

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


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

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

#pragma ENDDUMP

FUNCTION main  //  wpac

  LOCAL pFunc := HB_FuncPtr( "CalledBack" )
    PRIVATE cXMLDoc := ""
    
  // Register the procedure
  Register( )
    
    // Connect to the server
    WConnectAs( 'localhost', 17943, 1 )
    
    // WCAPConnected()
    MsgInfo( "Got Here" )
        
    // WCAPDisconnect( )
    QUIT
    
RETURN NIL


FUNCTION CalledBack( PC )

cXMLDoc := PC

RETURN NIL
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 05:50 PM

Still getting a fight from ConnectAs: The link returns an error Undefined __WCAPConnectAs

Also, did you mean to put BOOL WCAPConnectAS( LPSTR,LONG,LONG) instead of void ?

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 07:58 PM

Tim,

This line has to be modified this way: (please notice uppercase ...AS)

hb_retl( WCAPConnectAS( ( char * ) hb_parc( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) );

Yes, based on the pascal prototype that you wrote, the function returns a logical value (BOOL).

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 11:27 PM

It now compiles ! This is good progress. However, the program dies without any message at REGISTER( ).

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 11:41 PM
Tim,

Please set these traces and lets see how far it goes:
Code (fw): Select all Collapse
HB_FUNC( REGISTER )
{
   MessageBox( 0, "before", "register", 0 );
   WCAPRegisterReceive( ( LONG ) RcvProcedure );
   MessageBox( 0, "after", "register", 0 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 11:43 PM

Tim,

Also, please create a DEF file from the EXE:

impdef.exe test.def test.exe

and copy the DEF file here, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Wed Oct 06, 2010 12:05 AM

Interesting,

Here is the Main():

FUNCTION main // wpac

MsgInfo("1")
// Register the procedure
Register( )
MsgInfo("2")
// Connect to the server
WPConnectAs( 'localhost', 17943, 1 )
MsgInfo("3")
WPConnected()
MsgInfo( "4" )

WPDisconnect( )
MsgInfo( &quot;5&quot; )

RETURN NIL

I get Msg 1, before, after, but no message 2 which comes right after the call to Register()

impdef is getting me a 0 byte file. Of course it is created with xBuilder / Pelles C ....

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Wed Oct 06, 2010 06:16 AM

Tim,

Please send me a ZIP file (renamed as *.ZOP) with your EXE, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Wed Oct 06, 2010 11:55 PM

Following all of the suggestions, and your very much appreciated guidance, Run of this application locks up the computer. Here are some observations:

1) The build with xBuilder used FWH 10.9 and xCC compiler.
2) The .dll I provided was 406KB. The lib you created was 4KB. Is that possible and still accurate
3) I did try a build with BCC in a UE project, but my lib was Microsoft C ... and I also got an error with a Borland .h file.
" Error E2187 c:\bcc582\include\prsht.h 1084: Unexpected end of file in conditional started on line 12 "
I suspect something else because I would expect that to be clean.
4) I tried to IMPLIB the .dll and it only yields a 2KB file. I like compression but that seems unlikely also.

Perhaps I just need to go back to using the .dll. I can do that easily in VB so maybe I need to call an intermediary vb routine that does this all for me ...

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