我将设计一个使用 WinDivert 来操纵网络流量的程序。我使用的语言是 C++,程序是在 Visual Studio 2008 下设计的。首先我在 Visual C++ CLR(Windows 窗体应用程序)中创建了一个项目,这样我就可以简单地实现 UI。
为了导入 WinDirvert 库,我在项目属性中做了如下设置:
- 配置属性:通用
公共语言运行时支持:公共语言运行时支持(/ctr) - 配置属性:链接器
附加依赖项:WinDivert.lib
模块定义文件的链接:windivert.def 的链接
在我创建的项目中,我还在头文件中添加了 windivert.h。
此外,windivert.h 包含在我的项目 (ProjectG.cpp) 的主入口点中:
#include "stdafx.h"
#include "Form1.h"
#pragma managed(push, off)
#include "windivert.h"
#pragma managed(pop)
using namespace ProjectG;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
HANDLE handle;
unsigned char packet[8192];
UINT packet_len;
WINDIVERT_ADDRESS addr;
handle = WinDivertOpen("udp", WINDIVERT_LAYER_NETWORK, 0,
WINDIVERT_FLAG_DROP);
if (handle == INVALID_HANDLE_VALUE)
{
Application::Exit();
}
while (TRUE)
{
// Read a matching packet.
if (!WinDivertRecv(handle, packet, sizeof(packet), &addr, &packet_len))
{
MessageBox::Show("Fail");
continue;
}
}
return 0;
}
最后我把{WinDivert.dll, windivert.h, WinDivert.lib, WinDivert32.sys}放到了项目目录下。
但是,显示以下错误:
fatal error LNK1306: DLL entry point "int __clrcall main(cli::array<class
System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z) cannot be managed;
compile to native ProjectG.obj ProjectG
附加:(警告)
warning LNK4070: /OUT:WinDivert.dll directive in .EXP differs from output filename
'C:\Users\David\Desktop\css\ProjectG\Debug\ProjectG.exe'; ignoring directive
ProjectG.exp ProjectG
问题:我该如何解决这种情况?