I'm working on refactoring a 5.5k-line C++ DLL, splitting it into a number of smaller DLLs. Unfortunately, a lot of the code is tied together, and in the process of splitting the GiantDLL I introduced a couple of circular references.
More specifically,
//In emergeOSLib.h:
DLL_EXPORT std::wstring ELGetProcessIDApp(DWORD processID, bool fullName);
//In a couple of functions in emergeOSLib.cpp:
ELMessageBox(GetDesktopWindow(), messageText, (WCHAR*)TEXT("Emerge Desktop"), ELMB_OK|ELMB_ICONERROR|ELMB_MODAL);
//In emergeUtilityLib.h:
DLL_EXPORT int ELMessageBox(HWND hwnd, std::wstring messageText, std::wstring messageTitle, DWORD msgFlags);
//In a function in emergeUtilityLib.cpp:
out << ELGetProcessIDApp(GetCurrentProcessId(), false) << TEXT(": ") << debugText << std::endl;
And voila, one circular reference. I'm pretty sure there are more, this is just the one I'm dealing with right now.
I've done some research and found that forward declarations seem to be the way to go:
Resolve header include circular dependencies
Circular Dependency in C++
The second link even suggests forward declarations are preferable to #include
s.
I have two questions at this point. First, how do I go about forward-declaring a function that's in another DLL? My understanding is that the compiler still won't be able to find the forward-declared function (since it's not compiling the second DLL as part of the first) and will complain. Second, which is generally considered better practice, #include
statements or forward declarations?