0

I have to create a simple prompt within a native C DLL. I've never had to create windows in C, so I don't know what possibilities exist.

The Window should contain a textbox and a button. I should be able to get the value of that textbox when the user presses the button. When shown, the window should not interrupt the program flow, it should be modeless. I have to be able to close the window from the code within the DLL.

I was thinking of using MFC until I realised that it was for C++. So I thought I could write a wrapper and then use it like that, but one obviously has to restructre some parts of the project so that it would work (like changing the entry points). I'm a bit confused as how to use any "GUI-Frameworks", but if there's an easy solution that would be great.

The solution should be as simple as possible.

EDIT:

What the DLL is used for...

We have an Application suite (I'll just call this the IDE) that uses the SCC interface. We have a SVN repository, so we use PushOk to translate the queries from the IDE to SVN commands. PushOk's and the IDE's definition of the SCC interface are not always consistent so the IDE would crash with certain operations. As we do not own the sourcecode to PushOk we wrote our own proxy dll which fixed the specific issues we were having.

Now, PushOk doesn't have an option to get a file whilst specifing the revision (it does but it doesn't work in our case). So we have to implement it our selves. The window aformentioned would be the window where one could enter a revision and then we'd get that file with that revision.

SanBen
  • 2,581
  • 26
  • 35
  • 1
    A DLL should probably never show a user interface. Why not create a standard application instead? – Cody Gray - on strike Jan 12 '12 at 10:09
  • Under the circumstances it would be best if the DLL implemented the window. I could however create a seperate application and then call that from the DLL, although i'd prefer a different solution. – SanBen Jan 12 '12 at 10:16
  • More information on your "circumstances" would be helpful then. I can't imagine such circumstances where a DLL should ever show a UI. – Cody Gray - on strike Jan 12 '12 at 10:31
  • You should not use a GUI-Framework from a DLL, that's a recipe for disaster. Stick to the plain win32 api (`CreateDialog()` and friends and all should be well). – rodrigo Jan 12 '12 at 11:05
  • @CodyGray: I noted the "circumstances" in the question – SanBen Jan 12 '12 at 11:37
  • @rodrigo: thank you, it seems as though that's precisely what I was looking for. I didn't know that function before. I don't ususally work directly with the win apis. Maybe you should post it as an answer so I can accept it. – SanBen Jan 12 '12 at 11:41

1 Answers1

2

You should not use a GUI-Framework from a DLL, that's a recipe for disaster. Stick to the plain win32 api (CreateDialog() and friends and all should be well).

(That phrase is copied from the comment, so I'll elaborate).

This function is actually quit easy to use:

  • First you need a DIALOG resource compiled into your DLL. The VisualStudio integrated resource editor will be handy here.

  • Then write a DLGPROC function

.

BOOL CALLBACK MyDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
        case WM_INITDIALOG:
           /* ... */
        default:
            return FALSE;
    }
}
  • And in your exported function just call, and save the handle for later:

.

 HWND hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(ID_MY_DIALOG), NULL);
  • If you want to destroy the dialog, just call:

.

DestroyWindow(hWnd);

Find all you want to know about Win32 dialogs (and more) here.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • I just read one is supposed to use EndDialog() instead of destroyWindow() when dealing with dialogs. – SanBen Jan 13 '12 at 15:29
  • 1
    @R34lthing `EndDialog()` is for modal dialogs, that are ran with `DialogBox()` or similar, because it handles the breaking of the local message loop. If your dialog is modeless then it should be destroyed with `DestroyWindow()` as an ordinary window. Find all you want to know about Win32 dialogs (and more) [here](http://msdn.microsoft.com/en-us/library/windows/desktop/ms632588(v=VS.85).aspx) – rodrigo Jan 13 '12 at 17:21