Jump to content

Can anyone translate this in to a dllcall?


Recommended Posts

It is supposed to tell it a copy protected flash drive is present. Here is what I have from their support:

You need to modify your executable file sources (by using our SDK samples) to enable reading the identification information from the USB drive:

This package contains the DLL and an example of the test function call (on C and Delphi).

If you'll call function correctly, after the function call you'll get A[99] = 8300.

Note that your application will receive output DLL (results) values in the array; some programming languages do not support this feature.

Of course, this is not really function from AntiDuplicate protection interface, this is only the test of the DLL compatibility.

Also note that you'll have to use binary OR, AND, XOR and NOT operations (with DWORD operands).

Sorry, we did not deal with AutoIt, and we cannot support conversion of our samples' code to this language.

Here is the C Example:

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;

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

}

Link to comment
Share on other sites

C translates pretty painlessly to autoit. Here's the example converted. But you will need to look up on dllstructs and -calls in the helpfile.

#cs
    Translated. Note: Requires newest version and maybe winapiex.au3 (cant remember ^^)
#ce
Local $hDll, $lpfnDllFunc1, $i
Local $A = DllStructCreate("long[128]")
$hDll = _WinApi_LoadLibrary("TestLib12.dll")
If $hDll
    For $i = 0 to 127
        DllStructSetData($a,1,$i,$i+1)
    Next
    $lpfnDllFunc1 = _WinApi_GetProcAddress($hDll, "TestFunc1")
    If NOT $lpfnDllFunc1 Then
        ConsoleWrite("Function not found!" & @LF)
    Else
        ; call the function
        DllCallAddress("void",$lpfnDllFunc1,"long*",DllStructGetPtr($a))
        ConsoleWrite("Result = " & DllStructGetData($a, 1,100) & @LF)
    EndIf
    _WinAPI_FreeLibrary($hDll)
EndIf

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

Thanks Shaggi. You are obviously a AutoIt head to the nth degree. My head is still swimming after a 15 year hatius from programming. Two questions if I may. 1) When I included WinAPIEx and ran the script I got a duplicate function _WinAPI_Duplicate handle because WinAPIEx does an include of WinApi and the same function is in both libraries. Did I do something wrong? Why would WinAPIEx include WinAPI when both libraries have the same function?

2) I have been beating my brains out trying to use the dllcall function and having it to nothing more then crash Windows. Should I stay away from dllcall and focus more on the functions in WinAPIEx?

Link to comment
Share on other sites

Thanks Shaggi. You are obviously a AutoIt head to the nth degree. My head is still swimming after a 15 year hatius from programming. Two questions if I may. 1) When I included WinAPIEx and ran the script I got a duplicate function _WinAPI_Duplicate handle because WinAPIEx does an include of WinApi and the same function is in both libraries. Did I do something wrong? Why would WinAPIEx include WinAPI when both libraries have the same function?

2) I have been beating my brains out trying to use the dllcall function and having it to nothing more then crash Windows. Should I stay away from dllcall and focus more on the functions in WinAPIEx?

1. I have no idea why they're doing that. Just don't include and use this snippet:

; /*****************************************
; * Retrieves the corrosponding address
; * to an ordinal or a string function
; * in a module
; *****************************************/
Func _GetProcAddress($hModule, $lpProcName)
    Switch VarGetType($lpProcName)
        Case "Int32" ;Ordinal passed
            Local $Type = "dword"
            Local $Value = _WinAPI_LoWord(_Iif($lpProc < 0, -$lpProc, $lpProc))
        Case "String" ;Function name passed
            Local $Type = "str"
            Local $Value = $lpProcName
        Case Else
            Return 0
    EndSwitch
    Local $Call = DllCall("Kernel32.dll", "handle", "GetProcAddress", _
            "handle", $hModule, _
            $Type, $Value)
    If NOT @Error Then Return $Call[0]
EndFunc   ;==>_GetProcAddress

2. Well that depends, if the function you want to call is avaible in the standard libraries, use that (unless it's extremely important to avoid the overhead of an wrapper-function ;) ). Of course, if the function isn't included in said libraries, you can't avoid dllcall. They're not really that hard to understand, read the topics in the helpfile and you're mostly set. Write here if you have any more questions or anything :)

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...