1. Registry creation and BINARY values (should be a song)

Hello all,

Im now working on my own wrapper for Windows Registry read/write/delete etc.
I found some bugs in Davi Tassinari de Figueiredo reg.ew routines one of them
being
KEY_ALL_ACCESS = #3F
which should be this value
KEY_ALL_ACCESS = #1F003F
and a few others I cant remember right off.

His routines mostly do not use the EX routines, mine will.

I have run into one small problem I think you can help me solve or bring
understanding
to my pea-sized brain. (below) is code for creating a registry key and inserting
several
different data types by their given name. The problem I have is with BINARY, how
am
I supposed to get around euphoria saying "end of line reached without closing"
if the
binary string is not acceptable, or contains escape characters etc..?
Can someone give me ideas what I might  run into later that may cause problems
with the
code..> This works on my Laptop w/98SE I tested it before hand.

<snip..>

without warning

include machine.e
include dll.e

atom kernel32, advapi32
kernel32 = open_dll("kernel32.dll")
advapi32=open_dll("advapi32.dll")

constant
   xlstrlen = define_c_func(kernel32,"lstrlen",{C_POINTER},C_INT)
,xRegCreateKeyEx =
   define_c_func(advapi32,"RegCreateKeyExA",{C_LONG,C_POINTER,C_LONG,C_POINTER,
   C_LONG,C_LONG,C_POINTER,C_POINTER,C_POINTER},C_LONG)
,xRegSetValueEx =
  define_c_func(advapi32,"RegSetValueExA",{C_LONG,C_POINTER,C_LONG,C_LONG,C_INT,C_LONG},C_INT)
  ,xRegQueryValueEx = define_c_func(advapi32,"RegQueryValueExA",
  {C_LONG,C_POINTER,C_POINTER,C_POINTER,C_POINTER,C_POINTER},C_INT)

constant
  HKEY_CLASSES_ROOT = #80000000,
  HKEY_CURRENT_USER = #80000001,
  HKEY_LOCAL_MACHINE = #80000002,
  HKEY_USERS = #80000003,
  HKEY_CURRENT_CONFIG = #80000005,
  HKEY_DYN_DATA = #80000006

constant
  REG_CREATED_NEW_KEY = 1,
  REG_OPTION_NON_VOLATILE = 0,
  STANDARD_RIGHTS_ALL = #1F0000,
  KEY_QUERY_VALUE = #1,
  KEY_SET_VALUE = #2,
  KEY_CREATE_SUB_KEY = #4,
  KEY_ENUMERATE_SUB_KEYS = #8,
  KEY_NOTIFY = #10,
  KEY_CREATE_LINK = #20,
  KEY_ALL_ACCESS = #1F003F

constant
  REG_SZ = 1,
  REG_BINARY = 3,
  REG_DWORD = 4

object junk

procedure CreateRegKey(atom hkey, sequence key, sequence Data)
  atom keyptr, nullptr, hRegKey, result, vNameptr, vDataptr
  integer regtype, data_len
  object vName, vData, binary

    keyptr = allocate_string(key)
    nullptr = allocate_string("")
    hRegKey = allocate(4)
    result = allocate(4)

if c_func(xRegCreateKeyEx,{hkey, keyptr, 0, nullptr, 0, KEY_ALL_ACCESS, 0,
    hRegKey, result}) = 0 then
      if peek4u(hRegKey) != 0 then
        if peek4u(result) =  REG_CREATED_NEW_KEY then
          for i = 1 to length(Data) do
            vName   = Data[i][1]
            regtype = Data[i][2]
            vData   = Data[i][3]

            if sequence(vName) then
              vNameptr = allocate_string(vName)
            else
              vNameptr = allocate(4)
              mem_set(vNameptr,0,4)
              poke4(vNameptr, vName)
            end if

            if sequence(vData) then
              vDataptr = allocate_string(vData)
              data_len = c_func(xlstrlen,{vDataptr})
            else
              data_len = 4
              vDataptr = allocate(4)
              poke4(vDataptr, vData)
            end if

junk = c_func(xRegSetValueEx,{peek4u(hRegKey), vNameptr, 0, regtype,
            vDataptr, data_len})

            free(vNameptr)
            free(vDataptr)
          end for
        --else -- to be completed
--  junk = c_func(xRegQueryValueEx,{peek4u(hRegKey), vNameptr, 0,
        regtype, vDataptr, data_len})
        end if
      end if
    end if
end procedure


-- sequence of Name, Type, Value
CreateRegKey(HKEY_CURRENT_USER, "EUPHORIA", {{"110", REG_DWORD, 8675309},
                                             {"111", REG_SZ, "String"},
{"112", REG_BINARY, "O# [! Y]! Y]!
                                             Y]!+]†ã!0ûã†!"},
                                             {"113", REG_SZ, "Cool eh"}})

puts(1,"finished")
if getc(0) then
end if

<..snip>

You will have to delete the key manualy. RegEdit is what I use to view the
registry at the moment.
When I have some more code together I'll stick it over into my EFFM viewer so
Euphoria will
have a really fast registry editor as well.

TIA,
Euman

new topic     » topic index » view message » categorize

2. Re: Registry creation and BINARY values (should be a song)

You should use a sequence of ASCII values rather than a literal string.

{"111",REG_SZ,"String 1"},
{"112",REG_BINARY,{65,35,32,27,73,220,240,243,33}},
{"113",REG_SZ,"String 2"}

Michael J. Sabal

>>> euman at bellsouth.net 05/09/02 03:54PM >>>
                                             {"111", REG_SZ,
"String"},
                                             {"112", REG_BINARY, "O# [!
Y]! Y]! Y]!+]*ã!0ûã*!"},
                                             {"113", REG_SZ, "Cool
eh"}})

new topic     » goto parent     » topic index » view message » categorize

3. Re: Registry creation and BINARY values (should be a song)

Hello again,

>Michael J. Sabal writes:

>You should use a sequence of ASCII values rather than a literal string.

>{"111",REG_SZ,"String 1"},
>{"112",REG_BINARY,{65,35,32,27,73,220,240,243,33}},
>{"113",REG_SZ,"String 2"}

This makes since to me...Thanks Michael
this means a loop to convert the binary into ascii values if presented with
string literals, this shouldnt be very hard.

Now that I looked into the access rights some more (cause I want this to be
perfect)

from the MS-SDK
KEY_ALL_ACCESS Combines the KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY,
KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and
KEY_SET_VALUE access rights, plus all the standard access rights except
SYNCHRONIZE.

when I looked at the standard rights info:
STANDARD_RIGHTS_ALL Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and
SYNCHRONIZE access.
STANDARD_RIGHTS_REQUIRED Combines DELETE, READ_CONTROL, WRITE_DAC, and
WRITE_OWNER access.

so in all actuality, my code was wrong and Davi Tassinari de Figueiredo reg.ew
is wrong

KEY_ALL_ACCESS = #F003F should be this if it were to be perfectly translated
from the MS-SDK

Euman

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu