Access denied when using DestroyWindow( hWnd)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing a Windows Forms application using VS.NET and C#. Upon user request I launch a Help Viewer as defined by a CHM file. The viewer window appears as expected. Upon some other user action I want to close (destroy) the viewer window. I am using the SDK functions [user32.dll] FindWindow() and DestroyWindow() to get the window handle and then destroy the window

However, the DestroyWindow() function returns a result of zero (not successful), so I then make a call to [kernel32.dll] GetLastError(). It returns the value 5, which is the error ERROR_ACCESS_DENIED

Why is the application that created a window not allowed to destroy it
What do I need to do to allow my application to destroy the window

Thanks
Dav
 
Hi Dave,

I'm not clear how you launch the Help Viewer window, maybe it's created on
another UI thread and the doc of DestroyWindow states:

A thread cannot use DestroyWindow to destroy a window created by a
different thread.

In this situation, I suggest you try posting WM_CLOSE message to the Help
Viewer window instead.

Does it resolve your problem?

If you still have problem on this issue, please let me know more about your
proglem (e.g. how you launch the helpview window?)

Thanks!
Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Ying-Shen

You were correct that the application was starting the viewer in another thread. I used the SendMessage() call with the WM_CLOSE message to synchronously close the viewer window. This worked well

Thanks
Dav

----- "Ying-Shen Yu[MSFT]" wrote: ----

Hi Dave

I'm not clear how you launch the Help Viewer window, maybe it's created on
another UI thread and the doc of DestroyWindow states

A thread cannot use DestroyWindow to destroy a window created by a
different thread.

In this situation, I suggest you try posting WM_CLOSE message to the Help
Viewer window instead

Does it resolve your problem

If you still have problem on this issue, please let me know more about your
proglem (e.g. how you launch the helpview window?

Thanks
Best regards,

Ying-Shen Yu [MSFT
Microsoft Community Suppor
Get Secure! - www.microsoft.com/securit

This posting is provided "AS IS" with no warranties and confers no rights
This mail should not be replied directly, please remove the word "online"
before sending mail
 
Back
Top