我需要编写一个应用程序来获取系统/应用程序的事件日志.另一个要求是我需要每隔一分钟读取事件日志以获取自上次读取以来的新事件日志.目前我正在考虑使用C#来实现而不是C++.
有了这些,我读了几个网页,如果我理解正确,我可以使用WMI或EventLog类来读取事件日志.在我看来,当使用EventLog类添加新事件日志时,我会收到通知,但我不确定这比使用WMI更好.如果我的理解是正确的,我想知道我应该采取哪种方式?
请给我一些建议.谢谢.
我想知道当我右键单击表项时如何打开弹出菜单.在弹出菜单中,应该给出一些添加和删除等操作,这将创建一个新行或删除所选行.
我是Qt世界的新手,所以如果有人能给我详细信息(如果可能的话还有代码),那么我将非常感激他/她.
谢谢.
我的目标:只有在QListWidget
您点击某个项目的区域内,才会打开包含删除的菜单.
编辑:好的我用QListWidget
和菜单解决了问题.现在必须完成以下工作:
如果使用鼠标右键单击某个项目,然后单击"删除",则该项目将被删除.
我的代码:
void ProvideContextMenu(const QPoint &); // MainWindow.h
Run Code Online (Sandbox Code Playgroud)
// In MainWindow.cpp
ui->listFiles->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->listFiles, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(ProvideContextMenu(const QPoint &)));
void MainWindow::ProvideContextMenu(const QPoint &pos)
{
QPoint item = ui->listFiles->mapToGlobal(pos);
QMenu submenu;
submenu.addAction("ADD");
submenu.addAction("Delete");
QAction* rightClickItem = submenu.exec(item);
if (rightClickItem && rightClickItem->text().contains("Delete") )
{
ui->listFiles->takeItem(ui->listFiles->indexAt(pos).row());
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2:好的,我解决了整个问题:D.我上传了我的代码,如果有人需要这样的东西,它可以帮助他/她.
自从最新的Windows 10 1809更新以来,我们无法再打开我们使用的USB HID键盘式设备CreateFile
.我们将问题简化为这个最小的例子:
#include <windows.h>
#include <setupapi.h>
#include <stdio.h>
#include <hidsdi.h>
void bad(const char *msg) {
DWORD w = GetLastError();
fprintf(stderr, "bad: %s, GetLastError() == 0x%08x\n", msg, (unsigned)w);
}
int main(void) {
int i;
GUID hidGuid;
HDEVINFO deviceInfoList;
const size_t DEVICE_DETAILS_SIZE = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + MAX_PATH;
SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = alloca(DEVICE_DETAILS_SIZE);
deviceDetails->cbSize = sizeof(*deviceDetails);
HidD_GetHidGuid(&hidGuid);
deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if(deviceInfoList == INVALID_HANDLE_VALUE) {
bad("SetupDiGetClassDevs");
return 1;
}
for (i = 0; ; ++i) {
SP_DEVICE_INTERFACE_DATA …
Run Code Online (Sandbox Code Playgroud) 有没有办法使用g ++编译器或任何其他方法打印C++对象的布局.一个简化的例子(假设int需要4个字节)
class A{
int a;
};
class B:public A{
int b;
}
Run Code Online (Sandbox Code Playgroud)
所以输出就是
A-
0 4
+ a +
B-
0 4 8
+ A.a + b +
Run Code Online (Sandbox Code Playgroud)
理解对象的布局(在我的例子中是虚拟机代码)会很有用.
提前致谢.
问候,扎赫尔
我最近发现朋友声明范围遵循极其特殊的规则 - 如果你有一个friend
函数或一个尚未声明的类的声明(定义),它会在直接封闭的命名空间中自动声明(定义),但它是不可见的不合格和合格的查询; 但是,友元函数声明通过依赖于参数的查找保持可见.
struct M {
friend void foo();
friend void bar(M);
};
void baz() {
foo(); // error, unqualified lookup cannot find it
::foo(); // error, qualified lookup cannot find it
bar(M()); // ok, thanks to ADL magic
}
Run Code Online (Sandbox Code Playgroud)
如果你看一下标准(参见链接的答案),他们就会付出很大的代价来启用这种古怪的行为,在复杂规则的限定/非限定查找中添加一个特定的例外.最终的结果让我感到非常困惑1,还有另一个案例要添加到实现中.作为
friend
声明引用现有名称,期限; 要么似乎更容易实现,指定,最重要的是,理解,我想知道:为什么他们为这个烂摊子烦恼?他们试图覆盖哪些用例?在任何这些更简单的规则下(特别是第二个与现有行为最相似的规则)会破坏什么?
例如,在这种特殊情况下
struct M {
friend class N;
};
N *foo;
typedef int N;
Run Code Online (Sandbox Code Playgroud)
你得到可笑的精神分裂症错误信息
<source>:4:1: error: 'N' does not name …
Run Code Online (Sandbox Code Playgroud)谁知道这个问题是什么?
我得到这个警告现场XXX永远不会分配给,永远有它的默认值零上private static Quantizer quantit;
我不知道该怎么做才能修复,因为当我尝试使用quantit.Quantize()
debug时说:"对象引用未设置为对象的实例." 并指向au = quantit.Quantize();
代码:
public class Quantization : System.Windows.Forms.Form
{
private static Quantizer quantit;
private Button btnLoad;
private PictureBox imgPhoto;
public Quantization()
{
btnLoad = new Button();
btnLoad.Text = "&Load";
btnLoad.Left = 10;
btnLoad.Top = 10;
btnLoad.Click += new System.EventHandler(this.OnLoadClick);
imgPhoto = new PictureBox();
imgPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
imgPhoto.Width = this.Width / 2;
imgPhoto.Height = this.Height / 2;
imgPhoto.Left = (this.Width - imgPhoto.Width) / 2;
imgPhoto.Top = …
Run Code Online (Sandbox Code Playgroud) 我试图以某种方式禁用/标记为弃用了可怕的std::string::operator=(char)
重载(根据我的经验,仅在错误地将整数分配给字符串时使用,并导致细微且难以跟踪的错误).
我尝试过:
一个带有静态断言的显式特化
#include <string>
#include <type_traits>
template<> std::basic_string<char> &std::basic_string<char>::operator=(char c) {
static_assert(false, "Don't use this!");
}
Run Code Online (Sandbox Code Playgroud)
这<string>
已失败,因为已经显式实例化了std::string
[[deprecated]]
属性,在各个位置上如上述应用于类似的声明; 我试过的位置似乎没有产生任何合理的结果;=delete
,由于与上述类似的原因而失败;setlocale
使用--wrap
ld
链接器选项对运行的使用进行运行时检查),但事实上这是一个模板和内联方法使问题复杂化.现在问题:
=delete
)标准库中的任何函数或方法(读取:在库中你不能改变标题中的声明)?[[deprecated]]
);嗨,我是C#从Java迁移的新手.尝试使用HEX中的IO读取文件.当我读到第一个字节时,我没有得到我在Hex编辑器中看到的内容.
我正在使用
StreamReader reader = new StreamReader(fileDirectory);
int hexIn;
String hex;
for (int i = 0; (hexIn = reader.Read()) != -1; i++){
hex = Convert.ToString(hexIn, 16);
}
Run Code Online (Sandbox Code Playgroud)
在Java我用过......
FileInputStream fis = new FileInputStream(file);
long length = file.length();
int hexIn;
String hex = "";
for(int i = 0; (hexIn = fis.read()) != -1; i++){
String s = Integer.toHexString(hexIn);
if(s.length() < 2){
s = "0" + Integer.toHexString(hexIn);
}
Run Code Online (Sandbox Code Playgroud)
我希望这是有道理的.任何帮助都会得到最多的帮助:)
谢谢
我正在尝试从批处理文件中运行多个后台进程,并将输出定向到文件.是否可以在Windows中执行此操作?这是我尝试过的,但最终导致启动程序的输出而不是后台进程.
start myapp.exe > myapp.out 2>&1
Run Code Online (Sandbox Code Playgroud) 假设我正在编写Derived
并且必须继承Base
,我无法控制并且有两个单独的构造函数和一个已删除的副本和移动构造函数:
struct Base {
Base(int i);
Base(const char *sz);
Base(const Base&) = delete;
Base(const Base&&) = delete;
};
struct Derived {
Derived(bool init_with_string);
};
Run Code Online (Sandbox Code Playgroud)
现在,根据another_param
我必须使用构造函数或其他函数初始化我的基类的值; 如果C++不那么严格,那就像是:
Derived::Derived(bool init_with_string) {
if(init_with_string) {
Base::Base("forty-two");
} else {
Base::Base(42);
}
}
Run Code Online (Sandbox Code Playgroud)
(这对于计算值以直接表达式传递给基类构造函数/字段初始化器很麻烦的所有情况也很有用,但我很讨厌)
不幸的是,即使我没有看到特定的codegen或对象模型障碍这种事情,这不是有效的C++,我想不出简单的解决方法.
有什么方法我不知道吗?