Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindWindow from user32.dll

Status
Not open for further replies.

guiding5

Programmer
May 29, 2002
3
IL
I am a newbie with C# :)

As i trying to find handle to window, i imported an external function from user32.dll :

Code:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
It works fine when i send to function both arguments and retreives me a handle, but if i send only a ClassName i dont get a handle !!!

ClassName is enought for FindWindow() to return handle.

It doesnt works when i try :
Code:
IntPtr hWnd = FindWindow("MyClass", string.Empty);
IntPtr hWnd = FindWindow("MyClass", "");
If anybody knows how to solve this problem please help :)
If anybody knows how to get handle of any window in another way i will be greatefull to hear how :)
 
Try creating another FindWindow imported function header. This new one would take a 32-bit integer for the second argument, and you'd call it with a 0 value to pass in a c-style NULL (0x00000000).

What's happening with calling the first style FindWindow is even String.Empty ends up passing a valid (albeit empty) memory address to FindWindow, and it thinks you're looking for a window with no title.

Chip H.
 
Thanks i`ll try ...
You mean like :
Code:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, int nptWindowName);
??
 
Yes, like that. Let me know how well it works.

Chip H.
 
This does works, i used IntPtr for second argument
and called function with IntPtr.Zero

Thanks !!!

:) :) :) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top