Old 10th October 2014, 06:15   #1
roonwhit
Junior Member
 
Join Date: Jan 2004
Location: Perth, Western Australia
Posts: 14
GetBinaryType

I'm not a C programmer, so I'm having problems getting the kernel32::GetBinaryType call correct. I need to know whether Excel is 63-bit or 32-bit. I am reading the install location from registry, and then trying:
System::Call "kernel32::GetBinaryType(t r0, *l .r1)"
where $0 contains the full path and filename for excel.exe
(Argument types are LPCTSTR and LPDWORD, with the return BOOL, which I'm ignoring).

I have tried various combinations of variables to get the type back, but to no avail. I have written a Fortran executable that runs properly, but it would be much neater if it was in the script.
Thanks for any assistance.
roonwhit is offline   Reply With Quote
Old 10th October 2014, 08:10   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
There is no l, use i.

Stu
Afrow UK is offline   Reply With Quote
Old 10th October 2014, 08:18   #3
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
Because that function requires a pointer, you have to allocate enough bytes to store the data. So the required data for the result is a DWORD, which is 4 bytes. Then you have to extract the data from the pointer, then free the pointer.

Reference: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

Here's a quick example I wrote, this returns '0' for 32 bit makensisw, and '6' for 64 bit makensisw.

Quote:
Name "GetBinaryType test"
OutFile "GetBinaryType.exe"

RequestExecutionLevel User
ShowInstDetails Show

Page InstFiles

Section

;StrCpy $0 "C:\Program Files XP\NSIS\makensisw.exe"
StrCpy $0 "C:\x64NSIS_test\NSIS\makensisw.exe"

System::Alloc 4 ; Alloc 4 bytes for the function.
Pop $1
System::Call 'kernel32::GetBinaryType(t r0, i r1)'
System::Call '*$1(i .r2)' ; Extract the data.
System::Free $1

DetailPrint "Value of $$2: $2"

SectionEnd

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 10th October 2014, 09:07   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
Originally Posted by JasonFriday13 View Post
Because that function requires a pointer, you have to allocate enough bytes to store the data. So the required data for the result is a DWORD, which is 4 bytes. Then you have to extract the data from the pointer, then free the pointer.

Reference: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

Here's a quick example I wrote, this returns '0' for 32 bit makensisw, and '6' for 64 bit makensisw.
You don't need to allocate anything:
code:
System::Call `kernel32::GetBinaryType(t 'C:\Windows\SysNative\Notepad.exe', *i .R0)`
Stu
Afrow UK is offline   Reply With Quote
Old 10th October 2014, 09:23   #5
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
Cool, there's two different ways to do the same task . I haven't used the system plugin in ages and I don't know about that shortcut.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 10th October 2014, 14:38   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
Originally Posted by JasonFriday13 View Post
Cool, there's two different ways to do the same task . I haven't used the system plugin in ages and I don't know about that shortcut.
The pointer flag * only works for i, l and p and exists because some functions return DWORDs or pointers in some parameters. v3 beta1 supports the new @ syntax so you can return into a buffer up to about 1000 bytes without using System::Alloc as long as the parameter is out only.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th October 2014, 01:39   #7
roonwhit
Junior Member
 
Join Date: Jan 2004
Location: Perth, Western Australia
Posts: 14
I get a return value of 0 for both 32 and 64 bit exe files. Using *i doesn't make any difference.

Thx David
roonwhit is offline   Reply With Quote
Old 13th October 2014, 09:45   #8
roonwhit
Junior Member
 
Join Date: Jan 2004
Location: Perth, Western Australia
Posts: 14
Stu,

That works fine on my home computer ... will have to wait until tomorrow to check at work.
Thanks,
David
roonwhit is offline   Reply With Quote
Old 13th October 2014, 20:13   #9
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
If you are using the System32 path (e.g. $SYSDIR) for notepad.exe then GetBinaryType will always return 0. This is because the NSIS installer always gets the 32-bit binary path due to WOW64 file system redirection (NSIS is 32-bit). So either use SysNative or use the preferred method - disable WOW64 file system redirection using the ${DisableX64FSRedirection} macro in x64.nsh.

Stu
Afrow UK is offline   Reply With Quote
Old 13th October 2014, 22:17   #10
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Lightbulb

Quote:
Originally Posted by Afrow UK View Post
So either use SysNative or use the preferred method - disable WOW64 file system redirection using the ${DisableX64FSRedirection} macro in x64.nsh.
${DisableX64FSRedirection} is not always safe to use around a System::Call. There are at least three possible issues:

1) System::Call will call LoadLibrary on the specified module and this can fail if the module is not already loaded. Not a issue in this case since kernel32 is always loaded.

2) The function you are calling might load a library (delay loading, shell extensions etc). This can often happen when you are dealing with shell stuff (pidls/IShellFolder etc)

3) The function you are calling might use ImageHlp/DbgHelp or otherwise call LoadLibrary to parse a input file. We don't know how GetBinaryType works internally but since MSDN states that it supports \\?\ long paths we can hope that it just uses CreateFile.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th October 2014, 12:42   #11
roonwhit
Junior Member
 
Join Date: Jan 2004
Location: Perth, Western Australia
Posts: 14
I don't know about scratchpaper.com, but it is 2.46.5 Rev 2.
I have installed 3.0b1, which solves the problem, although I would prefer a portable version due to managed client restrictions at work.
roonwhit is offline   Reply With Quote
Old 15th October 2014, 13:17   #12
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
Quote:
Originally Posted by roonwhit View Post
I don't know about scratchpaper.com, but it is 2.46.5 Rev 2.
That version number is the same as the one from scratchpaper.com, which is unicode only.

NSIS 3 basically merges ansi and unicode together, no doubt PortableApps will update it once NSIS 3 hits mainstream (could be a while though).

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 15th October 2014, 14:07   #13
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
Originally Posted by roonwhit View Post
I don't know about scratchpaper.com, but it is 2.46.5 Rev 2.
I have installed 3.0b1, which solves the problem, although I would prefer a portable version due to managed client restrictions at work.
Portable apps from portableapps.com are not self contained AFAIK, that is, they can leave junk behind after running. Anyway, MakensisW will write a couple of entries in the registry but the compiler itself will not write anything anywhere so you can just install 3.0 at home, put it in a zip file and use that as your portable version...

IntOp $PostCount $PostCount + 1
Anders 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