我有一个 c++/CLI 项目,它给了我奇怪的错误:
Severity Code Description Project File Line Suppression State
Error LNK2022 metadata operation failed (801311D7) : Walter.Net.IDS.WFP C:\Users\Administrator\source\Workspaces\IDPS\vesnx\Walter.Net.IDS.WFP\PacketInspector.obj 1
和:
Severity Code Description Project File Line Suppression State
Error LNK1255 link failed because of metadata errors Walter.Net.IDS.WFP C:\Users\Administrator\source\Workspaces\IDPS\vesnx\Walter.Net.IDS.WFP\LINK 1
然后我有 24 个与在 Visual Studio 2022 生成的文件中找不到 mscorlib 相关的问题。
我认为问题出在我的私人领域:cliext::vector
// ***********************************************************************
// Assembly : Walter.Net.IDS.WFP
// Author : W2307
// Created : 02-10-2023
//
// Last Modified By : W2307
// Last Modified On : 04-10-2023
// ***********************************************************************
// <copyright file="PacketInspector.h" company="VESNX SA">
// Walter Verhoeven, Lambert Snellinx
// </copyright>
// <summary>
// Adapter pattern over WFP framework that will allow the post-processing of
// packages send and received by
// </summary>
// ***********************************************************************
#pragma once
#include <cliext/vector> // For CLI vector
#include "WfpEventArgs.h" // Include the header for WfpEventArgs
#include "FilterInfo.h"
#include "LoggerHelper.h"
using namespace System;
using namespace System::Collections::ObjectModel; // For ReadOnlyCollection
//using namespace Microsoft::Extensions::Logging;
namespace Walter {
namespace Net {
namespace IDS {
namespace WFP {
public ref class PacketInspector sealed {
public:
// Define the delegate (if using non-standard C++ syntax)
delegate void WfpEventHandler(Object^ sender, WfpEventArgs^ e);
// Declare the event using the delegate see OnPacketReceived
event WfpEventHandler^ WfpEvent;
/// <summary>
/// create the package inspector class for monitoring communications from remote ip
/// addresses as well as local ip addresses and ports.
/// </summary>
/// <param name="logger">pass logger to the packet inspector to instrument the code execution</param>
//PacketInspector(ILogger^ logger);
PacketInspector();
/// <summary>
/// free resources
/// </summary>
~PacketInspector();
/// <summary>
/// capture local ip address and port data
/// </summary>
/// <param name="ipAddress">Local IP address to monitor</param>
/// <param name="port">Port to filter on</param>
/// <returns>True if filter and callout are active</returns>
bool StartCaptureIp(String^ ipAddress, int port); // Starts capturing packets
/// <summary>
/// Capture remote ip address interaction
/// </summary>
/// <param name="ipAddress">Remote IP address to monitor</param>
/// <returns>True if filter and callout are active</returns>
bool StartCapture(String^ ipAddress); // Starts capturing packets
/// <summary>
/// stops processing the remote IP address
/// </summary>
/// <param name="ipAddress">the remote ip address</param>
/// <returns>true if processing was successful terminated</returns>
bool StopCapture(String^ ipAddress); // Stops capturing packets
/// <summary>
/// stops processing the local ip address and port
/// </summary>
/// <param name="ipAddress">the local ip address</param>
/// <param name="port">the local port</param>
/// <returns>true if processing was successful terminated</returns>
bool StopCaptureIp(String^ ipAddress, int port); // Starts capturing packets
/// <summary>
/// get the filters we detected to be active on the packet inspector registered ip addresses
/// </summary>
property ReadOnlyCollection<FilterInfo^>^ Filters {
ReadOnlyCollection<FilterInfo^>^ get();
}
protected:
/// <summary>
/// Triggers the delegate
/// </summary>
/// <param name="e">the event</param>
void OnPacketReceived(WfpEventArgs^ e) {
//todo, do not call it directly but enqueue this in a buffer the processing thread will/ should dequeue it ensuring non-blocking interaction
WfpEvent(this, e);
}
private:
/// <summary>
/// test if the IP address is valid
/// </summary>
/// <param name="ipAddress">the string we assume is a ip address</param>
/// <returns>true if a ip address</returns>
bool IsValidIP(String^ ipAddress);
/// <summary>
/// contains the filters
/// </summary>
cliext::vector<FilterInfo^>^ _filterList;
LoggerHelper^ _logger;
};
}
}
}
}
大家有什么建议吗?
这很可能是 CLI 和模板的另一个问题。 我怀疑您对代码中的向量<..>的怀疑是正确的。如果我们的怀疑是正确的,我可以想出两种方法:
template ref class cliext::vector<FilterInfo^>;
的内容。您可能也需要对其他模板类型执行此操作。