EP_RegLoadKeyEx

Post here any topics that related to Enigma Protector, its functionality, your misunderstanding, offers to improvements etc etc etc
Post Reply
mtx-electronics
Posts: 17
Joined: Wed Oct 10, 2012 8:09 am

EP_RegLoadKeyEx

Post by mtx-electronics »

I get a message from enigma protector that EP_RegLoadKey is deprecated and to use EP_RegLoadKeyEx. Looking at the INC file I see it has some new size parameters, do I have to first call the function with NULL for name & key to get size and after call again to get the name & key returned? or does it return all data with one call?
Enigma
Site Admin
Posts: 2946
Joined: Wed Aug 20, 2008 2:24 pm

Re: EP_RegLoadKeyEx

Post by Enigma »

Hi mtx-electronics, yes, exactly.

For C# and Delphi there is written some help functions that are using EP_RegLoadKeyEx. But the common scenario is same for any development language:

Code: Select all

    public static bool EP_RegistrationLoadKeyA(out string Name, out string Key)
    {
        Name = Key = string.Empty;
        int namelen = 0, keylen = 0;
        if (EP_RegLoadKeyEx(IntPtr.Zero, ref namelen, IntPtr.Zero, ref keylen) != LOADKEY_REGINFONOTFOUND)
        {
            byte[] namebuf = new byte[namelen];
            byte[] keybuf = new byte[keylen];
            if (EP_RegLoadKeyEx(Marshal.UnsafeAddrOfPinnedArrayElement(namebuf, 0), ref namelen, Marshal.UnsafeAddrOfPinnedArrayElement(keybuf, 0), ref keylen) == LOADKEY_SUCCEEDED)
            {
                Name = Encoding.ASCII.GetString(namebuf);
                Key = Encoding.ASCII.GetString(keybuf);
                return true;
            }
        }
        return false;
    }

    public static bool EP_RegistrationLoadKeyW(out string Name, out string Key)
    {
        Name = Key = string.Empty;
        int namelen = 0, keylen = 0;
        if (EP_RegLoadKeyEx(IntPtr.Zero, ref namelen, IntPtr.Zero, ref keylen) != LOADKEY_REGINFONOTFOUND)
        {
            byte[] namebuf = new byte[namelen];
            byte[] keybuf = new byte[keylen];
            if (EP_RegLoadKeyEx(Marshal.UnsafeAddrOfPinnedArrayElement(namebuf, 0), ref namelen, Marshal.UnsafeAddrOfPinnedArrayElement(keybuf, 0), ref keylen) == LOADKEY_SUCCEEDED)
            {
                Name = Encoding.Unicode.GetString(namebuf);
                Key = Encoding.Unicode.GetString(keybuf);
                return true;
            }
        }
        return false;
    }
Post Reply