vb variants in c#
-
Can anyone convert the following vb6 code to c#? Dim SW As SHDocVw.ShellWindows Dim IE As SHDocVW.InternetExplorer Set SW = New ShellWindows For Each IE In SW If TypeOf IE.Document Is HTMLDocument Then Debug.Print IE.hWnd End If Next IE The problem lies in the line "For Each IE In SW" since VB supports typeless variables and C# is typed.
-
Can anyone convert the following vb6 code to c#? Dim SW As SHDocVw.ShellWindows Dim IE As SHDocVW.InternetExplorer Set SW = New ShellWindows For Each IE In SW If TypeOf IE.Document Is HTMLDocument Then Debug.Print IE.hWnd End If Next IE The problem lies in the line "For Each IE In SW" since VB supports typeless variables and C# is typed.
I don't know if every object in SW is of type InternetExplorer or not. I assume it is not. Use COM Interop or something like that to get all the SHDocVW objects into the .NET system. Then this should work (not sure about the class names):
ShellWindows SW = new ShellWindows(); InternetExplorer IE; foreach (object o in SW) { IE = o as InternetExplorer; if (IE.Document is HTMLDocument) Debug.WriteLine (IE.hWnd); }
Hope this helps.:)