问题在于用于查找所选用户已登录的计算机的SQL查询.我执行查询,使用适配器将结果填充到表中,然后将表对象读入数组.我不完全理解Powershell中数组的语法和功能,所以我可能会错误地做这个部分.在将表读入数组的函数内部,数组的内容看起来很好(只是计算机名)但是当我将该数组传递出函数并将其分配给变量时,该数组具有以下数据:{ #,compName}.它似乎是找到的计算机数量,然后是名称,如果找到一台计算机,则阵列为{1,ComputerName}.但是,如果找到多台计算机,则为2台或更多台,则阵列为{2,ComputerNameComputerName}.
这是带有SQL查询的函数以及用户选择计算机的函数.
Function GetComputerList{
param ($u)
#use the display name of the user to get their login name
$queryUser = Get-ADUser -f{DisplayName -eq $u} #-Properties sAMAccountname | Select sAMAccountname
$queryName = "'"
$queryName += $queryUser.SamAccountName
$queryName += "'"
$query = "SELECT SYS.Netbios_Name0 FROM v_R_System SYS WHERE User_Name0 = $queryName ORDER BY SYS.User_Name0, SYS.Netbios_Name0"
$connection = new-object system.data.sqlclient.sqlconnection( "Data Source=SERVER;Initial Catalog=DATABASE;Integrated Security=SSPI;”)
$adapter = new-object system.data.sqlclient.sqldataadapter ($query, $connection)
$table = new-object system.data.datatable
$adapter.Fill($table)
$i = 1
foreach($object in $table){
<#Write-Host …Run Code Online (Sandbox Code Playgroud) 我很难绕过声明可变(或指针)变量并通过FFI与C代码交互.我大部分时间都在玩这个,并且由于Rust的发展速度很快,我发现了相互矛盾的例子.:)
情况是这样的:我有一个C函数,它接受一个指向a的指针struct,这个结构有ints和char *s的字段.我的理解是我需要在Rust中声明一个类似的结构来传递给extern C函数.
这是我在尝试解决这个问题时编写的示例文件:
main.rs
extern crate libc;
struct testStruct {
an_int: libc::c_int,
a_string: *mut libc::c_char
}
extern {
fn start_test(test: *mut testStruct) -> libc::c_int;
}
fn main() {
// println!("Hello, world!");
let test_struct = testStruct { an_int: 1, a_string: "hello" };
start_test(&mut test_struct);
}
Run Code Online (Sandbox Code Playgroud)
-
test_file.c
#include <stdio.h>
#include "test_file.h"
struct test_struct {
int an_int;
char *a_string;
};
int start_client(struct test_struct *test) {
printf("Test function!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
显然,实际的代码更复杂,我只是想尝试一个基本的例子来理解如何使用FFI在Rust中使用mutable/pointer.