FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Accessing a Delphi DLL function.
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Mon Oct 22, 2007 01:37 PM
Hi Everybody,

I have a Test DLL from a company that has a cost effective way of converting a standard USB Jump drive into a software protection device.
The software is called AntiDuplicate. It modifies a standard USB Jump drive so that it knows the difference between the original and a copy thus allowing you to use it as a hardware key (sells for $129.00 U.S.)

I need to know if it is possible to read data form this file.

The test dll can be downloaded from my site:

www.can-soft.net/dl/TestDLL.zip
" rel="noopener">
www.can-soft.net/dl/TestDLL.zip


They also gave me this info:


If Fivewin can call functions with the array as argument and use the result from the same array, we can use AntiDuplicate DLL.

This package contains the DLL and an example of the test function call (on Delphi Pascal). If you prefer example on other program language, please let me know.
If you'll call function correctly, after the function call you'll get A[99] = 8300.



Does anyone know if Fivewin can work with this?
Can someone provide a sample of how to read it?

Thanks,
Jeff
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Mon Oct 22, 2007 01:39 PM

Jeff,

Please review samples\dlls\delphi32*.prg to access a Delphi DLL from FW

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Mon Oct 22, 2007 02:13 PM

Antonio,

I have looked at the sample but how do you return an array from a Delphi DLL?

The samples seem to work fine for text but I get NIL returned with the array.

Thanks,
Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Mon Oct 22, 2007 02:23 PM

Jeff,

> If you prefer example on other program language, please let me know

Could you please ask them for a C language sample ? thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Mon Oct 22, 2007 02:33 PM
Jeff,

Please try this:
#include "FiveWin.ch"
#include "Struct.ch"

function Main()

   local oStruct, cBuffer

   STRUCT oStruct
      MEMBER n1 AS LONG
      MEMBER n2 AS LONG
      ... // please repeat it up to 128
      MEMBER n128 AS LONG
   ENDSTRUCT

    cBuffer = oStruct:cBuffer
   TestFunc1( cBuffer )
   oStruct:cBuffer = cBuffer

   MsgInfo( oStruct:n1 )

return nil

DLL FUNCTION TESTFUNC1( pValues as LPSTR ) AS BOOL PASCAL LIB "
TestLib12.dll'
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Tue Oct 23, 2007 01:38 AM
Antonio,

The code you gave me will only return a 0 (zero).

I asked for a C Language sample and this is what they sent me:

=======================

typedef VOID (CALLBACK* LPFNDLLACC1)(LONG[127]);

.....

HINSTANCE hDLL;              // Handle to DLL
LPFNDLLACC1 lpfnDllFunc1;    // Function pointer
LONG a[128];
INT i;

.....

hDLL = LoadLibrary("TestLib12.dll");
if (hDLL != NULL)
{
        for (i = 0; i < 128; i++)
                a[i] = i;
        lpfnDllFunc1 = (LPFNDLLACC1)GetProcAddress(hDLL, "TestFunc1");
        if (!lpfnDllFunc1)
        {
                printf("Function not found!\n");
        }
        else
        {
                // call the function
                lpfnDllFunc1(a);
                printf("Result = %u\n", a[99]);
        }
        FreeLibrary(hDLL);
}

=======================




Thanks,
Jeff
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Tue Oct 23, 2007 07:26 AM

Jeff,

Please change this line:

DLL FUNCTION TESTFUNC1( pValues AS LPSTR ) AS BOOL PASCAL FROM "TestFunc1" LIB "TestLib12.dll"

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Tue Oct 23, 2007 05:12 PM

Same thing ... Always shows 0 (zero)

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Tue Oct 23, 2007 07:07 PM

Jeff,

Could you please ask the developers to place a MessageBox( 0, "here", "inside the DLL", 0 ); inside that DLL function just to check if we properly access it ? thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Thu Oct 25, 2007 02:46 PM

Hi Antonio,

Ok ... here is the latest DLL from the company:

http://www.antiduplicate.com/t/TestDLL.zip

Thanks,
Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Thu Oct 25, 2007 03:14 PM

Jeff,

The function is getting called as the MessageBox() is shown.

Could you provide me the PRG declaring the 128 members of the struct ? Thanks,

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Thu Oct 25, 2007 03:40 PM

Antonio,

Please check your email.

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Thu Oct 25, 2007 03:41 PM
Jeff,

I am testing it this way, so it can be simpler:
#include "FiveWin.ch" 
#include "Struct.ch" 

function Main() 

   local oStruct, cBuffer, n

   STRUCT oStruct 
      MEMBER cData AS STRING LEN 4 * 128 
   ENDSTRUCT 

   oStruct:cData = Replicate( " ", 4 * 128 )
   MsgInfo( Empty( oStruct:cData ) )

   cBuffer = oStruct:cBuffer 
   TestFunc1( cBuffer ) 
   oStruct:cBuffer = cBuffer 

   MsgInfo( Empty( oStruct:cData ) )
   
   for n = 1 to Len( oStruct:cData )
      if SubStr( oStruct:cData, n, 1 ) != " "
         MsgInfo( n )
      endif
   next      

return nil 

DLL FUNCTION TESTFUNC1( pValues as LPSTR ) AS BOOL PASCAL ;
FROM "TestFunc1" LIB "TestLib12.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Accessing a Delphi DLL function.
Posted: Thu Oct 25, 2007 03:47 PM
Jeff,

There you have the MessageBox() shown value:
   for n = 1 to Len( oStruct:cData ) 
      if SubStr( oStruct:cData, n, 1 ) != " " 
         MsgInfo( n ) 
      endif 
   next
   
   MsgInfo( Bin2L( SubStr( oStruct:cData, 1, 4 ) ) ) // <=====

Don't know why they show [99], when they are placing it at zero :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Accessing a Delphi DLL function.
Posted: Thu Oct 25, 2007 04:50 PM

Antonio,

Are you sure this is right? They told me that the value should be 8300 at a[99].

With this code we get a value of 808464534.

It looks like the input and output values are the same?

Jeff

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)