Archive: Check if a string is Char(zero)


Check if a string is Char(zero)
I'm trying to get the label of a CD using this:


; Get current drive label
DriveInfo::GetDriveLabel "D:\"
Pop $1

But if there is no cd in drive, it returns a zero character (at least I think it is). How do I replace that zero char with "<empty>" for example?


strcmp "$1" "0" 0 +2
strcpy $1 "<empty>"

not the character "0" but Chr(0), so ascii value 0


ahh, use "" intead of "0" in the compare then.


hm doenst seem to work, perhaps it aint Chr(0), but

The plugin uses
GetVolumeInformation(buf,buf2,sizeof(buf2)-1,0,0,0,0,0);

and MSDN sais "If not all the requested information is retrieved, the return value is zero."

And if I display the var in a msgbox or any other thing it displays the square box char.

this is my code as it is now:



StrCpy $2 ""

again:
; Enumerate CD Drives
EnumCDs::next /NOUNLOAD
Pop $0
StrCmp $0 "error" done
StrCmp $0 "done" done

; Get current drive label
DriveInfo::GetDriveLabel "$0"
Pop $1

strcmp "$1" "" 0 +2
strcpy $1 "<empty>"

StrCpy $2 "$2|$0 $1"
goto again

done:
EnumCDs::next
Pop $0

WriteINIStr "$PLUGINSDIR\insertcd.ini" "Field 1" "ListItems" $2

What about calling kernel32 directly and bypassing the driveinfo plugin? ie something like this.


hm cant get that one working at all...


; $0 - Drive to check returns the Disc Serial Number

Function GetDiskVolumeSerialNumber

!define GetVolumeInformation "Kernel32::GetVolumeInformation(t,*t,i,*i,*i,*i,t,i) i"

StrCpy $R0 "hi"
System::Call '${GetVolumeInformation}("C:\",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})'
MessageBox MB_OK|MB_ICONSTOP "hi $R0 hi"

FunctionEnd ;GetDiskVolumeSerialNumber


always results in "hi hi hi" Shouldn't R1 be changed there?

With this works with me:


System::Call 'kernel32::GetVolumeInformation(t "C:\", t .r0 , i 255, *i .r1, *i .r2, *i .r3, *i .r4, i 255) i .r11'
DetailPrint $0
DetailPrint $1
DetailPrint $2
DetailPrint $3
DetailPrint $4
DetailPrint $R1