ShowDialog with a target hwnd - when MyApp exits, so does the target application

Hi,

I am building an application which provides managed 2-factor reauthentication in legacy applications. The idea being that there are certain points in an application where a user ought to be challenged for a password or PIN, and the application do this natively.

Naturally I need the authentication dialog to lock onto the destination application, and prevent the user from clicking behind the dialog. Otherwise, there's no point.

I've got the modal dialog worked out, but when I close my application, the application which the dialog is being attached to closes as well.

For example, if I call this function to lock onto "Untitled - Notepad", the dialog correctly prevents the user from editing the new file but when my application exits, Notepad generates its "save on exit" dialog.

I have tried disposing of the dialog once it's no longer required, to no effect.

Can anyone suggest the reason for this?
Function MyMessageBox(ByVal strMessage As String, _
            ByVal CoBrandingImage As String, _ 
            ByVal Btns As MessageBoxButtons, _ 
            ByVal parenthwnd As IntPtr) As DialogResult 
        Dim frmMsgBx As New Form 
        Dim dlgResponse As DialogResult 
        Dim lblMsgText As New Label 
        Dim btnMsgOK As New Button 
 
<snip> 
 
        dlgResponse = frmMsgBx.ShowDialog(GetWindowFromHost(parenthwnd)) 
        frmMsgBx.Dispose() 
        Return dlgResponse 
    End Function

Open in new window

LVL 5
tstaddonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ladarlingCommented:
How is the other application started? Is the user starting it, or are you starting it from code?
0
tstaddonAuthor Commented:
It's a running application, started by the user. In fact, it can be any application.

I use universal hooks to identify trigger points within a running application so we know when we've hit the screen which mandates a reauthentication attempt.

Once the criteria are detected, I pass the hwnd of the screen  to the GetWindowFromHost function, and in turn use the resulting class to set the window parent for the authentication dialog.

In essence it's comparable to how enterprise SSO works, except we're not doing SSO, we're forcing the person at the keyboard to prove they are the same person who logged into the application.
0
tstaddonAuthor Commented:
Slightly off-topic, but the basis for this application is the "keys to the castle" problem.

If a data system is subject to data protection requirements, or confidentiality requirements, then organisations may need to ensure that nobody else is impersonating the user who logged into the PC at 9 o'clock that morning.

If it's not the same person, the only way you can know if the impersonator is entitled to access that system or not, is if you challenge them for their own credentials.

How many legacy applications enforce user reauthentication out of the box?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

ladarlingCommented:
How many legacy applications enforce user reauthentication out of the box?
I cant think of any, offhand.
But to the original problem, intuition says that the call to dispose the child modal dialog is bubbling up to the parent through the message system, though I am sure that you have already had that idea yourself.
*My* next question would be: is there a way to disentangle the two before disposing of the dialog? Have you tried setting the parent back to a form in your .net application? Or to nothing, perhaps?
0
tstaddonAuthor Commented:
I was thinking along the same lines but I couldn't find any examples of someone doing this with a window created dynamically and then presented through ShowDialog.

If I take the parent window out of the ShowDialog call or I set it to a window other than the destination application, then I lose the app-modal behaviour I want, but I do not get the external application shutdown.

It doesn't appear to be timer related; I can let the destination app run on for half an hour after the presenting the dialog and then disposing it - and the destination application still gets instructed to close when I quit my application.
0
tstaddonAuthor Commented:
Even if I change the owner back to MyApp the same behaviour carries on. With this code, I left myApp for half an hour then closed it and it STILL tried to close the other application.



     dlgResponse = frmMsgBx.ShowDialog(ParentWindow)
     frmMsgBx.Owner = Me
     frmMsgBx.Close()
 
     frmMsgBx.Dispose()

Open in new window

0
tstaddonAuthor Commented:
It's been a while since the last update. I have narrowed this down to the point where I now know what's happening.

The window is not itself being disposed of correctly even though I'm using safe methods. I assume the next step is to destroy the window using API and see what happens.
0
tstaddonAuthor Commented:
Hi,

More digging and I think I'm near a solution - but other projects are taking my attention away from this. I will close this for now, but if anyone wants me to come back with the solution at a later date, I can do.

Thanks all
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.