Even though this question has already been asked before, the code proposed in the answers didn't get me much further so maybe someone can shed light on this.
I got most of the code from this answered question.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace TestClassLibrary
{
public class ClassTest
{
public ClassTest()
{
}
public static void GetWindowPath(int handle, out string paths) {
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
var explorer = shellWindows.Cast<SHDocVw.InternetExplorer>().Where(hwnd => hwnd.HWND == handle).FirstOrDefault();
if (explorer != null)
{
string path = new Uri(explorer.LocationURL).LocalPath;
Console.WriteLine("name={0}, path={1}", explorer.LocationName, path);
paths = path;
}
else
{
//Console.WriteLine("name={0}, path={1}", explorer.LocationName, path);
paths = "Test";
}
}
Basically what I want to achieve is to have this method return the full path of the window that corresponds to the handle. The method will later on be used externally using the .DLL that this code is compiled into.
The problem I have is that for some reason explorer is always NULL and thus doesn't return a path.
I'd be happy if anyone could shed some light on this, so that I and probably other people who have problems on that matter may know what to do here.