Page 1 of 2
Accessing a Delphi DLL function.
Posted: Mon Oct 22, 2007 1:37 pm
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
Posted: Mon Oct 22, 2007 1:39 pm
by Antonio Linares
Jeff,
Please review samples\dlls\delphi32\*.prg to access a Delphi DLL from FW
Posted: Mon Oct 22, 2007 2:13 pm
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
Posted: Mon Oct 22, 2007 2:23 pm
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
Posted: Mon Oct 22, 2007 2:33 pm
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'
Posted: Tue Oct 23, 2007 1:38 am
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
Posted: Tue Oct 23, 2007 7:26 am
by Antonio Linares
Jeff,
Please change this line:
DLL FUNCTION TESTFUNC1( pValues AS LPSTR ) AS BOOL PASCAL FROM "TestFunc1" LIB "TestLib12.dll"
Posted: Tue Oct 23, 2007 5:12 pm
by Jeff Barnes
Same thing ... Always shows 0 (zero)
Posted: Tue Oct 23, 2007 7:07 pm
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
Posted: Thu Oct 25, 2007 2:46 pm
by Jeff Barnes
Hi Antonio,
Ok ... here is the latest DLL from the company:
http://www.antiduplicate.com/t/TestDLL.zip
Thanks,
Jeff
Posted: Thu Oct 25, 2007 3:14 pm
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,
Posted: Thu Oct 25, 2007 3:40 pm
by Jeff Barnes
Antonio,
Please check your email.
Jeff
Posted: Thu Oct 25, 2007 3:41 pm
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"
Posted: Thu Oct 25, 2007 3:47 pm
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
Posted: Thu Oct 25, 2007 4:50 pm
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