- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在调用 Windows API DsRoleGetPrimaryDomainInformation,如下面的代码块所示。我想要获取域林名称和域 DNS 名称。当我对域名 DNS 名称执行 ShowMessage
时,它只显示“????”对于域林名称,它显示 EmptyString。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = (
DsRolePrimaryDomainInfoBasic,
DsRoleUpgradeStatus,
DsRoleOperationState);
DSROLE_MACHINE_ROLE = (
DsRole_RoleStandaloneWorkstation,
DsRole_RoleMemberWorkstation,
DsRole_RoleStandaloneServer,
DsRole_RoleMemberServer,
DsRole_RoleBackupDomainController,
DsRole_RolePrimaryDomainController);
PDSROLE_PRIMARY_DOMAIN_INFO_BASIC = ^DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
DSROLE_PRIMARY_DOMAIN_INFO_BASIC = record
MachineRole: DSROLE_MACHINE_ROLE;
Flags: ULONG;
DomainNameFlat: LPWSTR;
DomainNameDns: LPWSTR;
DomainForestName: LPWSTR;
DomainGuid: TGUID;
end;
function DsRoleGetPrimaryDomainInformation(lpServer: LPCWSTR;
InfoLevel: DSROLE_PRIMARY_DOMAIN_INFO_LEVEL; var Buffer: DSROLE_PRIMARY_DOMAIN_INFO_BASIC): DWORD; stdcall; external 'netapi32.dll';
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
pBuffer : DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
begin
if not DsRoleGetPrimaryDomainInformation(nil,DsRolePrimaryDomainInfoBasic,pBuffer) = ERROR_SUCCESS then
begin
ShowMessage('Something is wrong!');
exit;
end;
ShowMessage(pBuffer.DomainNameDns );
ShowMessage(pBuffer.DomainForestName);
end;
end.
最佳答案
根据文档,缓冲区不是一个输出参数,而是一个指针。
所以
function DsRoleGetPrimaryDomainInformation(lpServer: LPCWSTR;
InfoLevel: DSROLE_PRIMARY_DOMAIN_INFO_LEVEL; var Buffer: DSROLE_PRIMARY_DOMAIN_INFO_BASIC): DWORD; stdcall; external 'netapi32.dll';
需要改为
function DsRoleGetPrimaryDomainInformation(lpServer: LPCWSTR;
InfoLevel: DSROLE_PRIMARY_DOMAIN_INFO_LEVEL; Buffer: pDSROLE_PRIMARY_DOMAIN_INFO_BASIC): DWORD; stdcall; external 'netapi32.dll';
这是一个具有完整实现的单元。刚刚在 Delphi 6 中测试:
unit DSRole;
{$WEAKPACKAGEUNIT}
{$HPPEMIT ''}
{$HPPEMIT '#include "dsrole.h"'}
{$HPPEMIT ''}
interface
uses
Windows;
//
// Domain information
//
type
_DSROLE_MACHINE_ROLE = (
DsRole_RoleStandaloneWorkstation,
DsRole_RoleMemberWorkstation,
DsRole_RoleStandaloneServer,
DsRole_RoleMemberServer,
DsRole_RoleBackupDomainController,
DsRole_RolePrimaryDomainController);
{$EXTERNALSYM _DSROLE_MACHINE_ROLE}
DSROLE_MACHINE_ROLE = _DSROLE_MACHINE_ROLE;
{$EXTERNALSYM DSROLE_MACHINE_ROLE}
TDsRoleMachineRole = DSROLE_MACHINE_ROLE;
//
// Previous server state
//
_DSROLE_SERVER_STATE = (DsRoleServerUnknown, DsRoleServerPrimary, DsRoleServerBackup);
{$EXTERNALSYM DSROLE_SERVER_STATE}
DSROLE_SERVER_STATE = _DSROLE_SERVER_STATE;
{$EXTERNALSYM DSROLE_SERVER_STATE}
PDSROLE_SERVER_STATE = ^DSROLE_SERVER_STATE;
{$EXTERNALSYM PDSROLE_SERVER_STATE}
TDsRoleServerState = DSROLE_SERVER_STATE;
_DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = (DsRoleFiller0, DsRolePrimaryDomainInfoBasic, DsRoleUpgradeStatus, DsRoleOperationState);
{$EXTERNALSYM _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL}
DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL;
{$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_INFO_LEVEL}
TDsRolePrimaryDomainInfoLevel = DSROLE_PRIMARY_DOMAIN_INFO_LEVEL;
//
// Flags to be used with the PRIMARY_DOMAIN_INFO_LEVEL structures below
//
const
DSROLE_PRIMARY_DS_RUNNING = $00000001;
{$EXTERNALSYM DSROLE_PRIMARY_DS_RUNNING}
DSROLE_PRIMARY_DS_MIXED_MODE = $00000002;
{$EXTERNALSYM DSROLE_PRIMARY_DS_MIXED_MODE}
DSROLE_UPGRADE_IN_PROGRESS = $00000004;
{$EXTERNALSYM DSROLE_UPGRADE_IN_PROGRESS}
DSROLE_PRIMARY_DOMAIN_GUID_PRESENT = $01000000;
{$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_GUID_PRESENT}
//
// Structure that correspond to the DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
//
type
PDSROLE_PRIMARY_DOMAIN_INFO_BASIC = ^DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
{$EXTERNALSYM PDSROLE_PRIMARY_DOMAIN_INFO_BASIC}
_DSROLE_PRIMARY_DOMAIN_INFO_BASIC = record
MachineRole: DSROLE_MACHINE_ROLE;
Flags: ULONG;
DomainNameFlat: LPWSTR;
DomainNameDns: LPWSTR;
DomainForestName: LPWSTR;
DomainGuid: TGUID;
end;
{$EXTERNALSYM _DSROLE_PRIMARY_DOMAIN_INFO_BASIC}
DSROLE_PRIMARY_DOMAIN_INFO_BASIC = _DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
{$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_INFO_BASIC}
TDsRolePrimaryDomainInfoBasic = DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
PDsRolePrimaryDomainInfoBasic = PDSROLE_PRIMARY_DOMAIN_INFO_BASIC;
PDSROLE_UPGRADE_STATUS_INFO = ^DSROLE_UPGRADE_STATUS_INFO;
{$EXTERNALSYM PDSROLE_UPGRADE_STATUS_INFO}
_DSROLE_UPGRADE_STATUS_INFO = record
OperationState: ULONG;
PreviousServerState: DSROLE_SERVER_STATE;
end;
{$EXTERNALSYM _DSROLE_UPGRADE_STATUS_INFO}
DSROLE_UPGRADE_STATUS_INFO = _DSROLE_UPGRADE_STATUS_INFO;
{$EXTERNALSYM DSROLE_UPGRADE_STATUS_INFO}
TDsRoleUpgradeStatusInfo = DSROLE_UPGRADE_STATUS_INFO;
PDsRoleUpgradeStatusInfo = PDSROLE_UPGRADE_STATUS_INFO;
_DSROLE_OPERATION_STATE = (DsRoleOperationIdle, DsRoleOperationActive, DsRoleOperationNeedReboot);
{$EXTERNALSYM _DSROLE_OPERATION_STATE}
DSROLE_OPERATION_STATE = _DSROLE_OPERATION_STATE;
{$EXTERNALSYM DSROLE_OPERATION_STATE}
TDsRoleOperationState = DSROLE_OPERATION_STATE;
PDSROLE_OPERATION_STATE_INFO = ^DSROLE_OPERATION_STATE_INFO;
{$EXTERNALSYM PDSROLE_OPERATION_STATE_INFO}
_DSROLE_OPERATION_STATE_INFO = record
OperationState: DSROLE_OPERATION_STATE;
end;
{$EXTERNALSYM _DSROLE_OPERATION_STATE_INFO}
DSROLE_OPERATION_STATE_INFO = _DSROLE_OPERATION_STATE_INFO;
{$EXTERNALSYM DSROLE_OPERATION_STATE_INFO}
TDsRoleOperationStateInfo = DSROLE_OPERATION_STATE_INFO;
PDsRoleOperationStateInfo = PDSROLE_OPERATION_STATE_INFO;
function DsRoleGetPrimaryDomainInformation(lpServer: LPCWSTR; InfoLevel: DSROLE_PRIMARY_DOMAIN_INFO_LEVEL; Buffer: pDSROLE_PRIMARY_DOMAIN_INFO_BASIC): DWORD; stdcall;
{$EXTERNALSYM DsRoleGetPrimaryDomainInformation}
procedure DsRoleFreeMemory(Buffer: pointer); stdcall;
{$EXTERNALSYM DsRoleFreeMemory}
implementation
const
netapi32 = 'netapi32.dll';
function DsRoleGetPrimaryDomainInformation; external netapi32 name 'DsRoleGetPrimaryDomainInformation';
procedure DsRoleFreeMemory; external netapi32 name 'DsRoleFreeMemory';
end.
有了这个,你只需要调用它:
uses
DSRole;
procedure TForm1.FormCreate(Sender: TObject);
var
pBuffer : pDSROLE_PRIMARY_DOMAIN_INFO_BASIC;
begin
pBuffer := new( pDSROLE_PRIMARY_DOMAIN_INFO_BASIC);
Caption := BoolToStr(DsRoleGetPrimaryDomainInformation(nil,DsRolePrimaryDomainInfoBasic,pBuffer) = ERROR_SUCCESS, True);
FreeMem(pBuffer);
end;
关于delphi - 如何在delphi中调用WINAPI DsRoleGetPrimaryDomainInformation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30523189/
一个非常简单的问题,如果我创建一个 HANDLE在 app1.exe 中,它得到值 0x01这个值是全局唯一的吗? 或者当其他一些进程创建一个 HANDLE 时是否有可能?也有值(value) 0x0
我正在使用winapi-rs crate并尝试获取cpu的使用率,但是我什至无法做到这一点。 PdhCollectQueryData转换为十六进制时将返回“-2147481643”,然后错误代码为“0
有人可以告诉我,在 winapi 中将进度条作为 TreeView 控件的一部分是否现实?我使用 GTK 制作了一个 GUI,并且使用进度条作为单元格元素效果很好,如下图所示。 我没有开发自定义控件的
有 getaddrinfo() 用于阻止主机解析,但是否有非阻塞方法? 最佳答案 我不认为有这样的事情,但你总是可以将它包装在一个线程中并使用信号量来表示完成。 关于winapi - 在 WINAPI
如果我知道 Hwnd,如何获取正在运行的应用程序的图标? 最佳答案 如果你有窗口的句柄,你可以使用 GetClassLong : HICON icon = (HICON)GetClassLong(wi
我正在尝试阅读 IMAGE_DOS_HEADER使用 definition of that structure 的模块来自 winapi箱。 这是我的工作代码: let mut IDH: IMAGE_
我目前正在阅读MSDN的文档,以将流渲染到音频渲染器。 换句话说,就是从麦克风播放我捕获的数据。 http://msdn.microsoft.com/en-us/library/dd316756%28
我有一个问题,希望你能帮我解决。已经没有我的研究运气了...尝试过 stackoverflow、google,甚至 yahoo... 如何在不使用鼠标的情况下强制显示工具提示? 我目前正在实现一些窗口
在 D 中,每次启动应用程序时,我的垃圾收集器都会崩溃。 Windows 模块: pragma(lib, "user32.lib"); import std.string; extern(Window
我正在学习 WinAPI C++ 的绘图形状 我试图在 WM_PAINT 上用一些代码绘制 2 个椭圆: PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps)
我使用 PostMessage 模拟鼠标事件并在记事本应用程序上进行了测试。 我不想通过发送鼠标事件来获得记事本应用程序的焦点。 仅当我在 PostMessage 参数中使用记事本的 ChildWin
如何使用 Win32 WinAPI 创建一个 EditBox,使其看起来像在 Visual C# 或 VB 中的 VS 设计器中放置一个编辑框(具有漂亮的顶部边框等)?这是一张图片,展示了它的外观以及
有CopyRect WinAPI function ,它只是复制一个 RECT到另一个。 自从我挖掘它以来,我一直对这个函数存在的原因很感兴趣。 是赋值运算符 ( = ) 还是 CopyMemory功
只是想知道是否有一种方法可以将数字打印到控制台通过调用。它可以是 10 进制,也可以是十六进制,我不介意。 我想看看一些函数返回的格式。 我宁愿不使用 WriteConsole 和大量 asm 来做这
这似乎部分有效,但我无法获取要打印的字符串值 pub fn test() { let mut buf: Vec = vec![0; 64]; let mut sz: DWORD = 0
在 Excel 中使用 Visual Basic,我可以使用 DECLARE 关键字声明 WinAPI 函数 - 例如 Declare Function SetLocaleInfo Lib "kern
..嗨,我有这个代码: #[cfg(windows)] extern crate winapi; use winapi::um::winuser::{FindWindowW, GetClientRec
我有一个 WH_CALLWNDPROC Hook 代码,它处理 WM_INITDIALOG 消息以获取有关消息框的信息。我可以获得“消息”、“标题”、“按钮”,但无法获得“图标”信息。我正在尝试使用如
这是我的源代码: extern crate user32; extern crate kernel32; use std::io::prelude::*; use std::net::TcpStrea
WinAPI OpenFile 函数返回 HFILE,例如 GetFileTime 需要 HANDLE。当我用 (HANDLE)some_hFile 喂它时,它似乎工作正常。这种类型有什么不同吗,或者
我是一名优秀的程序员,十分优秀!