Old 23rd July 2019, 15:55   #1
PascalB
Junior Member
 
Join Date: Jul 2019
Posts: 7
How to System.dll call plugin GetBinaryTypeA

Hi folks,

i have to check, if a application binary is 32 or 64 bit inside a Section.
Depending on the return value i have to execute different MSI-packages.

Windows has a nice function GetBinaryTypeA but i don't know how to set the parameters in NSIS syntax.

Here is what i have:
code:

; Set output path to the windows\system32 directory.
SetOutPath $WINDIR\System32 ; Set Path to kernel32.dll

StrCpy $0 "C:\Program Files\Microsoft Office\root\Office16\winword.exe" ; assign memory to $0
System::Call 'Kernel32::GetBinaryTypeA(t, *i) i(.r0, r1r1).r2'
DetailPrint 'Path: "$0"'
DetailPrint "Path length: $1"
DetailPrint "Return value: $2"



I only need the integer returned by the function. But i do always get $2 = 0, even if i use a invalid filename

$0 is always empty and $1 is always a 6 digit number.


Thanks in advance!
Best regards,
Pascal
PascalB is offline   Reply With Quote
Old 23rd July 2019, 17:07   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,165
You are pretty close but "GetBinaryTypeA" should be "GetBinaryType" for compatibility with Unicode and ".r0" is wrong, it means write to $0, you want "r0" (read from $0).

Quote:
StrCpy $0 "$windir\Explorer.exe"
System::Call 'KERNEL32::GetBinaryType(tr0, *i.r1)i.r0'
DetailPrint "Function returned $0, type is $1"
...
or

Quote:
System::Call 'KERNEL32::GetBinaryType(ts, *i.r1)i.r0' "$windir\Explorer.exe"
DetailPrint "Function returned $0, type is $1"
${If} $0 <> 0
... $1
${EndIf}
You should use $SysDir, not $WinDir\system32.

Your detection is probably flawed if Office 64 installs to the real 64-bit program files folder. Use the macros in x64.nsh to disable the FS redirection around the call to GetBinaryType.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th July 2019, 12:52   #3
PascalB
Junior Member
 
Join Date: Jul 2019
Posts: 7
Smile It works

Works great!
Thank you very much!
PascalB is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump