GetDllBitness()

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

GetDllBitness()

13 Jan 2020, 14:29

whipped it up quick, placed here for reference..
GetDllBitness()
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: GetDllBitness()

13 Jan 2020, 14:53

Updated the API call as it was incorrect.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: GetDllBitness()

13 Jan 2020, 15:14

You can do it without imagehlp.dll

Code: Select all

oFile := FileOpen(DllPath, "r")
oFile.Seek(0x3c)
oFile.Seek(oFile.ReadInt()+4)
machineType := oFile.ReadUShort()
oFile.Close()
if (machineType = 0x14c)
   msgbox 32 bit
if (machineType = 0x8664) or (machineType = 0x200)
   msgbox 64 bit
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: GetDllBitness()

13 Jan 2020, 15:23

:) yah I was aware but figured using the api call would be somehow "cleaner" lol
also wouldn't oFile.ReadInt()+A_PtrSize be more compliant? *wonderin
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: GetDllBitness()

13 Jan 2020, 15:40

No. Because
After the MS-DOS stub, at the file offset specified at offset 0x3c, is a 4-byte signature that identifies the file as a PE format image file.
https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#signature-image-only
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: GetDllBitness()

13 Jan 2020, 18:13

What exactly does this do and what is it for?

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: GetDllBitness()

13 Jan 2020, 18:38

Delta Pythagorean wrote:
13 Jan 2020, 18:13
What exactly does this do and what is it for?
Based on the function's name, the example and the description (scroll down in the code window), I would suppose that it determines, if a specific dll-file is a 64 or a 32 bit library. ("It gets the bitness of a DLL").
Application case: As you might know, you can't use 64 bit DLLs on 32 bit Windows operating systems - so how do you determine programmatically, for example, if the user downloaded the right DLL version for a certain task?
Description: Returns a dll's bitness.
Parameters:
dll: The full path of the dll whose bitness is to be determined.
warn (optional): Displays a message if the dll is invalid then exits.
Return value: The return value is a nonzero number.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: GetDllBitness()

16 Jan 2020, 12:15

Hi, if the else branch is executed you do not free the loaded dll. In any case, it is not necessary to load it manually as dllcall will do it for you automatically if needed. See :arrow: dllcall - performance.

Thanks for sharing, cheers.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: GetDllBitness()

16 Jan 2020, 12:35

Thanks @Helgef
By `load it` do you mean explicit load of the imagehlp library? If so, my script crashes without it.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: GetDllBitness()

16 Jan 2020, 13:17

arent u also supposed to eventually UnMapAndLoad if ure gonna use this dllcall?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: GetDllBitness()

16 Jan 2020, 13:21

Sorry, I see you do a double numget, which means that you dereference something allocated by the dll, so indeed you need to load it explicitly and cannot rely on dllcall to do it for you.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: GetDllBitness()

17 Jan 2020, 10:52

I really did rush through this one.
Thanks guys, updated.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 80 guests