本文介绍了PInvoke翻译不正确/内存损坏错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此获取内存损坏错误:
这是我要翻译为C#的文档:
C ++(msdn) http://msdn.microsoft.com/zh-我们/library/dd877207%28v=vs.85%29.aspx [ ^ ]
Getting a memory corruption error on this:
Here''s the documentation I''m trying to translate to C#:
C++(msdn) http://msdn.microsoft.com/en-us/library/dd877207%28v=vs.85%29.aspx[^]
NET_API_STATUS NetEnumerateComputerNames(
__in_opt LPCWSTR Server,
__in NET_COMPUTER_NAME_TYPE NameType,
__in ULONG Reserved,
__out PDWORD EntryCount,
__out LPWSTR **ComputerNames
);
C#
C#
[DllImport("Netapi32.dll", SetLastError = true)]
public static extern int NetEnumerateComputerNames(
[MarshalAs(UnmanagedType.LPWStr)]
string server_name,
NET_COMPUTER_NAME_TYPE name_type,
ulong reserved,
out int entry_count,
out IntPtr computer_names
);
public static void GetRemoteSystemInformation(string host, ref string computer_name, ref string system_os)
{
computer_name = "";
system_os = "Unknown";
int entry_count;
IntPtr p_computer_names;
var ret = PInvoke.NetEnumerateComputerNames(host, (int)NET_COMPUTER_NAME_TYPE.NET_PRIMARY_COMPUTER_NAME, 0, out entry_count, out p_computer_names);
if (PInvoke.ERROR_SUCCESS == ret)
{
}
}
[edit]代码块,链接链接-OriginalGriff [/edit]
[edit]Code blocks, link linkified - OriginalGriff[/edit]
推荐答案
这篇关于PInvoke翻译不正确/内存损坏错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!