> 
> Hi,
> I investigated a little bit more on this issue and I think I have a
> solution (Hope I'm not to late for RC3):
> 
> The numbering scheme in vbp is different at Objects(OCX) and
> References(DLL).
> 
> The version number for DLLs seems to be a HEX value like the
> corresponding registry typelib entry. At OCX the version number seems to
> be a DEC value. Therefore converting the VBP entries must be adjusted.
> The Typelib entries in registry are HEX values for both.
> 
> Patch summary:
> changed: Regex for References/Objects to get the hex major version
> changed: use the appropriate Converter
> changed: store filename in tempvar to add on logging output
> changed: some variables names, stripped 16
> 
> I'll include the patch here. If I should file a bug or patch entry then
> drop me a note.
> 

My last patch for this, including everything above:
changed: logging will show numbers from VBP rather than hex converted
numbers

so far
Dominik

-- 
The answer to the great question of life,
the universe and everything is 42 (Douglas Adams)
Index: Vb6Task.cs
===================================================================
RCS file: /cvsroot/nantcontrib/NAntContrib/src/Tasks/Vb6Task.cs,v
retrieving revision 1.19
diff -u -w -b -r1.19 Vb6Task.cs
--- Vb6Task.cs  1 Jan 2005 14:04:05 -0000       1.19
+++ Vb6Task.cs  16 Apr 2005 09:45:44 -0000
@@ -325,11 +325,11 @@
         ///             5. Get the TLB filename and returns it
         /// </summary>
         /// <param name="guid">The guid of the tlb to look for</param>
-        /// <param name="major">The major version number of the tlb</param>
-        /// <param name="minor16">The minor version number of the tlb. If you 
parse minor from a string, treat the string as hex value.</param>
+        /// <param name="major">The major version number of the tlb. If you 
parse minor from a string, treat the string as hex value.</param>
+        /// <param name="minor">The minor version number of the tlb. If you 
parse minor from a string, treat the string as hex value.</param>
         /// <param name="lcid">The culture id</param>
         /// <returns>null if couldn't find a match, otherwise it returns the 
file.</returns>
-        private string VB6GetTypeLibFile(Guid guid, ushort major, ushort 
minor16, uint lcid) {
+        private string VB6GetTypeLibFile(Guid guid, ushort major, ushort 
minor, uint lcid) {
             string tlbFile = null;
 
             Microsoft.Win32.RegistryKey regKey;
@@ -341,16 +341,17 @@
                         continue;
 
                     ushort tmpMajor = 0;
-                    ushort tmpMinor16 = 0;
+                    ushort tmpMinor = 0;
                     string [] parts = ver.Split('.');
                     if (parts.Length > 0) {
-                        tmpMajor = (ushort) double.Parse(parts[0], 
CultureInfo.InvariantCulture);
+                        //tmpMajor = (ushort) double.Parse(parts[0], 
CultureInfo.InvariantCulture);
+                        tmpMajor = Convert.ToUInt16(parts[0], 16);  // Treat 
major as hex
                         if (parts.Length > 1) {
-                            tmpMinor16 = Convert.ToUInt16(parts[1], 16);  // 
Treat minor as hex
+                            tmpMinor = Convert.ToUInt16(parts[1], 16);  // 
Treat minor as hex
                         }
                     }       
 
-                    if (major < tmpMajor  || (major == tmpMajor && minor16 <= 
tmpMinor16)) {
+                    if (major < tmpMajor  || (major == tmpMajor && minor <= 
tmpMinor)) {
                         // Found it..
                         Microsoft.Win32.RegistryKey regKeyWin32 = 
regKeyCulture.OpenSubKey("win32");
                         if (regKeyWin32 != null) {
@@ -400,7 +401,7 @@
             Regex codeRegEx = new 
Regex(@"(Class|Module)\s*=\s*\w*;\s*(?<filename>.*($^\.)*)\s*$");
 
             // Regexp that extracts reference entries from the VBP (Reference=)
-            Regex referenceRegEx = new 
Regex(@"(Object|Reference)\s*=\s*({|\*\\G{)(?<tlbguid>[0-9\-A-Fa-f]*($^\.)*)}\#(?<majorver>[0-9($^\.)]*)\.(?<minorver>[0-9a-fA-F($^\.)]*)\#(?<lcid>[0-9]($^\.)*)(;|\#)(?<tlbname>[^\#\n\r]*)");
+            Regex referenceRegEx = new 
Regex(@"(Object|Reference)\s*=\s*({|\*\\G{)(?<tlbguid>[0-9\-A-Fa-f]*($^\.)*)}\#(?<majorver>[0-9a-fA-F($^\.)]*)\.(?<minorver>[0-9a-fA-F($^\.)]*)\#(?<lcid>[0-9]($^\.)*)(;|\#)(?<tlbname>[^\#\n\r]*)");
             
             string key = String.Empty;
             string keyValue = String.Empty;
@@ -440,16 +441,33 @@
                                     //at that location, the typelib ID is used 
to lookup
                                     //the file name
                                             
+                                                                       //the 
version entry in VBP file seems to be different at 
+                                                                       
//objects and references
+                                                                       
//reference (DLL) = Entry is in Hex
+                                                                       
//object (OCX) = Entry is in Dez
+                                                                       //in 
registry the typelib entry is always Hex
+
                                     // # Added to properly cast the parts of 
the version #
                                     // Ensure that we use the correct cast 
option
-                                    string temp = 
match.Groups["majorver"].Value;
-                                    ushort majorVer = (ushort) 
double.Parse(temp, CultureInfo.InvariantCulture);
                                     
-                                    // Minor is considered a hex value
-                                    temp = match.Groups["minorver"].Value;
-                                    ushort minorVer16 = Convert.ToUInt16(temp, 
16);
+                                    string tempMajor = 
match.Groups["majorver"].Value;
+                                    string tempMinor = 
match.Groups["minorver"].Value;
+                                    
+                                    ushort majorVer = 0;
+                                    ushort minorVer = 0;
+                                    
+                                    if (key == "Object" ) {
+                                        // Object (OCX) is considered a dec 
value
+                                        majorVer = (ushort) 
double.Parse(tempMajor, CultureInfo.InvariantCulture);
+                                        minorVer = (ushort) 
double.Parse(tempMinor, CultureInfo.InvariantCulture);
+                                    }
+                                    else {
+                                                                               
// Reference (DLL) is considered a hex value
+                                        majorVer = Convert.ToUInt16(tempMajor, 
16);
+                                        minorVer = Convert.ToUInt16(tempMinor, 
16);
+                                    }
 
-                                    temp = match.Groups["lcid"].Value;
+                                    string temp = match.Groups["lcid"].Value;
                                     uint lcid = 0;
                                     
                                     if ( 0 < temp.Length) {
@@ -459,16 +477,18 @@
                                     string tlbGuid = 
match.Groups["tlbguid"].Value;
                                     Guid guid = new Guid(tlbGuid);
 
+                                    //preserve filename we are looking for
+                                                                       string 
tlbTemp = tlbName;
                                     // Find the tlb file 
-                                    tlbName = VB6GetTypeLibFile(guid, 
majorVer, minorVer16, lcid);
+                                    tlbName = VB6GetTypeLibFile(guid, 
majorVer, minorVer, lcid);
                                     if (File.Exists(tlbName)) {
                                         references.Includes.Add(tlbName);
                                     } else {
                                         // Show a warning if we couldn't find 
the reference. Don't rely on VB.
                                         if (tlbName == null) {
-                                            Log(Level.Warning, "Couldn't find 
the tlb file for '{0}' ver.{1}.{2:x}.", guid, majorVer, minorVer16);
+                                            Log(Level.Warning, "Couldn't find 
the tlb file for '{0}' ver.{1}.{2} {3}", guid, tempMajor, tempMinor, tlbTemp);
                                         } else {
-                                            Log(Level.Warning, "Couldn't find 
the file '{0}'.", tlbName);
+                                            Log(Level.Warning, "Couldn't find 
the file '{0}'.", tlbTemp);
                                         }
                                     }
                                 }

Reply via email to