FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour OT: .DLL interface
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 12:15 AM

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.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Thu Oct 07, 2010 07:43 AM

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.

regards, saludos

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

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.

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: Thu Oct 07, 2010 07:10 PM

Tim,

You have to create the import library for Borland this way:

implib.exe wcap.lib wcap.dll

regards, saludos

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

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)

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: Thu Oct 07, 2010 11:40 PM

Tim,

Have you included wcap.lib in the UEStudio FWH settings ?

regards, saludos

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

It is in the application file for xHarbour in the FWH libraries listing, with reference to the proper directory.

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: Fri Oct 08, 2010 06:28 AM

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 );

regards, saludos

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

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 ...

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: Fri Oct 08, 2010 07:52 PM

Tim,

Very good! :-)

Now, lets jump from C level to PRG code...

I am writing the code

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 07:58 PM
You have to modify this function this way:
Code (fw): Select all Collapse
#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 (fw): Select all Collapse
function CallBack( cXML, nSize )
   
   MsgInfo( cXML, "It works!" )

return nil
regards, saludos

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

Tim,

Do you have an example for their CalledBack() pascal code ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: OT: .DLL interface
Posted: Fri Oct 08, 2010 09:26 PM
Here is their Delphi code:

Code (fw): Select all Collapse
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 (fw): Select all Collapse
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
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: Sat Oct 09, 2010 05:54 AM

Tim,

It seems as they don't return anything to the DLL...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 77
Joined: Sun Aug 26, 2007 11:53 PM
Re: OT: .DLL interface
Posted: Thu Oct 14, 2010 12:04 AM

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!