In Windows, I want to grab a FileOpenDialog that already exists in another process, as a child of another application and force it to navigate to a specific folder. I have hope that COM interop can help accomplish this. As I'm doing some research, I'm trying to first just open a new dialog using COM, but I'm stuck at a point. I can get an IntPtr to a dialog instance and an IntPtr to its interface that has the method I want to call, but I don't know the proper technique to call it. Here's my code:
static void Main(string[] args)
{
// the implementation COM object: FileOpenDialog
var classId = new Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7");
var fileOpenDialogType = Type.GetTypeFromCLSID(classId, true);
var fileOpenDialog = Activator.CreateInstance(fileOpenDialogType);
IntPtr pUnknown = Marshal.GetIUnknownForObject(fileOpenDialog);
// the COM interface: IFileOpenDialog
var interfaceId = new Guid("d57c7288-d4ad-4768-be02-9d969532d960");
var result = Marshal.QueryInterface(pUnknown, ref interfaceId, out IntPtr pIFileOpenDialog);
// at this point:
// result = 0
// pIFileOpenDialog = some non-zero value (for a memory address, I assume)
// But how can I invoke the "Show" method of the dialog? Something like this:
//Invoke("Show", pIFileOpenDialog);
Marshal.Release(pUnknown);
Marshal.Release(pIFileOpenDialog);
}