Jump to content

Dll Return Types


Recommended Posts

Alright, I will start by saying I HAVE looked at the DllCall section in the Help File.

Now, there are some Return Types that I don't see exactly in the Help File, particularly:

HMODULE

BOOL

and I was wondering if these might be:

PTR

BYTE

Is this correct? Is there a place that lists these and possibly more than these? Any clarification on these types would be greatly appreciated.

Also, how do you know when to use :cdecl? What determines whether it is used or not?

Thank you in advance.

Link to comment
Share on other sites

bool is bool (or int or long). It's not boolean (byte).

darkjohn20, new AutoIt, upgrade.

Oops, I ALWAYS forget to run help in Beta mode...I see it now. Thanks!

So, would hMODULE be handle then?

Edited by darkjohn20
Link to comment
Share on other sites

Here is some code I have so far for a resource project I am working on (you may have read my other post).

#RequireAdmin
#include <Array.au3>

$cEnumResTypeProc = DllCallbackRegister("_EnumResTypeProc", "bool", "handle;str;lparam")

$Kernel32 = DllOpen("Kernel32.dll")
ConsoleWrite("DLL: " & $Kernel32 & @CRLF)

$hFileName = FileOpenDialog("Find File", @WorkingDir, "Executable (*.exe)", 3)
ConsoleWrite("Path: " & $hFileName & @CRLF)

$hLoadLibrary = DllCall($Kernel32, "handle", "LoadLibrary", "str", $hFileName)
_ArrayDisplay($hLoadLibrary, "hLoadLibrary")

$EnumResourceTypes = DllCall($Kernel32, "bool", "EnumResourceTypes", "handle", $hLoadLibrary[0], "ptr", DllCallbackGetPtr($cEnumResTypeProc), "lparam", 0)
_ArrayDisplay($EnumResourceTypes, "EnumResourceTypes")

DllCallbackFree($cEnumResTypeProc)

Func _EnumResTypeProc($hMODULE, $lpssType, $lParam)
    ConsoleWrite("Type: " & $lpssType & @CRLF)
    Return True
EndFunc

It doesn't work, and I can't figure out why. It freezes on EnumResourceTypes. Any ideas?

Thanks.

To be clear, there is no response from _EnumResTypeProc(), so it must be a problem before that?

Edited by darkjohn20
Link to comment
Share on other sites

This is wrong:

$cEnumResTypeProc = DllCallbackRegister("_EnumResTypeProc", "bool", "handle;str;lparam")

It should be:

$cEnumResTypeProc = DllCallbackRegister("_EnumResTypeProc", "bool", "handle;ptr;lparam")

And the callback should be:

Func _EnumResTypeProc($hMODULE, $pStrOrResource, $lParam)

And from there you need to determine if its a resource ID, or a pointer to a string.

If it's a string pointer, you'll need to use DLLStructCreate() with the pointer.. problem is figuring out the string length.. you can experiment I guess with different sizes

*edit (2nd time!) - copying and pasting screws things up haha - had to use a popup window this time

Edited by Ascend4nt
Link to comment
Share on other sites

There is a print buffer mentioned in an example on MSDN:

TCHAR szBuffer[80]; // print buffer for info file

Perhaps that is a suggested size?

Edit: You can't use AutoIt tags on links (blue words) already inside AutoIt tags, because it gets the html code used to make that a link.

You can remove everything between the "[" and "]", including those and it will be fine.

I have this so far, but it freezes on DllStructCreate, so I know I'm doing it wrong:

Func _EnumResTypeProc($hMODULE, $lpssType, $lParam)
    $Is_IntResource = DllCall($Kernel32, "bool", "IS_INTRESOURCE", "word", $lpssType)

    If $Is_IntResource = True Then
        ConsoleWrite($lpssType & " is an IntResource" & @CRLF)
    ElseIf $Is_IntResource = False Then
        ConsoleWrite($lpssType & " is not an IntResource" & @CRLF)
        $Struct = DllStructCreate("char buffer[80]", $lpssType)
        ConsoleWrite("DLL Struct Data: " & DllStructGetData($Struct, "buffer") & @CRLF)
    EndIf

    $Struct = 0
    Return True
EndFunc

Would I place a DllStructCreate in when Is_IntResource is False?

Edited by darkjohn20
Link to comment
Share on other sites

IS_INTRESOURCE is a macro, which means it's not code that you can call, but a simple equation. Here's the definition from Winuser.h:

#define IS_INTRESOURCE(_r) ((((ULONG_PTR)(_r)) >> 16) == 0)

Basically that means this:

If BitShift($lpssType,16)=0 Then
    ConsoleWrite($lpssType & " is an IntResource" & @CRLF)
Else
    ConsoleWrite($lpssType & " is not an IntResource - but we still need to check the string for a #xxx" & @CRLF)
    $Struct = DllStructCreate("char var1[80]",$lpssType)
    $string=DllStructGetData($Struct,1)
    ; CHECK for #xxx in string for a resource #, otherwise, it should be a regular string - and then do what you will
EndIf
Edited by Ascend4nt
Link to comment
Share on other sites

Alright, I tried what you gave me, and this is the output (in this case anyways):

0x00000002 is an IntResource

0x00000003 is an IntResource

0x00000005 is an IntResource

0x0000000E is an IntResource

0x00000010 is an IntResource

0x00000018 is an IntResource

What happens if it IS an IntResource?

And what do I do if it ISN'T an IntResource and IS a Resource Number?

I'll do some more reading by myself for now. :(

Link to comment
Share on other sites

haha, I goofed - the one line should read:

$string=DllStructGetData($Struct,1)

Also - you might want to make sure this is all Unicode. In other words, call "EnumResourceTypesW" and use "wchar[80]" for the structure.

As far as the rest - I've never messed with Resource stuff (and don't have a need to), so someone else would have to help you there.

Link to comment
Share on other sites

Alright, thanks. I'll continue reading to see if any of the information I currently have has a specific use that I haven't read about yet (such as a direct place to "insert" a Resource #).

Thanks again.

Edit:

Hey, hey. This might have something to do with that resource number, no?

http://msdn.microsoft.com/en-us/library/ms648029%28VS.85%29.aspx

I still don't quite get macros. I understand the one you explained, but I'm not sure what to do with this. But, I can't be spoon-fed everything!:(

Edited by darkjohn20
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...