简体   繁体   中英

C++ MFC - Sharing data between MFC DLL and WTL exe?

I have a MFC project that provides a GUI interface for manipulating a complicated data structure (let's call it ComplicatedClass). I have a WTL project that needs to use this class a lot. I would like to be able to manage only one instance of this class and don't want each project to have its own copy of ComplicatedClass.

If I want these projects to share one instance of this class, how would I go about doing this in a safe and reliable manner? It seems like the only alternative to me is to basically have two copies of the class (one managed by the MFC project and one managed by the WTL side).

You don't need two copies. You don't mention how your application is structured, but I assume the MFC project is an.exe and the WTL one is a dll. Export a function from the dll that takes a ComplicatedClass* and store it for use in your dll. I assume here that ComplicatedClass doesn't have any UI data - ie, no CWnd-derived objects. If it does, you'll need to be careful to wrap your HWND's properly, or stick to win32-only messaging (ie, only use::SendMessage).

This is just general advise, your question isn't specific enough for anything else. For example I don't see why you conclude that you have to have two copies. If you just pass a pointer from one to the other, they can both access them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM