使用 /clr 编译 MFC 应用程序(步骤 1:链接动态 DLL)

发布于 2024-07-22 18:04:55 字数 1566 浏览 7 评论 0原文

我已成功将使用旧版本 Developer Studio 编译的 MFC 应用程序升级到 Visual Studio 2008。由于 MFC 中存在一些重大更改,因此需要进行极少量的更改。 现在一切正常,我想采取下一步并使用 /clr 编译解决方案。

为此,我在 MSDN 网站上找到了有用的信息:

以下是我采取的步骤:

  1. 运行时库设置为多线程调试 DLL (/MDd)
  2. 使用 MFC 设置为在共享 DLL 中使用 MFC

但是,这样做会阻止我链接该项目:

  1. 无法再解析对 afxData 的引用; 不知何故,afxData 仅在静态链接到 MFC 时才可见。 在我的代码中,我有以下声明:

    extern AFX_DATA AUX_DATA afxData;

    它适用于静态链接的 MFC 版本。

  2. _afxThreadState_afxWinState 的引用也无法解析。

以下是完整的错误消息:

error LNK2001: unresolved external symbol "struct AUX_DATA afxData" (?afxData@@3UAUX_DATA@@A)
error LNK2001: unresolved external symbol "class CThreadLocal<class _AFX_THREAD_STATE> _afxThreadState" (?_afxThreadState@@3V?$CThreadLocal@V_AFX_THREAD_STATE@@@@A)
error LNK2001: unresolved external symbol "class CProcessLocal<class _AFX_WIN_STATE> _afxWinState" (?_afxWinState@@3V?$CProcessLocal@V_AFX_WIN_STATE@@@@A)

以防万一这可能与名称修改有关...

那么,我该怎么做才能动态链接到 MFC,但仍然引用 afxData_afxThreadState_afxWinState

I have successfully upgraded an MFC application which was compiled with an old version of Developer Studio to Visual Studio 2008. A very small number of changes were needed because of some breaking changes in MFC. Now that everything works, I'd like to take the next step and compile the solution with /clr.

To do so, I have found useful information on the MSDN web site:

Here are the steps I have taken:

  1. Set the Runtime Library to Multi-threaded Debug DLL (/MDd).
  2. Set the Use of MFC to Use MFC in a Shared DLL.

However, doing so prevents me from linking the project:

  1. The reference to afxData can no longer be resolved; somehow, afxData is only visible when linking statically against MFC. In my code, I have the following declaration:

    extern AFX_DATA AUX_DATA afxData;

    which works fine with the statically linked MFC version.

  2. The references to _afxThreadState and _afxWinState cannot be resolved either.

Here are the full error messages :

error LNK2001: unresolved external symbol "struct AUX_DATA afxData" (?afxData@@3UAUX_DATA@@A)
error LNK2001: unresolved external symbol "class CThreadLocal<class _AFX_THREAD_STATE> _afxThreadState" (?_afxThreadState@@3V?$CThreadLocal@V_AFX_THREAD_STATE@@@@A)
error LNK2001: unresolved external symbol "class CProcessLocal<class _AFX_WIN_STATE> _afxWinState" (?_afxWinState@@3V?$CProcessLocal@V_AFX_WIN_STATE@@@@A)

in case this might be related to the name mangling...

So, what can I do in order to dynamically link against MFC, but still reference afxData, _afxThreadState and _afxWinState?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她说她爱他 2024-07-29 18:04:55

在共享 DLL 中使用 MFC 时,必须dllimport导入 AUX_DATA。

extern __declspec(dllimport) AUX_DATA afxData

对于线程状态,不要使用模板类,而是使用其中之一,

AFX_MODULE_THREAD_STATE* pState = _AFX_CMDTARGET_GETSTATE()->m_thread;
AFX_THREAD_STATE* pState = AfxGetThreadState(); 

具体取决于您需要的状态信息。 例如,请参阅此处了解某些成员已移至模块状态以修复错误。 请注意,AfxGetModuleThreadState 存在,但未记录,可能会在未来版本中更改。

Win状态下不响铃,怎么用? 可能有一种新方法可以实现这一目标。

When using MFC in a shared DLL, AUX_DATA must be dllimported.

extern __declspec(dllimport) AUX_DATA afxData

For thread state, rather than using template classes, use one of these

AFX_MODULE_THREAD_STATE* pState = _AFX_CMDTARGET_GETSTATE()->m_thread;
AFX_THREAD_STATE* pState = AfxGetThreadState(); 

Depending on the state information you require. For example, see here for some members that were moved to module state to fix a bug. Note that AfxGetModuleThreadState exists but is undocumented and could be changed in a future version.

Win state does not ring a bell, how is it used? There is probably a new way to accomplish it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文