Page 2 of 4
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 5:09 pm
by Antonio Linares
Tim,
For Microsoft and PellesC, please replace _export with __declspec(dllexport) and try to build it again, thanks

Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 5:30 pm
by TimStone
Here is the exact code I'm using:
Code: Select all | Expand
#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
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<<<
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 7:38 pm
by Antonio Linares
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>
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 9:44 pm
by TimStone
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.
Re: OT: .DLL interface
Posted: Mon Oct 04, 2010 11:45 pm
by Antonio Linares
Tim,
You have to implement the other missing functions:
Code: Select all | Expand
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 ) );
}
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 4:59 pm
by TimStone
Here is the current code using your model:
Code: Select all | Expand
#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
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 5:06 pm
by Antonio Linares
Tim,
Some changes are required. Please try it this way:
Code: Select all | Expand
#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
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 5:50 pm
by TimStone
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 ?
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 7:58 pm
by Antonio Linares
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).
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 11:27 pm
by TimStone
It now compiles ! This is good progress. However, the program dies without any message at REGISTER( ).
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 11:41 pm
by Antonio Linares
Tim,
Please set these traces and lets see how far it goes:
Code: Select all | Expand
HB_FUNC( REGISTER )
{
MessageBox( 0, "before", "register", 0 );
WCAPRegisterReceive( ( LONG ) RcvProcedure );
MessageBox( 0, "after", "register", 0 );
}
Re: OT: .DLL interface
Posted: Tue Oct 05, 2010 11:43 pm
by Antonio Linares
Tim,
Also, please create a DEF file from the EXE:
impdef.exe test.def test.exe
and copy the DEF file here, thanks
Re: OT: .DLL interface
Posted: Wed Oct 06, 2010 12:05 am
by TimStone
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 ....
Re: OT: .DLL interface
Posted: Wed Oct 06, 2010 6:16 am
by Antonio Linares
Tim,
Please send me a ZIP file (renamed as *.ZOP) with your EXE, thanks
Re: OT: .DLL interface
Posted: Wed Oct 06, 2010 11:55 pm
by TimStone
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 ...