May 01, 2024, 05:09:26 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Writing binary values to the registry

Started by Andy, November 17, 2011, 12:22:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

I decided to revisit some older code I was working on.

I am trying to write binary values to the registry, and I have got very close but there is a problem - I cannot write "00" - the Null character.

This is older code and a bit long winded - but it works up to a point.

How can I write the Null character, any suggestions?

Attached is the program and the include file.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Copex

Ive not tryed your code but, would this not work?

-------------------------
int VALL

VALL = null

print "Null Vallue"
print VALL

do : until inkey$ <>""
---------------------------

So

IF backsymbol = NULL

??????
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

Andy

Thanks for trying,

It won't work for me as it has to be a string value not an int.

When I convert it to ascii using the CHR$ command, it gives a zero which is ascii value 30 and inserts 30 not Null, I need an ascii value of "00" (Null).

If I can get this working it may be useful to everyone.

Thanks again,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Copex

November 17, 2011, 03:50:17 AM #3 Last Edit: November 17, 2011, 03:52:18 AM by Copex
humm ok i see what you meen...... ASCii v30 when you write to a file.

int VALL
string val1,val2

VALL = null
val1 = chr$(vall)
val2 = "0"

Print "Char Oct Dec Hex Control-Key Control Action"
print:print "0 60 48 30             Zero "
print:print "NUL 0 0 0 ^@         Null character "

print:Print "CHR/ASC/Hex Value"
print:print "chr =  ",val1," ASC = ",ASC(val1)," HEX = ",HEX$(asc(Val1))
print "CHR = ",val2," ASC =  ",ASC(val2)," HEX = ",HEX$(asc(Val2))
do : until inkey$ <>""
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

LarryMc

I don't have time to code it out but this is what I'd do if it absolutely has to be a string.

I assume that the hex string you will possibly process can be anything from '00' to 'FF'; that there is no value you could never get and therefore can't be substituted in place of '00'


You are converting base  16 to base 10 and are trying to take 2 char and convert to one.

I'd take 1 char instead of 2 at a time but save in groups of 2

so, the max I can get in one char (v1) is 'F' for a value of 15
add a constant to it to put the asc of it at "A" when the value is 0
get the next hex char(v2) and do the same to it
tmpstr = chr$(v1)+chr$(v2)
so a hex '00" wil be 'AA' which will be your backsymbol

when the registry string is read you procress 2 chars as a group
get the first(v1) and get the ASC of it then subtract the constant
get v2 and do the same

to get the value you started with v1*16+v2


I don't know how long or how many characters you plan on storing in the registry but this scheme would double the number for any given input.


OK, it's 5:15 in the morning and I've been up (coding) for 15+ straight hours.  
When someone reads this it might not make any sense at all.
If that's the case then, cut an old man some slack.

Hope this helps

larryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

will try your idea - go get some sleep!

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Johnny

Hello to all,

In the past I struggled more then once with that limitation of storing "binary" data in strings...   :(
A "00" value indicates for Basic internally the "end of string", so when you try to put "00" in a normal string, that's the end of the string for Basic, all what comes after "00" is ignored...
But for DLL files, this is usually a valid value inside a string, like for the registry in this case for example.

But I discovered long ago a well working workaround to get also "00" characters in strings, that's what I like in Basic, there's always a back door...   ;D
Strings with a "00" in the middle are still useless for Basic itself, but you can send them to DLL functions without problems!

Theory: A DLL only receives "a piece of memory" where the string is stored (through the pointer to the string), and doesn't care that Basic sees a "0" as end-of-string.
You only need to get the correct data in the correct bytes of the string's memory space...

To do this, use an ISTRING variable instead, with enough length to store your complete string, it may be longer, that is no problem.
DEF Output$[20]:ISTRING
Then you fill that "storage space" in memory with whatever you like, also "00", and this on a byte-by-byte basis, like this for example:
FOR X = 0 to 19
   Output$[X] = CHR$(0) ' Here you can fill your string with whatever value (between 0 and 255) you need to send!
NEXT X

(Naturally, the "0" in CHR$(0) will become the value that you like to store in that position)

Now the whole string is filled with data, including the necessary "00" bytes, you just use this string now into your DLL function.
In general, you also need to deliver the length of the string to that DLL function, but do not use LEN(Output$) here, that value is incorrect when there is a "00" in it!
You have to keep track of the "special string's length" in a separate counter or so...

This trick saved my day several times until now.   :)
I hope this helps you and maybe also others to solve problems like this...

Good luck!!
Johnny

Andy

Hi Johnny and to all,

Yes, that little trick worked!  :)

I have attached a working copy of the program and the include file.

Once you have run the program, check the registry key and it's there.

Before I finish this thread can anyone tell me why in EB this line is ok:

DECLARE IMPORT,RegEnumValueA(hKey AS INT,dwIndex AS INT,lpValueName AS STRING,lpcbValueName AS POINTER,lpReserved AS INT,lpType AS POINTER,lpData AS POINTER BYREF,lpcbData AS POINTER),INT

The line above was in the old registry.inc file not this one.

IWB is complaining about the BYREF in this line, it's not a major thing it just stops me enumerating reg sub keys in IW as I have had to remove the BYREF out of the line of code.

Not urgent but if anyone knows how to change it that would be great  ;)

Thanks everyone!
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

I plugged your DECLARE into one of my programs and got a duplicate definition error (I use Sapero's windowssdk.inc).
There it is :

declare import,RegEnumValueA(HKEY hKey,DWORD dwIndex,LPSTR lpValueName,pointer lpcchValueName,pointer lpReserved,pointer lpType,pointer lpData,pointer lpcbData),LONG

In yours it's lpData AS POINTER BYREF which would indicate a 'pointer to  a pointer'

The one above is simply a pointer.  That would indicate that if your lpData is of type string or a udt which are passed by ref as the default you simply enter the var.  If lpData is not one of those two types then you would have to pass &var.

That's my guess anyway.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

I have now found out that the problem is NOT the BYREF entry in the include file, the problem is invoking this command:

RegEnumKeyExA

I've attached an example program to enumerate a registry key, the program works fine in EB but the application hangs in IWB on the line:

retval = RegEnumKey(examkey,y) 'where examkey is the sub key name & y in the key number.

Strange  ???

May never find the answer to this one.

But thanks for trying,
Andy.




Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.