I am writing a dll library (for example for checking login details of a user) and I want to pop up a confirmation dialog or a informational dialog in the process, for example
You really shouldn't. This does not belong in a library, but should be done in the application that uses this library instead.
Where a WinForms application might solve it by showing a MessageBox
, a web application might perform the request without asking after a successful POST (since a POST usually shows the intent to modify a resource).
When for example your library is used for logging in, simply throw a AuthenticationException
, so the client application (whether it's WinForms, web, or whatever) can catch that and display the appropriate message.
As for your edit:
I have a dll for creating database at runtime of an application ...
Why not expose two methods like IsDatabaseUpToDate()
and UpdateDatabase()
? Then in the client, you can call the first method. If it returns false, you ask the user (be it with a MessageBox, an HTML form, a JavaScript Alert, a simple Yes button or a blinking tile) whether they want to update the database. If so, you call the UpdateDatabase()
method and you're ready to go.
To accomplish this you need to right click on the project and select "Add Reference", then select the ".NET" tab and click "System.Windows.Forms". Then this should work inside the .dll:
System.Windows.Forms.MessageBox.Show("Hello World!");
Of course this is a bad idea for the original poster (as covered by CodeCaster).