试试看用Char* 定义API吧,没时间帮你写代码,给个例子给你吧,希望有帮助
private static extern unsafe bool LookupAccountSid(
string sSystemName,System.IntPtr lpSID,
Char* lpAccountName,
ref int iANameSize,
Char* lpDomainName,
ref int iDNameSize,
ref int lpAccountType
);
private static extern unsafe bool LookupAccountSid(
string sSystemName,System.IntPtr lpSID,
Char* lpAccountName,
ref int iANameSize,
Char* lpDomainName,
ref int iDNameSize,
ref int lpAccountType
);
解决方案 »
- 定时关机 C#编写
- C# Dundas chart for winform的图表怎么导入到Excel中?
- 怎么在CS代码中用随机数调用wpf中的image控件~??
- 用sqlserver的客户端 如何用msde、 不用装sqlserver吗 我知道有好心人会进来的
- c#读取串口数据
- 如何调用一个软件中某个dll,使其可以在无此软件的机子上调用?
- 重写了一个 DataGridViewComboBoxColumn和Datagridview,怎样在新的Datagridview添加重写的列,比如添加新列时会出现重新的列
- c#第三方控件 DEV7.2.5中 lookupedit的问题
- 在.net 2.0 如何调用WebService的构造函数中带参数的
- 请教下代码的问题。有些地方我看不懂,哪位高手可以大概说下代码的执行过程吗,谢谢!
- 怎么总是出现这个编译错误?
- listbox问题。
fixed(Char* lpUserBufferPointer = lpUserNameBuffer,lpDomainBufferPointer = lpDomainNameBuffer)
{
if( ConvertStringSidToSid(sSIDString,&pSID))
{
Trace.WriteLine("call ConvertStringSidToSid() to Get SID point successful!");
try
{
fRtn = LookupAccountSid(null,pSID,
lpUserBufferPointer,ref lpUserNameBufferSize,
lpDomainBufferPointer ,ref lpDomainNameBufferSize,ref lpAccountType);
if (fRtn)
{
Trace.WriteLine("call LookupAccountSid() to Get user account info successful!");
try
{
sUserName = new String(lpUserNameBuffer,0,lpUserNameBufferSize);
sDomainName = new String(lpDomainNameBuffer,0,lpDomainNameBufferSize);
iReturnCode = CI_Error_NoError;
}
catch
{
iReturnCode = CI_Error_SystemError;
}
}
else
{
iReturnCode = GetLastError();
Trace.WriteLine("call LookupAccountSid() failed!Last Error code = " + iReturnCode.ToString());
iReturnCode = CI_Error_APIError;
}
}
catch(Exception e)
{
iReturnCode = CI_Error_APIError;
Trace.WriteLine("call LookupAccountSid() Error!Error is " + e.Message);
}
//Free buffer memery
//waiting code
try
{
Trace.WriteLine("Start to free memory!");
LocalFree(pSID);
}
catch(Exception e)
{
Trace.WriteLine("Free memory Error!Error is " + e.Message);
} }
}