Registry Module (windows only)

Share your advanced PureBasic knowledge/code with the community.
AZJIO
Addict
Addict
Posts: 1355
Joined: Sun May 14, 2017 1:48 am

Re: Registry Module (windows only)

Post by AZJIO »

Gives an error

Code: Select all

XIncludeFile "Registry.pbi"
UseModule Registry
Debug ReadValue(#HKEY_CLASSES_ROOT, "batfile\shell\runas\command", "")
Debug ReadValue(#HKEY_CLASSES_ROOT, "VBSFile\Shell\Open2", "")
On line 525

Code: Select all

      Case #REG_EXPAND_SZ
        ExSZlength = ExpandEnvironmentStrings(*lpData, 0, 0)
5.72 x32/x64
Win10 x64 1809
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Registry Module (windows only)

Post by ChrisR »

It works without any problem here:

Code: Select all

C:\Windows\System32\cmd.exe /C "%1" %*
Open &with Command Prompt
Is it related to Russian Cyrillic characters for you ?
AZJIO
Addict
Addict
Posts: 1355
Joined: Sun May 14, 2017 1:48 am

Re: Registry Module (windows only)

Post by AZJIO »

1. there is no cyrillic alphabet in both registry keys. It's not the first time I use the module, it works fine with Cyrillic
2. I temporarily made the WinAPI function, given that I only need to get strings. Source (Line 217-222)

Code: Select all

Procedure.s RegRead(Root, KeyPath$, ValueName$)
	Protected Size, ValueData$, hKey, Type
	If #ERROR_SUCCESS = RegOpenKeyEx_(Root,KeyPath$,0,#KEY_READ,@hKey)
		If #ERROR_SUCCESS = RegQueryValueEx_(hKey,ValueName$,0,@Type,0,@Size)
			ValueData$=Space(Size)
			If #ERROR_SUCCESS = RegQueryValueEx_(hKey,ValueName$,0,0,@ValueData$,@Size)
			EndIf
		EndIf
		RegCloseKey_(hKey)
	EndIf
	ProcedureReturn ValueData$
EndProcedure
3. Rebooted for prevention. The problem was not eliminated.
4. There are no special differences, other file extensions work.
5. I was confused by the fact that I am reading the line #REG_SZ, and an error is issued on the data type #REG_EXPAND_SZ.
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: Registry Module (windows only)

Post by fryquez »

There are 2 bugs with #REG_EXPAND_SZ.

1. ExpandEnvironmentStringsW is not located in advapi32.dll
2. ExpandEnvironmentStringsW does expects the size in Characters

Change all calls from ExpandEnvironmentStringsW to ExpandEnvironmentStrings_

and change this line

*ExSZMem = AllocateMemory(ExSZlength)

to

*ExSZMem = AllocateMemory(ExSZlength * 2)
Post Reply