Z Zenerdiode Active Member Licensed User Mar 11, 2012 #1 I am getting a CS0266 compiler error when compiling the following line: Code: Sub Globals 'Declare the global variables here. Dim Binary(0) As Byte End Sub Sub App_Start Reg.New1 'Reg is a RegistryDesktop object Reg.RootKey(Reg.rtCurrentUser) Binary()=Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") 'Causing the CS0266 error '.... End Sub I may be wrong, but I think Reg.GetValue is trying to return an object that I'm then trying to assign to the array - but that is the method shown in the Registry library help. It works fine in the IDE; but when compiling to Desktop it return the compiler error. Could someone suggest a fix to the RegistryDesktop.cs file for me please?
I am getting a CS0266 compiler error when compiling the following line: Code: Sub Globals 'Declare the global variables here. Dim Binary(0) As Byte End Sub Sub App_Start Reg.New1 'Reg is a RegistryDesktop object Reg.RootKey(Reg.rtCurrentUser) Binary()=Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") 'Causing the CS0266 error '.... End Sub I may be wrong, but I think Reg.GetValue is trying to return an object that I'm then trying to assign to the array - but that is the method shown in the Registry library help. It works fine in the IDE; but when compiling to Desktop it return the compiler error. Could someone suggest a fix to the RegistryDesktop.cs file for me please?
B Basic4Life Member Licensed User Mar 11, 2012 #2 It should work if you switch Binary()=Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") Click to expand... with Binary()=Reg.GetBytesArray("Control Panel\Desktop","UserPreferencesMask") Click to expand...
It should work if you switch Binary()=Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") Click to expand... with Binary()=Reg.GetBytesArray("Control Panel\Desktop","UserPreferencesMask") Click to expand...
Z Zenerdiode Active Member Licensed User Mar 12, 2012 #3 Thank You - that has helped for getting a Byte array; however .GetValue is also used for returning an array of strings - in the case of a hive being a 'REG_MULTI_SZ' I still need a solution/update to RegistryDesktop.dll
Thank You - that has helped for getting a Byte array; however .GetValue is also used for returning an array of strings - in the case of a hive being a 'REG_MULTI_SZ' I still need a solution/update to RegistryDesktop.dll
M mjcoon Well-Known Member Licensed User Mar 12, 2012 #4 Zenerdiode said: Thank You - that has helped for getting a Byte array; however .GetValue is also used for returning an array of strings - in the case of a hive being a 'REG_MULTI_SZ' I still need a solution/update to RegistryDesktop.dll Click to expand... Is your complaint really that the Help for Registry.dll is a bit faulty? After all, there is a GetStringsArray() method. And a GetValueKind() for finding out which Get... method (and hence which variable) to use for each entry. So the problem is perhaps that GetValue can be used in the old flexible variable manner for non-array values that do not have to have a fixed declared type. But not, despite what the Help says, for arrays... Mike.
Zenerdiode said: Thank You - that has helped for getting a Byte array; however .GetValue is also used for returning an array of strings - in the case of a hive being a 'REG_MULTI_SZ' I still need a solution/update to RegistryDesktop.dll Click to expand... Is your complaint really that the Help for Registry.dll is a bit faulty? After all, there is a GetStringsArray() method. And a GetValueKind() for finding out which Get... method (and hence which variable) to use for each entry. So the problem is perhaps that GetValue can be used in the old flexible variable manner for non-array values that do not have to have a fixed declared type. But not, despite what the Help says, for arrays... Mike.
agraham Expert Licensed User Longtime User Mar 13, 2012 #5 Zenerdiode said: I am getting a CS0266 compiler ... It works fine in the IDE; but when compiling to Desktop it return the compiler error. Could someone suggest a fix to the RegistryDesktop.cs file for me please? Click to expand... I suspect that RegistryDesktop predates the optimising compiler and there isn't a simple mod for the C# code as it doesn't know the type of data. The underlying problem is that you can assign any just about anything (even an array) to a single variable of type Object as that is an automatic downcast but you can't assign an array of Object to an array of anything else without an explicit cast as that is an upcast. The best solution is, as suggested by Mike, to use GetBytesArray as you already know the type of the return that you want. You could also assign GetValue to a Door library Object (not an ObjectArray as that will error for the reason given above) and play with it using reflection Code: Obj1.New1(False) Obj1.Value = Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") v = Obj1.RunMethod2("GetValue", 0, "System.Int32") Msgbox(Obj1.RunMethod("ToString"), v)
Zenerdiode said: I am getting a CS0266 compiler ... It works fine in the IDE; but when compiling to Desktop it return the compiler error. Could someone suggest a fix to the RegistryDesktop.cs file for me please? Click to expand... I suspect that RegistryDesktop predates the optimising compiler and there isn't a simple mod for the C# code as it doesn't know the type of data. The underlying problem is that you can assign any just about anything (even an array) to a single variable of type Object as that is an automatic downcast but you can't assign an array of Object to an array of anything else without an explicit cast as that is an upcast. The best solution is, as suggested by Mike, to use GetBytesArray as you already know the type of the return that you want. You could also assign GetValue to a Door library Object (not an ObjectArray as that will error for the reason given above) and play with it using reflection Code: Obj1.New1(False) Obj1.Value = Reg.GetValue("Control Panel\Desktop","UserPreferencesMask") v = Obj1.RunMethod2("GetValue", 0, "System.Int32") Msgbox(Obj1.RunMethod("ToString"), v)
M mjcoon Well-Known Member Licensed User Mar 13, 2012 #6 agraham said: The underlying problem is that you can assign any just about anything (even an array) to a single variable of type Object as that is an automatic downcast but you can't assign an array of Object to an array of anything else without an explicit cast as that is an upcast. Click to expand... As far as that's concerned I'm just an outcast! Mike.
agraham said: The underlying problem is that you can assign any just about anything (even an array) to a single variable of type Object as that is an automatic downcast but you can't assign an array of Object to an array of anything else without an explicit cast as that is an upcast. Click to expand... As far as that's concerned I'm just an outcast! Mike.