Page 3 of 4
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 12:15 am
by reinaldocrespo
Tim;
Hi. Never mind the size of the resulting .lib. It does not contain any code. It's just declarations for the linker. The actual code stays on the .dll. I also think that you should be able to have this working with xhb (xcc), so you shouldn't add the overhead of moving your dev environment over to bcc.
Although I consider that writing a c wrapper function as a very simple task, what you need seems to be a bit more complicated as you are not only calling a .dll function but also providing a pointer for one of those functions to call bck another c func that calls another a .prg function (I know I get lost here...).
Please send me your email address (reinaldo dot crespo at gmail) so that I can share with you some text about how c wrapper functions works with xharbour. That might not totally solve your problem, but it will help you get started or at least understand a little of what Antonio is doing. Thank God Antonio is helping.
Reinaldo.
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 7:43 am
by Antonio Linares
Tim,
I have inspected your EXE and it seems it is not exporting the required C function, thats probably why the application hangs.
As I have commented you by email, it seems as PellesC is not properly managing the __declspec(dllexport) directive.
At this point my advise is to try it using Borland or Microsoft.
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 4:57 pm
by TimStone
I tried with Borland but it found an error
I had to create a new .lib file ( IMPLIB ) so it would be Borland compatible. The bottom line is that the linker does not see the functions from that .lib so I can't get a build.
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 7:10 pm
by Antonio Linares
Tim,
You have to create the import library for Borland this way:
implib.exe wcap.lib wcap.dll
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 7:53 pm
by TimStone
I did that ... followed your directions from one of the original posts ...
I then put the library in the linker path with all the other .lib files
The build yields this message:
--------------------Configuration: wcap - Debug--------------------
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
Error: Unresolved external '_WCAPRegisterReceive' referenced from C:\USERS\TIM STONE\DOCUMENTS\PROJECTS\ASW9\DEBUG\WPAC.OBJ
Error: Unresolved external '_WCAPConnectAS' referenced from C:\USERS\TIM STONE\DOCUMENTS\PROJECTS\ASW9\DEBUG\WPAC.OBJ
Error: Unresolved external '_WCAPConnected' referenced from C:\USERS\TIM STONE\DOCUMENTS\PROJECTS\ASW9\DEBUG\WPAC.OBJ
Error: Unresolved external '_WCAPDisconnect' referenced from C:\USERS\TIM STONE\DOCUMENTS\PROJECTS\ASW9\DEBUG\WPAC.OBJ
Error: Unresolved external '_WCAPSend' referenced from C:\USERS\TIM STONE\DOCUMENTS\PROJECTS\ASW9\DEBUG\WPAC.OBJ
wcap.EXE - 5 error(s), 0 warning(s)
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 11:40 pm
by Antonio Linares
Tim,
Have you included wcap.lib in the UEStudio FWH settings ?
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 12:22 am
by TimStone
It is in the application file for xHarbour in the FWH libraries listing, with reference to the proper directory.
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 6:28 am
by Antonio Linares
Tim,
I see whats going on, the functions are in pascal mode.
So in your code you have to make these changes to use the right prototypes:
void pascal WCAPRegisterReceive( LONG);
BOOL pascal WCAPConnectAs( LPSTR, LONG, LONG );
BOOL pascal WCAPConnected( void );
void pascal WCAPDisconnect( void );
void pascal WCAPSend( LPSTR );
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 4:50 pm
by TimStone
VICTORY ! I got a build and it did connect.
Only 1 question left ... with the modified CalledBack( ) system, how can I read the reply message ? In other words, their .dll uses CalledBack( ) to place an XML response ...
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 7:52 pm
by Antonio Linares
Tim,
Very good!

Now, lets jump from C level to PRG code...
I am writing the code
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 7:58 pm
by Antonio Linares
You have to modify this function this way:
Code: Select all | Expand
#include <hbvm.h>
void __declspec(dllexport) RcvProcedure( char * szXML, LONG lSize )
{
hb_vmPushSymbol( hb_dynsymGetSymbol( "CALLBACK" ) ); // 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()
}
And add this function in your PRG code:
Code: Select all | Expand
function CallBack( cXML, nSize )
MsgInfo( cXML, "It works!" )
return nil
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 8:03 pm
by Antonio Linares
Tim,
Do you have an example for their CalledBack() pascal code ?
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 9:26 pm
by TimStone
Here is their Delphi code:
Code: Select all | Expand
procedure CalledBack(PC: PChar);
var
sDocType, sText :String;
iX :Integer;
XmlList :TXmlNodeList;
begin
with Form1 do
begin
Memo1.Text := Form1.Memo1.Text + String(PC);
Inc(Form1.FCount);
lblDLLStatus.Caption := IntToStr(Form1.FCount);
iX := Pos('Hello', String(PC));
if (iX > 40) AND (iX < 60) then
begin
xmlObject.ClearDocument;
xmlObject.LoadMemory(PC);
sDocType := Trim(xmlObject.Document.DocumentElement.TagName);
if sDocType = 'Hello' then
begin
XmlList :=
xmlObject.Document.DocumentElement.SelectNodes('Win32WindowHandle');
if XmlList.Length > 0 then //need to tranlate AAIA code
begin
sText := TXmlElement(XmlList.Item(0)).ElementText;
try
FServerHandle := StrToInt(sText);
lblSetFocus.Font.Color := clBlue;
except
FServerHandle := 0;
end;
XmlList.Free;
end;
end;
end;
end;
end; {CalledBack}
Here is their VB code:
Code: Select all | Expand
Sub CalledBack(ByVal lpszXMLDoc As Long)
Dim sXMLDoc As String
Dim iLen As Integer
iLen = lstrlen(lpszXMLDoc)
sXMLDoc = String$(iLen, 0)
Call lstrcpy(sXMLDoc, lpszXMLDoc)
Form1.Text1.Text = sXMLDoc
End Sub
Re: OT: .DLL interface
Posted: Sat Oct 09, 2010 5:54 am
by Antonio Linares
Tim,
It seems as they don't return anything to the DLL...
Re: OT: .DLL interface
Posted: Thu Oct 14, 2010 12:04 am
by Jonathan Hodder
Hi Tim
For a matter of interest what is this DLL used for?
I am dabbling in writing c (Borland) code for inclusion in my Harbour progs.
So far I've only modified existing c functions included in FW od xHarbour.
In following your experience tn this toppic this interface has provided me with a few tips.
I wonder if anyone has further info I read up on (not only for DLL interfaces)?
Thanks!