0

Overview:
I have 2 utilities and both have same common interface i.e. open a dialog box to "request for username".
The code for "requesting username" is written in different library and both these utilities call that library .

ISSUE:

In 1 utility it works fine and I got this this dialog box which request username but in other utility it doesn't come up.

MY Investigation: ON deeper investigation I found that both these utilities call CDialog::DoModal() which in turns call onCreate() . In my other utility breakpoint never hits onCreate function . Any idea why ?

sample code

// IN actual Utility
//somewhere in code 

Dialog_for_common_interface dlg( message.c_str(), "Please enter username:" );

        CString username;

        bool is_correct = ( dlg.DoModal(username) == IDOK )

// IN Dialog_for_common_interface

int  Dialog_for_common_interface::DoModal ( CString &_reply_c )
{
    int result_i = CDialog::DoModal(); // break point hits this but value of result_i = -1;

    if ( result_i == IDOK )
    {
        _reply_c = reply_c;
    }

    return result_i;
}

// Breakpoint nver hits the below function

int Dialog_for_common_interface::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

    SetWindowText( title_c );

    return 0;
}
samprat
  • 2,150
  • 8
  • 39
  • 73
  • DoModal returning -1 typically means it could not find the dialog resource. Since libs can not contain a dialog resource it has to be in the calling module and it has to have the same ID in both utilities. – ScottMcP-MVP Jul 11 '14 at 14:00
  • @ScottMcP-MVP, Thanks for suggestion. Couple of doubts. What you mean by could not find dailog resources? Actually the whole code of requesting user name is on different lib and both utilities calls that library. IT works fine for one utility but not for other. Issue is why is it not calling OnCreate function ? I think when it calls onCreate then it wil check for resources right? – samprat Jul 11 '14 at 14:10
  • It will not call OnCreate if the resource is not found. Where is your dialog resource? What is its ID number? Are the answers the same for both utilities? Is there a DLL involved or is it a static library? Your question does not address any of these important details. – ScottMcP-MVP Jul 11 '14 at 14:14
  • THe dialog resource ID is in resource directory of Dialog_for_common_interface. its definetely same for both utilities as I have not made any changes to it. There is no Dll involved. PS: I am bit new to windows programming so there is high chances that i may be doing something silly but before raising question i Hvae checked from my side properly. – samprat Jul 11 '14 at 14:47
  • If Dialog_for_common_interface is a lib project it does not use the resource directory: libs can not contain resources. I suspect you also have the dialog resource in one of your utility projects. – ScottMcP-MVP Jul 11 '14 at 14:58
  • In my actaul project I give the path of that code as header file. When I open Dialog_for_common_interface project I can see resource directory with all static dialog boxes. – samprat Jul 11 '14 at 15:03

1 Answers1

0

Copy the dialog resource into both exe projects. And make sure they both use the same ID value for the dialog resource.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • Dialog_common_interferce has hell lot of files. do you want me to copy all in the same project and add path in header files and compile it ? – samprat Jul 11 '14 at 15:13
  • No, copy the dialog resource. It is just a few lines in an .rc file – ScottMcP-MVP Jul 11 '14 at 15:14
  • U mean just copy Dialog_common_interferce.rc file into my current utility and rebuilt it right ? I def need to mention that file in CMake ? – samprat Jul 11 '14 at 15:25
  • copied .rc file into my utility project and change the cmkae file ane built it again. Got error Er: IDC_EDIT_PROMPT_FOR_STRING cannot find . THis is exactly the DIalog box that I want to open. Then Copied all values from resource.h of common_interface project to my current utility project and eror gone. And it works . I got Dialog box – samprat Jul 11 '14 at 15:46
  • @ Scot , Thanks a lot MAte . SO stil I didnt get what was wrong and how I am gonna fix ? I dont wannt to copy resources into current project. – samprat Jul 11 '14 at 15:48
  • @samprat: What's wrong and how to fix it: Read [TN058: MFC Module State Implementation](http://msdn.microsoft.com/en-us/library/ft1t4bbc.aspx) thoroughly. Also consider learning the Windows API before diving into MFC programming. The latter will not make any sense without intimate familiarity with the former. – IInspectable Jul 11 '14 at 16:07
  • @samprat - The dialog resource has to be in an exe file or a DLL file. Those are the only choices. It can not be in a lib file. You could consider making a DLL project instead of a lib project. – ScottMcP-MVP Jul 11 '14 at 17:38
  • @ScottMcP-MVP, I agree but then how does it work in 1st utility. both utilites called lib but in my case it doesnt work – samprat Jul 11 '14 at 21:36