AFX_MANAGE_STATE(AfxGetStaticModuleState()) 究竟做了什么

2022-01-12 00:00:00 c++ mfc

我使用了很多模态对话框,它们在不使用 AFX_MANAGE_STATE 的情况下运行良好,但最近我正在处理一个不同的项目,其中资源 dll 与启动 dll 不同.我在网上冲浪并发现了上面的行,当我在启动对话框之前插入它时,它起作用了.我想可能是因为我们有不同的 dll,我们需要加载主 dll 的状态才能启动对话框,但我不确定.我无法在互联网上的任何地方找到一个好的解释.谁能简单地解释一下 AFX_MANAGE_STATE 的作用以及为什么我突然不得不使用它.

I have used a lot of modal dialogs and they worked fine without the use of AFX_MANAGE_STATE, but recently I was working on a different project in which the resource dlls are different from the launching dll. I surfed the web and found out the above line and when I inserted it before launching the dialog, it worked. I guess that maybe since we have different dlls, we need to load the state of the main dll in order to launch the dialog, but I am not sure. I have not been able to find a good explanation anywhere on the internet. Could anyone please explain in simple terms what AFX_MANAGE_STATE does and why I suddenly had to use it.

谢谢.

推荐答案

每个 .exe 和 .dll 都有一个内部资源句柄,指向您的对话框和其他资源.如果调用DLL中的函数,当前资源句柄指向的是.exe中的资源,这是错误的,需要改成DLL的资源.

Every .exe and .dll has an internal resource handle, pointing to your dialogs and other resources. If you call a function in your DLL, the current resource handle is pointing to the resources in the .exe, which is wrong and needs to be changed to the resources of the DLL.

这就是 AFX_MANAGE_STATE 所做的.

相关文章