dll调用 调用方法基本正确,WINDOWS中有很多怪问题出现null Exception的.用 try{...}catch(Exception){}容错就好. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对了,静态的API调是static 的. 我使用new 是开辟数组空间,函数原型如下BOOL EnumServicesStatus( SC_HANDLE hSCManager, DWORD dwServiceType, DWORD dwServiceState, LPENUM_SERVICE_STATUS lpServices, DWORD cbBufSize, LPDWORD pcbBytesNeeded, LPDWORD lpServicesReturned, LPDWORD lpResumeHandle); ess=new EnumServiceStatus[100]; --》ess=EnumServiceStatus[100]; 试试 yaoyaonet(绿洲)编译都不通过:(还有这个函数是用来枚举windows2000的服务,我试了,如果调用函数时出错,将不能完全枚举服务 在C#中使用API首先要使用引入名字空间:using System.Runtime.InteropServices;然后[DllImport("AdvAPI32")]+函数说明 using System.Runtime.InteropServices;名称空间已经引用编译都通过了,是在运行时出现的错误提示,用try...catch...finally捕捉异常,将不能得到一个我所需要的东西. 函数原型:BOOL EnumServicesStatus( SC_HANDLE hSCManager, DWORD dwServiceType, DWORD dwServiceState, LPENUM_SERVICE_STATUS lpServices, DWORD cbBufSize, LPDWORD pcbBytesNeeded, LPDWORD lpServicesReturned, LPDWORD lpResumeHandle);C#结构[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)] public struct ServiceStatus { public ServiceType Type; public ServiceCurrentType CurrentType; public SerivceControlAccepted ControlAccepted; public int Win32ExitCode; public int ServiceSpecificExitCode; public int CheckPoint; public int WaitHint; } [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)] public struct EnumServiceStatus { [MarshalAs(UnmanagedType.LPTStr)] public String ServiceName; [MarshalAs(UnmanagedType.LPTStr)] public String DisplayName; public ServiceStatus status; }使用的枚举类型public enum ServiceCurrentType { Stopped =0x00000001, StartPending =0x00000002, StopPending =0x00000003, Running =0x00000004, ContinuePending =0x00000005, PausePending =0x00000006, Paused =0x00000007 }public enum ServiceType { KernelDriver =0x00000001, FileSystemDriver =0x00000002, Adapter =0x00000004, RecognizerDriver =0x00000008, ServiceDriver =(KernelDriver|FileSystemDriver|RecognizerDriver), Win32_OwnProcess =0x00000010, Win32_ShareProcess =0x00000020, ServiceWin32 =(Win32_OwnProcess|Win32_ShareProcess), InterActiveProcess =0x00000100, TypeAll =(Adapter|ServiceDriver|ServiceWin32|InterActiveProcess) } public enum SerivceControlAccepted { Stop =0x00000001, PauseContinue =0x00000002, Shutdown =0x00000004, ParamChange =0x00000008, NetBindChange =0x00000010, HardwareProfileChange =0x00000020, PowerEvent =0x00000040, SessionChange =0x00000080 } public enum ServiceActiveStatus { Active =0x00000001, InActive =0x00000002, StateAll =(Active|InActive) }详细的API说明在ms-help://MS.MSDNQTR.2003FEB.2052/dllproc/base/enumservicesstatus.htm中 C# 3.0中 函数返回值是匿名类型 怎么办啊 var 又不能作为函数返回值类型 C# 怎么提取字符串中固定字符的数量 多线程 取文本框文本 怎样用电脑的记事本编写应用程序? Windows 桌面连接的问题,200分,大家都来接分 读写文件操作 删除重复数据的算法 为什么不一样??? 关于登录窗口(原码),新手问题怎么处理? 新手刚学C#请教大神这应该怎么实现 请问我如何在一个窗体变化以后将信息传递到另一个已打开的窗体中 vs2003的安装问题。
BOOL EnumServicesStatus(
SC_HANDLE hSCManager,
DWORD dwServiceType,
DWORD dwServiceState,
LPENUM_SERVICE_STATUS lpServices,
DWORD cbBufSize,
LPDWORD pcbBytesNeeded,
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle
);
编译都不通过:(
还有这个函数是用来枚举windows2000的服务,
我试了,如果调用函数时出错,将不能完全枚举服务
using System.Runtime.InteropServices;然后
[DllImport("AdvAPI32")]
+函数说明
编译都通过了,是在运行时出现的错误提示,用try...catch...finally
捕捉异常,将不能得到一个我所需要的东西.
BOOL EnumServicesStatus(
SC_HANDLE hSCManager,
DWORD dwServiceType,
DWORD dwServiceState,
LPENUM_SERVICE_STATUS lpServices,
DWORD cbBufSize,
LPDWORD pcbBytesNeeded,
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle
);
C#结构
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct ServiceStatus
{
public ServiceType Type;
public ServiceCurrentType CurrentType;
public SerivceControlAccepted ControlAccepted;
public int Win32ExitCode;
public int ServiceSpecificExitCode;
public int CheckPoint;
public int WaitHint;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct EnumServiceStatus
{
[MarshalAs(UnmanagedType.LPTStr)]
public String ServiceName;
[MarshalAs(UnmanagedType.LPTStr)]
public String DisplayName;
public ServiceStatus status;
}
使用的枚举类型
public enum ServiceCurrentType
{
Stopped =0x00000001,
StartPending =0x00000002,
StopPending =0x00000003,
Running =0x00000004,
ContinuePending =0x00000005,
PausePending =0x00000006,
Paused =0x00000007
}
public enum ServiceType
{
KernelDriver =0x00000001,
FileSystemDriver =0x00000002,
Adapter =0x00000004,
RecognizerDriver =0x00000008,
ServiceDriver =(KernelDriver|FileSystemDriver|RecognizerDriver),
Win32_OwnProcess =0x00000010,
Win32_ShareProcess =0x00000020,
ServiceWin32 =(Win32_OwnProcess|Win32_ShareProcess),
InterActiveProcess =0x00000100,
TypeAll =(Adapter|ServiceDriver|ServiceWin32|InterActiveProcess)
}
public enum SerivceControlAccepted
{
Stop =0x00000001,
PauseContinue =0x00000002,
Shutdown =0x00000004,
ParamChange =0x00000008,
NetBindChange =0x00000010,
HardwareProfileChange =0x00000020,
PowerEvent =0x00000040,
SessionChange =0x00000080
}
public enum ServiceActiveStatus
{
Active =0x00000001,
InActive =0x00000002,
StateAll =(Active|InActive)
}
详细的API说明在
ms-help://MS.MSDNQTR.2003FEB.2052/dllproc/base/enumservicesstatus.htm中