0

Let me first say that I do not want a copy of a resource file on two projects (I have seen a question about that).

Using Windows 7, MS VS 2013, C++, MFC.

These two projects I will be referencing are part of the same solution.

I have a dialog that has been created with rc/h/cpp files for it that works in one project (Project A). I want to be able to open that dialog from a routine in a separate project (Project B). Project B has a GUI button that when clicked I wish for the dialog from Project A to be brought up.

I have included a reference to Project A in the properties of Project B.

I have included (#include) the rc file path for Project A in the rc file for Project B (which takes care of the resource file, and the definition numbers for the resource file do not overlap).

I have included the path (From Project A) to the class that controls the dialog in Project B (in the file that contains the event handler to bring up the dialog).

There are no errors with the setup I have, it just doesn't do anything. I create the dialog and try a DoModal on it like I would anywhere in Project A (where it works) and nothing happens, I can click the button many times and it never brings anything up.

I cannot provide any of the code on this, but I hope that is enough information to give me some kind of clue. I am lost as of now. Thank you.

Ex of routine:

#include "DialogIWant.h"

...

void OnPushButtonOnProjectB ()
{
    CDialogIWant dialog;  // CPP/H/RC in the other project A
    dialog.DoModal();  // Nothing comes up
}
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77
Clay
  • 1
  • 1
  • Project A and Project B are not automatically linked to each other. I am not sure if I follow but the way you are describing things project B should not even build successfully. If you have multiple projects in the same solution then right-click on project B, click on "*Set as startup project*" in popup menu. Put a break point on `dialog.DoModal()` and run with debugger. – Barmak Shemirani Sep 29 '15 at 23:13
  • Yes the Project B is the startup project, I neglected to say that. The problem is the dialog itself is null when I create it, I don't think the DoModal part is really the issue. I don't think I can even create any instance of the CDialogIWant class even though it is referenced through an #include. I basically want to know if it is possible to use a single dialog from one project in different projects and if so how do I do it. Thanks. – Clay Sep 29 '15 at 23:34
  • Is the resource actually contained withing the Project B binary, or only in Project A? It won't be able to load the dialog if it can't locate the resource for it. You can also try putting a breakpoint after the DoModal call to see what the return value is. -1 means it couldn't create the dialog, IDABORT will display error information from GetLastError in the output window. – 1201ProgramAlarm Sep 30 '15 at 01:14

1 Answers1

0

Resource files are able to use #inclde the same as any other C++ file. Have the dialog resource in a separate file, and include it in the .rc files of both projects.

You will also need to share the resource ID definitions, which are usually in resource.h.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622