#163610 - 2006-06-23 06:00 PM
Function Specifications
|
jtokach
Seasoned Scripter
   
Registered: 2001-11-15
Posts: 513
Loc: PA, USA
|
This form of function specification seems to be pretty prevalent with MS technologies, that is, assigning IN's and OUT's in the function declaration. I see some benefits and drawbacks, depending on how you look at it. I don't think I've ever used a KiX UDF that utilizes this format. I was wondering if maybe I'm missing the bigger picture or anyone has any thoughts on this.
Consider this from the WMI SDK:
EnumValues Method in Class StdRegProv The EnumValues method enumerates the named values of the given subkey. This topic uses Visual Basic syntax. For information on using this method with C/C++, see Calling a Method.
Registry.EnumValues( _ Long hDefKey, _ String sSubKeyName, _ Variant sNames(), _ Variant iTypes() _ ) As Integer Parts Registry Variable of a StdRegProv object data type. hDefKey [in] Optional parameter that specifies the tree that contains the sSubKeyName path. The default value is HKEY_LOCAL_MACHINE (0x80000002). The following trees are defined in Winreg.h: HKEY_CLASSES_ROOT (0x80000000) HKEY_CURRENT_USER (0x80000001) HKEY_LOCAL_MACHINE (0x80000002) HKEY_USERS (0x80000003) HKEY_CURRENT_CONFIG (0x80000005) HKEY_DYN_DATA (0x80000006) Note that HKEY_DYN_DATA is a valid tree for Windows 95 and Windows 98 computers only.
sSubKeyName [in] Specifies the path that contains the named values to be enumerated. sNames [out] Contains an array of named value strings. The elements of this array correspond directly with the elements of iTypes. iTypes [out] Contains an array of data value types (integers). You can use these types to determine which Get method to call. For example, if the data value type is REG_SZ, you would call GetStringValue to retrieve the named value's data value. The elements of this array correspond directly with the elements of sNames. The following data value types are defined in Winnt.h: REG_SZ (1) REG_EXPAND_SZ (2) REG_BINARY (3) REG_DWORD (4) REG_MULTI_SZ (7) Return Values The EnumValues method returns a uint32 which is 0 if successful or some other value if any other error occurred.
Example The following example shows how to use the EnumValues method. Code:
'Assumes objRegistry is a valid StdRegProv object. On Error Resume Next
Const HKEY_LOCAL_MACHINE As Long = &H80000002 Const REG_SZ As Integer = 1 Const REG_EXPAND_SZ As Integer = 2 Const REG_BINARY As Integer = 3 Const REG_DWORD As Integer = 4 Const REG_MULTI_SZ As Integer = 7
Dim lRC As Long Dim sPath As String Dim sNames() As Variant Dim iTypes() As Variant Dim sValue As String Dim sMultiStrings() As Variant Dim uBinary() As Variant Dim lDWORDValue Dim i, j As Integer Dim sMsg As String
sPath = "SOFTWARE\MyKey" lRC = objRegistry.EnumValues(HKEY_LOCAL_MACHINE, sPath, sNames, iTypes)
If (lRC = 0) And (Err.Number = 0) Then For i = LBound(iTypes) To UBound(iTypes) Select Case iTypes(i) Case REG_SZ lRC = objRegistry.GetStringValue(HKEY_LOCAL_MACHINE, _ sPath, _ sNames(i), _ sValue) If sNames(i) = "" Then 'the default named value sMsg = sMsg & "default" & " = " & sValue & vbCrLf Else sMsg = sMsg & sNames(i) & " = " & sValue & vbCrLf End If Case REG_EXPAND_SZ lRC = objRegistry.GetExpandedStringValue(HKEY_LOCAL_MACHINE, _ sPath, _ sNames(i), _ sValue) If sNames(i) = "" Then 'the default named value sMsg = sMsg & "default" & " = " & sValue & vbCrLf Else sMsg = sMsg & sNames(i) & " = " & sValue & vbCrLf End If Case REG_BINARY lRC = objRegistry.GetBinaryValue(HKEY_LOCAL_MACHINE, _ sPath, _ sNames(i), _ uBinary) If sNames(i) = "" Then 'the default named value sMsg = sMsg & "default" & " = " Else sMsg = sMsg & sNames(i) & " = " End If For j = LBound(uBinary) To UBound(uBinary) sMsg = sMsg & uBinary(j) & " " If j = UBound(uBinary) Then sMsg = sMsg & vbCrLf End If Next j Case REG_DWORD lRC = objRegistry.GetDWORDValue(HKEY_LOCAL_MACHINE, _ sPath, _ sNames(i), _ lDWORDValue) If sNames(i) = "" Then 'the default named value sMsg = sMsg & "default" & " = " & Hex(lDWORDValue) & vbCrLf Else sMsg = sMsg & sNames(i) & " = " & Hex(lDWORDValue) & vbCrLf End If Case REG_MULTI_SZ lRC = objRegistry.GetMultiStringValue(HKEY_LOCAL_MACHINE, _ sPath, _ sNames(i), _ sMultiStrings) If sNames(i) = "" Then 'the default named value sMsg = sMsg & "default" & " = " Else sMsg = sMsg & sNames(i) & " = " End If For j = LBound(sMultiStrings) To UBound(sMultiStrings) sMsg = sMsg & multi_sz(j) If j <> UBound(sMultiStrings) Then sMsg = sMsg & "," Else sMsg = sMsg & vbCrLf End If Next j Case Else sMsg = sMsg & sNames(i) & " = " & "Unknown" & vbCrLf End Select Next i MsgBox sMsg Else 'An error occurred End If
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|