OT: .DLL interface

Re: OT: .DLL interface

Postby Antonio Linares » Mon Oct 04, 2010 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: OT: .DLL interface

Postby TimStone » Mon Oct 04, 2010 5:30 pm

Here is the exact code I'm using:

Code: Select all  Expand view


#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: Select all  Expand view



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 http://www.harbour-project.org/
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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: OT: .DLL interface

Postby Antonio Linares » Mon Oct 04, 2010 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: OT: .DLL interface

Postby TimStone » Mon Oct 04, 2010 9: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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: OT: .DLL interface

Postby Antonio Linares » Mon Oct 04, 2010 11:45 pm

Tim,

You have to implement the other missing functions:
Code: Select all  Expand view

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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: OT: .DLL interface

Postby TimStone » Tue Oct 05, 2010 4:59 pm

Here is the current code using your model:

Code: Select all  Expand view


#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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: OT: .DLL interface

Postby Antonio Linares » Tue Oct 05, 2010 5:06 pm

Tim,

Some changes are required. Please try it this way:
Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: OT: .DLL interface

Postby TimStone » Tue Oct 05, 2010 5: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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: OT: .DLL interface

Postby Antonio Linares » Tue Oct 05, 2010 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: OT: .DLL interface

Postby TimStone » 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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: OT: .DLL interface

Postby Antonio Linares » Tue Oct 05, 2010 11:41 pm

Tim,

Please set these traces and lets see how far it goes:
Code: Select all  Expand view

HB_FUNC( REGISTER )
{
   MessageBox( 0, "before", "register", 0 );
   WCAPRegisterReceive( ( LONG ) RcvProcedure );
   MessageBox( 0, "after", "register", 0 );
}
 
regards, saludos

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

Re: OT: .DLL interface

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41462
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: OT: .DLL interface

Postby TimStone » 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( "5" )

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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: OT: .DLL interface

Postby Antonio Linares » Wed Oct 06, 2010 6:16 am

Tim,

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

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

Re: OT: .DLL interface

Postby TimStone » 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
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 134 guests

cron