Page 1 of 1

EP_RegLoadKeyEx

Posted: Mon Nov 05, 2012 3:10 pm
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?

Re: EP_RegLoadKeyEx

Posted: Mon Nov 05, 2012 3:22 pm
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;
    }