Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在.net中调用mprapi.dll函数_C#_.net_Unmanaged - Fatal编程技术网

C# 在.net中调用mprapi.dll函数

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

我试图在c#net中调用本机api。有人能帮我把下面的代码翻译成C#call吗?我真的很感激

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)