MFC winsock1 和 2

发布于 2024-09-19 13:15:29 字数 254 浏览 6 评论 0原文

我的项目深陷麻烦。

我必须将两个雷达与我的程序链接,但第一个雷达有自己的使用winsock的库,而第二个雷达我想使用winsock2。

我怎样才能做到这一点?

目前,我从 winsock.hwinsock2.h 中的包含中收到许多重新定义错误。

考虑到第一个雷达库已经是一个 DLL,我只有一个头文件和 lib 文件(没有源代码)。

预先感谢您的任何答复。

I'm deep in trouble with my project.

I have to link two radar with my program, but the first has its own library that uses winsock, while in the second I want to use winsock2.

How can i do that?

At the moment i get many redefinition errors from the includes within winsock.h and winsock2.h.

Take into account that the first radar library is already an DLL, i've got only a header and lib file (no source).

Thank you in advance for any answer.

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

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

发布评论

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

评论(1

红衣飘飘貌似仙 2024-09-26 13:15:29

您可以通过构造代码(和预编译头)来解决编译问题,以便没有文件同时包含winsock.h和winsock2.h,这可能意味着根本不使用预编译头或以比更复杂的方式使用它们在 MFC 项目中是正常的...

您可以将每个 DLL 包装在 COM 对象中,并从主程序通过 COM 访问它们。这样做的优点是可以将两个 DLL 的使用与主编译完全分开。

您可以将每个 DLL 包装在一个新的 DLL 中(每个 DLL 一个),该 DLL 为您的程序提供一个接口,该程序不需要接口标头中的 winsock 标头。

当然,这可能只是您的 Windows.h 包含顺序的问题,请尝试将其放在预编译头的顶部...

#ifndef _WINDOWS_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif

#include <winsock2.h>

You could possibly work around the compilation problem by structuring your code (and precompiled headers) so that no file includes both winsock.h and winsock2.h, this may mean either not using precompiled headers at all or using them in a more complex way than is normal in MFC projects...

You could wrap each DLL in a COM object and access them via COM from your main program. This has the advantage of completely separating the use of the two DLLs from your main compilation.

You could wrap each of the DLLs in a new DLL (one each) which provides an interface to your program that does not need the winsock headers in the interface headers.

Of course this may simply be an issue with your Windows.h include order, try putting this at the top of your precompiled header...

#ifndef _WINDOWS_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif

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