Like Tree1Likes
  • 1 Post By fmuir

Dialog Boxes from DLL Fail to Open

This is a discussion on Dialog Boxes from DLL Fail to Open within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have created a DLL containing two functions that attempt to invoke dialog boxes. However, when executing the program ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    11

    Dialog Boxes from DLL Fail to Open

    Hello,
    I have created a DLL containing two functions that attempt to invoke dialog boxes. However, when executing the program that
    calls the functions I see that the MessageBox, that's defined in one of the functions, is displayed, but neither of the dialog boxes open. It appears that I am not using the correct handle when calling these functions. Does anyone have a suggestion about how I can get the correct handle. Neither setting the handle to NULL, nor using GetModuleHandle() (to get the address of either the DLL or the Executable) works. The returned handle is always NULL. The two dialog boxes can be displayed through a different WIN32 application The two functions inside the DLL are:
    Code:
    // Modeless Dialog
    extern "C"
    {
    TS104_API INT TS104_S1(VOID)
    {
    hWndParent = NULL;
    hDlg = CreateDialog( GetModuleHandle(reinterpret_cast<LPCWSTR>("TS104.exe")),
    MAKEINTRESOURCE(IDD_DIALOG2), hWndParent, (DLGPROC)GoTo1Proc ); 
    if(hDlg != NULL)
    {
     ShowWindow( hDlg, SW_SHOW );
    }
    else
    {
     MessageBox( NULL, L"CreateDialog returned NULL", L"Warning!",
       MB_OK | MB_ICONINFORMATION );
    }
    return TRUE;
    }
    } 
    // Modal Dialog
    extern "C"
    {
    TS104_API INT TS104_S2( CHAR* Symbol, INT& Iarr, CONST INT Index )
    {
    hWndParent = NULL;
    HINSTANCE hInstance = 0;
    DialogBox( GetModuleHandle(reinterpret_cast<LPCWSTR>("TS104.exe")),
    MAKEINTRESOURCE(IDD_DIALOG1), hWndParent, (DLGPROC)GoTo2Proc ); 
    return TRUE;
    }
    }
    Regards,
    -Frank

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > hDlg = CreateDialog( GetModuleHandle(reinterpret_cast<LPCWSTR>("TS104.e xe")),
    I would suggest you look up how to create UNICODE strings, rather than trying to hammer the square peg into the round hole.

    Just pretending you have a pointer to a UNICODE string doesn't make the actual string a UNICODE string.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    11
    Quote Originally Posted by Salem View Post
    Just pretending you have a pointer to a UNICODE string doesn't make the actual string a UNICODE string.
    @ Salem,

    Thanks for the suggestion. I'll look at UNICODE strings tomorrow! I am assuming that GetModuleHandle() is the function to use. We'll see what happens later!

    Regards,
    -Frank

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    11
    @ Salem,

    Trashed the casts and changed the lines of code to 'hInstance = GetModuleHandle(L"TS104.dll");,' re-compiled and the dialogs opened. Your suggestion was right on. You also piqued my interest in learning more about UNICODE. Thanks!!

    Regards,
    -Frank
    Salem likes this.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    For compatibility ANSI - UNICODE:

    #include <tchar.h>
    ...
    hInstance = GetModuleHandle(_T("TS104.dll"));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialog Boxes
    By relyt_123 in forum Windows Programming
    Replies: 14
    Last Post: 06-24-2007, 12:17 AM
  2. Two quick questions about open file dialog boxes
    By PJYelton in forum Windows Programming
    Replies: 5
    Last Post: 04-05-2005, 08:49 AM
  3. Command to open the 'Open Dialog Box' found in most programs.
    By OmegaFirebolt in forum Windows Programming
    Replies: 5
    Last Post: 03-16-2003, 07:58 PM
  4. Dialog Boxes
    By frenchfry164 in forum Windows Programming
    Replies: 1
    Last Post: 02-17-2002, 08:43 PM
  5. Dialog Boxes
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 01-03-2002, 10:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21