Accessing a Delphi DLL function.

User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Accessing a Delphi DLL function.

Post by Jeff Barnes »

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


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 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

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 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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

Post by Antonio Linares »

Jeff,

Please try this:

Code: Select all

#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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

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:

Code: Select all


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

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 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Same thing ... Always shows 0 (zero)
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Hi Antonio,

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


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



Thanks,
Jeff
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Antonio,

Please check your email.

Jeff
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jeff,

I am testing it this way, so it can be simpler:

Code: Select all

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

Post by Antonio Linares »

Jeff,

There you have the MessageBox() shown value:

Code: Select all

   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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

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 12.01, xHarbour 1.2.1, Bcc582)
Post Reply