method must have a return type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michaeldebruin
    New Member
    • Feb 2011
    • 134

    method must have a return type

    Hello all,

    I am trying to get a program which can retrieve the serial key of Windows from the Registry. I've found the source code on this website, but I can't seem to get it working.
    This is the source code as I have it right now.
    Code:
    //first byte offset
            const int start = 52;
            //last byte offset
            const int end = start + 15;
            //decoded key length
            const int length = 29;
            //decoded key in byte form
            const int decoded = 15;
    
            public static DecodeKeyByteArray(byte id)
            {
        
                //char[] for holding the decoded product key
                var decodedKey = new char[length];
    
                //List<byte> to hold the key bytes
                var keyHex = new List<byte>();
    
                //list to hold possible alpha-numeric characters
                //that may be in the product key
                var charsInKey = new List<char>()
                        {
                            'B', 'C', 'D', 'F', 'G', 'H', 
                            'J', 'K', 'M', 'P', 'Q', 'R', 
                            'T', 'V', 'W', 'X', 'Y', '2', 
                            '3', '4', '6', '7', '8', '9'
                        };
    
                //add all bytes to our list
                for (var i = start; i <= end; i++)
                {
                    keyHex.Add(id[i]);
                }
                //now the decoding starts
                for (var i = length - 1; i >= 0; i--)
    
                    switch ((i + 1) % 6)
                    {
                        //if the calculation is 0 (zero) then add the seperator
                        case 0:
                            decodedKey[i] = '-';
                            break;
                        default:
                            var idx = 0;
    
                            for (var j = decoded - 1; j >= 0; j--)
                            {
                                var @value = (idx << 8) | keyHex[j];
                                keyHex[j] = (byte)(@value / 24);
                                idx = @value % 24;
                                decodedKey[i] = charsInKey[idx];
                            }
                            break;
                    }
                return new string(decodedKey);
            }
    
    
            private void btnGetSerialKey_Click(object sender, EventArgs e)
            {
                
                byte[] id = null;
                var regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
    
                if (regKey != null) id = regKey.GetValue("DigitalProductId") as byte[];
    
                btnGetSerialKey.Text = DecodeKeyByteArray(id);
    
            }
    Visual Studio keep saying that I must have a return method, but since I have a return method. I just don't know why it is going wrong.

    Thanks in advance for the help.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    if the method
    Code:
     public static DecodeKeyByteArray(byte id)
    returns a string then you must declare it as

    Code:
    public static string DecodeKeyByteArray(byte id)

    Comment

    Working...