我正在尝试在 c# .net 中调用本机 api。谁能帮我将下面的代码翻译成 C# 调用?我会很感激的。
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 和 dwPortsInUse 的值?
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);
}
}