OT: .DLL interface

Re: OT: .DLL interface

Postby reinaldocrespo » 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.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

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

Re: OT: .DLL interface

Postby Antonio Linares » Fri Oct 08, 2010 7:58 pm

You have to modify this function this way:
Code: Select all  Expand view
#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 view

function CallBack( cXML, nSize )
   
   MsgInfo( cXML, "It works!" )

return nil
 
regards, saludos

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

Re: OT: .DLL interface

Postby Antonio Linares » Fri Oct 08, 2010 8:03 pm

Tim,

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

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

Re: OT: .DLL interface

Postby TimStone » Fri Oct 08, 2010 9:26 pm

Here is their Delphi code:

Code: Select all  Expand view

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 view

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

Re: OT: .DLL interface

Postby Antonio Linares » Sat Oct 09, 2010 5:54 am

Tim,

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

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

Re: OT: .DLL interface

Postby Jonathan Hodder » 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!
Jonathan Hodder
 
Posts: 77
Joined: Sun Aug 26, 2007 11:53 pm

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: George, nageswaragunupudi and 28 guests