小编Aar*_*ron的帖子

我应该如何在C++中正确使用FormatMessage()?

没有:

  • MFC
  • ATL

如何使用FormatMessage()获取错误文本HRESULT

 HRESULT hresult = application.CreateInstance("Excel.Application");

 if (FAILED(hresult))
 {
     // what should i put here to obtain a human-readable
     // description of the error?
     exit (hresult);
 }
Run Code Online (Sandbox Code Playgroud)

c++ windows error-handling formatmessage

84
推荐指数
5
解决办法
5万
查看次数

VC++中的getopt()

Linux下编程时,我非常喜欢使用GNU getopt.据我所知,getopt()在MS VC++下不可用.

注意:

  • Win32环境
  • 使用Visual Studio
  • 没有提升
  • 没有MFC
  • 不关心可移植性

题:

  • 那么我如何相应地移植getopt()?
    • 在移植时我应该注意哪些指导原则?
  • 已知端口具有相同的功能?

c++ windows visual-studio-2008

11
推荐指数
2
解决办法
2万
查看次数

使用gnu DDD进行远程调试

题:

  • 目标位于远程主机上时,是否可以进行调试

例:

 # ddd --debugger /usr/bin/bashdb <sript-name> (on remote host)
Run Code Online (Sandbox Code Playgroud)

linux debugging ddd-debugger

11
推荐指数
1
解决办法
9031
查看次数

在C++中从命令行处理参数的最有效方法

有效地在C++中进行命令行参数处理的建议:

注意:仅限Windows

 1:     #include <iostream.h>
 2:     int main(int argc, char **argv)
Run Code Online (Sandbox Code Playgroud)

而不是,例如:

 if ( argc != 3 )  {
      ....
 }
Run Code Online (Sandbox Code Playgroud)

问候

c++ windows

10
推荐指数
4
解决办法
7979
查看次数

如何在VC++中创建线程

  • Linux下用C编程时,我倾向于使用POSIX Threads.

  • 没有MFC

题:

那么我如何在VC++中创建线程?

在win32下查找有关线程的更多信息?

编辑:

  • 简要说明

我喜欢stackoverflow - 学生最好的资源!

问候

c++ windows visual-studio-2008

8
推荐指数
2
解决办法
2万
查看次数

使用WinDbg的变量值

题:

如何显示 a的C++ 迭代使用WinDbg的,示出如下:

for (vector<string>::iterator i = args.begin(); i != args.end(); i++)
//omitted
//for instance:
} else if (*i == "-i") {//attempting to display the value of *i
        ++i;
        if (!::PathFileExistsA(i->c_str()))
        {
Run Code Online (Sandbox Code Playgroud)

注意:

使用?? 评估C++表达式命令,它显示以下内容:

0:000> ?? i

class std::_Vector_iterator<std::basic_string<char,
std::char_traits<char>,
std::allocator<char> >,
std::allocator<std::basic_string<char,
std::char_traits<char>,
std::allocator<char> > > >

   +0x000 _Mycont          : 0x0012ff40 std::_Container_base_secure
   +0x004 _Mynextiter      : (null) 
   +0x008 _Myptr           : 0x009c6198 

std::basic_string<char,std::char_traits<char>,std::allocator<char> >
Run Code Online (Sandbox Code Playgroud)
  • 另一个命令可以显示/打印*i- 如果我错了,请纠正我

c++ winapi windbg

7
推荐指数
1
解决办法
1万
查看次数

如果malloc通过gdb返回NULL,如何设置条件断点

示例源代码:

#include        <stdio.h>
#include        <stdlib.h>
#include        <errno.h>

#define         GIGABYTE        1024*1024*1024

int
main (void)
{
        void    *foo;
        int     result;

        foo = (void *) malloc (GIGABYTE*5);
        result = errno;

        if (foo != NULL) {
                return 2;
        } else {
                fprintf (stderr, "ERROR: %d\n", result);
                return 1;
        }
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

题:

  • 如何指导GDB( # gdb -silent ./huge_malloc)来停止/暂停执行,如果malloc()回报率0x0,没有检查是否foo0x0

c linux malloc gdb

7
推荐指数
1
解决办法
2491
查看次数

如何将接口指针传递给线程?

注意:

  • 使用原始Win32 CreateTheard()API
  • 没有MFC
  • 接口只是指向vtable的指针

题:

  • 如何将接口指针传递给线程?

插图:

IS8Simulation *pis8 = NULL;

...

CoCreateInstance(
                 clsid,
                 NULL,
                 CLSCTX_LOCAL_SERVER,
                 __uuidof(IS8Simulation),
                 (void **) &pis8);



...

hThread = CreateThread(
                NULL,
                0,
                SecondaryThread,
                //interface pointer pis8
                0,
                &dwGenericThreadID);

...

DWORD WINAPI SecondaryThread(LPVOID iValue)
{
    //using iValue accordingly
    //E.g.: iValue->Open
Run Code Online (Sandbox Code Playgroud)

问候

c++ com multithreading interface marshalling

6
推荐指数
2
解决办法
4550
查看次数

当一个进程被杀死时,这个信息记录在哪里?

题:

  • 当一个进程被终止时,这些信息是否记录在任何地方(即内核中),例如syslog(或者可以配置为记录syslog.conf)
  • 是杀手的PID信息,死亡的时间和日期以及原因

更新 -你们都给了我一些见解,非常感谢你们

linux kill process

6
推荐指数
1
解决办法
9479
查看次数

在WinDbg中表示wchar_t和char

注意:

/*
* Trivial code
*/
wchar_t *greeting = L"Hello World!";
char *greeting_ = "Hello World!";
Run Code Online (Sandbox Code Playgroud)

WinDbg的:

0:000> ?? greeting
wchar_t * 0x00415810
"Hello World!"
0:000> ?? greeting_
char * 0x00415800
"Hello World!"

0:000> db 0x00415800
00415800  48 65 6c 6c 6f 20 57 6f-72 6c 64 21 00 00 00 00  Hello World!....
00415810  48 00 65 00 6c 00 6c 00-6f 00 20 00 57 00 6f 00  H.e.l.l.o. .W.o.
00415820  72 00 6c 00 64 00 21 …
Run Code Online (Sandbox Code Playgroud)

c++ x86 winapi windbg

4
推荐指数
1
解决办法
2151
查看次数