Articles of c + +

为什么一个连接不得不打开,而不是填充数据集?

当我连接到C#应用程序中的SQL数据源时,可以使用以下代码填充数据集。 请注意,我不明确打开到数据源的连接。 SqlConnection cw_con = new SqlConnection("Server=Server;Database=Database;User=User;password=password"); SqlCommand cmd = new SqlCommand("SELECT * FROM Example WHERE value = value"); cmd.Connection = cw_con; //Create DataSet DataSet cw_ds = new DataSet("cw_ds"); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; //Execute Command and Fill DataSet da.Fill(cw_ds); cw_ds.Clear(); 但是,如果我想执行一个非查询如INSERT INTO或UPDATE为什么我必须使用connection.Open();显式打开连接connection.Open(); ? SqlConnection cw_con = new SqlConnection("Server=Server;Database=Database;User=User;password=password"); cw_con.Open(); SqlCommand cmd […]

如何在Windows Vista / 7/8上以编程方式启动SFC?

我一直在试图解决Chris Iverson在其他的Stackoverflow问题中遇到的问题 。 我想以编程方式启动SFC ( 系统文件检查器工具)。 它适用于Windows XP: private void RunSfc() { ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/K sfc.exe /scannow"); System.Diagnostics.Process.Start(startInfo); } 在Windows XP下工作的其他变体: //Launch SFC directly ProcessStartInfo startInfo = new ProcessStartInfo("sfc.exe", "/scannow"); System.Diagnostics.Process.Start(startInfo); //Use full path to SFC String sfcPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "sfc.exe"); ProcessStartInfo startInfo = new ProcessStartInfo(sfcPath, "/scannow"); Windows 7上的相同代码失败(启动程序以pipe理员身份运行)。 出现控制台窗口,但SFC提供了错误: Windows Resource […]

Windows API相当于“WMIC QFE Get”

我是C ++新手,目前正在C ++ DLL中获取Windows Hotfix / Patch信息。 我已经评估了以下方面: 通过在C ++代码中执行subprocess并运行wmic qfe get并读取所有数据。 通过使用C ++ API来初始化COM,连接到Wbem并select * from win32_quickfixengineering查询中执行select * from win32_quickfixengineering 。 除上述两种方法外, 有没有直接的Windows API,为我做所有的工作,并给出目前安装在机器上的KB信息列表?

C ++保留内存空间

是否有任何方法来保留内存空间,以便默认情况下使用Windows内存pipe理器,以便我的应用程序不会耗尽内存,如果我的程序没有使用超过我在程序开始时保留的空间?

在HandleScope构造函数的Windows上的V8中的SegFault

我开发了一个embedded了V8的C ++ Windows服务。 debugging版本运行良好。 问题是发行版本根本不起作用。 我将使用VisualStudio 2010的V8引擎编译为一个static-lib文件。 我将服务的debugging版本与V8debugging库以及服务的发布版本与V8版本库链接起来。 Release版本在程序的第一行HandleScope v8Scope;中HandleScope v8Scope; 。 (我实例化了v8引擎的本地范围)。 不幸的是,我无法debugging,因为我运行的版本,我看不出有什么问题,因为在debugging版本运行正常。 我不明白为什么当我尝试实例化范围时收到SegmFault。 你有什么build议,我如何处理这种情况? LaterEdit: 使用后续代码,我意识到当前的隔离是NULL。 所以,现在我的问题是如何创build一个不是NULL的隔离上下文。 Isolate* isolate = Isolate::GetCurrent(); if (isolate==NULL) return; Locker v8Locker; HandleScope v8Scope(isolate); 谢谢,

如何修复Windows 8.1中的崩溃C?

我正在用MinGW Gcc使用代码块。 编译构build工作正常,但是当我执行它运行时崩溃: main.c中: #include <stdio.h> #include <stdlib.h> #include <vlc/vlc.h> #include <vlc/libvlc.h> #include <windows.h> int main(int argc, char **argv) { libvlc_instance_t *vlc; vlc = libvlc_new (0, NULL); return 0; } 生成日志: ————– Clean: Debug in rtsp (compiler: GNU GCC Compiler)————— Cleaned "rtsp – Debug" ————– Build: Debug in rtsp (compiler: GNU GCC Compiler)————— mingw32-gcc.exe -Wall […]

是正则expression式的gcc 4.8或更早的车?

我正在尝试在C ++ 11代码中使用std :: regex,但看起来支持是有点bug。 一个例子: #include <regex> #include <iostream> int main (int argc, const char * argv[]) { std::regex r("st|mt|tr"); std::cerr << "st|mt|tr" << " matches st? " << std::regex_match("st", r) << std::endl; std::cerr << "st|mt|tr" << " matches mt? " << std::regex_match("mt", r) << std::endl; std::cerr << "st|mt|tr" << " matches tr? " […]

如何检测用户何时单击WebView控件中的超链接?

我试图检测用户何时点击从Windows 10的WebView控件中的超链接。有什么办法来检测此事件吗?

将数据序列化代码从C ++ linux / mac移植到C ++窗口

我有一个软件框架在mac和linux上编译和运行成功。 我现在试图将其移植到Windows(使用mingw)。 到目前为止,我有软件编译和运行在Windows下,但它不可避免的越野车。 特别是,我有一个阅读macos(或linux)序列化到程序的windows版本(segfaults)的数据的问题。 序列化过程序列化原始variables(长整数,整数,双精度等)的值到磁盘。 这是我正在使用的代码: #include <iostream> #include <fstream> template <class T> void serializeVariable(T var, std::ofstream &outFile) { outFile.write (reinterpret_cast < char *>(&var),sizeof (var)); } template <class T> void readSerializedVariable(T &var, std::ifstream &inFile) { inFile.read (reinterpret_cast < char *>(&var),sizeof (var)); } 所以为了保存一堆variables的状态,我依次调用每个variables的serializeVariable。 然后再读取数据,调用readSerializedVariable按照保存顺序进行调用。 例如保存: ::serializeVariable<float>(spreadx,outFile); ::serializeVariable<int>(objectDensity,outFile); ::serializeVariable<int>(popSize,outFile); 并阅读: ::readSerializedVariable<float>(spreadx,inFile); ::readSerializedVariable<int>(objectDensity,inFile); ::readSerializedVariable<int>(popSize,inFile); 但在Windows中,这个序列化数据的读取失败。 我猜测,Windows序列化数据有点不同。 我想知道是否有一种方法可以修改上面的代码,以便保存在任何平台上的数据可以在任何其他平台上读取…任何想法? […]

移植win32代码(windows.h)到linux

我正在一个C ++项目,我有一堆Visual Studio生成的项目文件,我想端口到Linux。 我基本上是在Windows上的多个文件中使用windows.h头文件。 现在,我不确定,因为那里没有明确的存在linux.h文件(如果是这样,请指导我在哪里看)。 在Linux上,我使用Eclipse CDT进行开发。 我有两个想法,它可能会在Linux上工作,但我希望你的input知道什么是正确的方向是: (1)用C ++文件中的Linux API调用删除Windows API调用。 但是,这意味着,我不得不在Linux中find相同的function,我不知道在哪里看。 例如。 在Win32中的Filetime相当于在Linux中的东西(还没有发现这个东西)。 (2)我复制这些函数的基本语法(如在windows.h中写的),只是创build一个头文件(可以说我把它命名为linux.h),并将这个头文件包含在linux项目中。 所以,显然你可能已经发现我对如何推进事情感到困惑。 我只是想把这件事情搞清楚 除了以下内容,请给我build议/意见:(1)不,我不想使用Boost。 (2)我不想在Visual Studio中重写这些文件。