C# 在.net中调用mprapi.dll函数
我试图在c#net中调用本机api。有人能帮我把下面的代码翻译成C#call吗?我真的很感激C# 在.net中调用mprapi.dll函数,c#,.net,unmanaged,C#,.net,Unmanaged,我试图在c#net中调用本机api。有人能帮我把下面的代码翻译成C#call吗?我真的很感激 dwResult = ::MprAdminMIBServerConnect( pwcComputerName.GetText(), &hMibServer ); dwResult = ::MprAdminServerGetInfo( hMibServer, 0, (LPBYTE*)&pServerBuf ); // I want to read the below variables
dwResult = ::MprAdminMIBServerConnect( pwcComputerName.GetText(), &hMibServer );
dwResult = ::MprAdminServerGetInfo( hMibServer, 0, (LPBYTE*)&pServerBuf );
// I want to read the below variables as string
pInObjectEntry->Put(L"rastotalportstoconnectto", pServerBuf->dwTotalPorts );
pInObjectEntry->Put(L"rasportsinuse", pServerBuf->dwPortsInUse );
这是示例代码,有人能告诉我如何读取dwTotalPorts和DWPortSinsuse的值吗
class RASCollector
{
[DllImport("mprapi.dll", SetLastError = false)]
public static extern UInt32 MprAdminMIBServerConnect([MarshalAs(UnmanagedType.LPWStr)] string lpwsServerName, out IntPtr phMibServer);
[DllImport("mprapi.dll", SetLastError = false)]
public static extern UInt32 MprAdminServerGetInfo(IntPtr phMprServer, UInt32 dwLevel, out byte[] pServerBuf);
public void Run()
{
IntPtr hMibServer = new IntPtr();
UInt32 result;
result = MprAdminMIBServerConnect("localhost", out hMibServer);
byte[] pServerBuf;
result = MprAdminServerGetInfo(hMibServer, 0, out pServerBuf);
}
}
这是通过使用互操作来完成的。 您需要像这样导入每个函数:
using System.Runtime.InteropServices;
[DllImport("mprapi.dll", SetLastError = false)]
public static extern UInt32 MprAdminMIBServerConnect([MarshalAs(UnmanagedType.LPWStr)] string lpwsServerName, out IntPtr phMibServer);
MSDN库中定义的数据类型应转换为对应的C#数据类型。您应该查看本文以了解更多信息:
有关在C#中编组复杂数据结构和指针的详细信息,请参阅:
其他功能呢。看起来还好吗<代码>[DllImport(“mprapi.dll”,SetLastError=false)]公共静态外部UInt32 MprAdminServerGetInfo(IntPtr phMprServer,UInt32 dwLevel,out字节[]pServerBuf)代码>