Question

there is a software which calls a method in my C# dll. In this dll method i need to have the window handle of the program/window which called my dll.

how to get this "calling window handle"?

Thanks!

Was it helpful?

Solution

This can return the main window handle.

System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle

As i know there is no way to get a concrete window because it's no more than Form object. But Form class has a property Handle. You can pass it as an argument to dll method calls.

OTHER TIPS

You can't: windows don't call methods, code calls methods.

You should ideally add a window handle parameter to your method. If that's absolutely impossible, you could use, say, the GetActiveWindow API function to get the window active on the current thread. This isn't guaranteed to work; maybe there are no windows open.

What do you need the window handle for?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top