编译ACE提示undefined reference to `in_word_set(char const *, unsigned int)’

使用linux编译ACE库,按照官网的步骤创建config.h文件和platform_macros.GNU文件后,使用make命令编译,结果提示以下错误:

[php]
/usr/local/ACE_wrappers/apps/gperf/tests/test.cpp:28: undefined reference to
`in_word_set(char const *, unsigned int)’
collect2: ld returned 1 exit status
make[4]: *** [cppout] Error 1
make[4]: Leaving directory `/usr/local/ACE_wrappers/apps/gperf/tests’
[/php]

其实是因为步骤少了一步,设置LD_LIBRARY_PATH的环境变量值,使用以下命令,重新编译即可:

[php]
export LD_LIBRARY_PATH=$ACE_ROOT/lib
[/php]

VS2005中C#程序调用C++动态库断点无效解决办法

近段时间将编译环境换成了VS2005,出现了一些其名其妙的问题,比如C#的程序调用C++的动态库,设置断点始终提示“当前不会命中断点,还没有为该该文档加载任何符号”


Continue reading ‘VS2005中C#程序调用C++动态库断点无效解决办法’ »

调用DLL弹出The value of ESP was not properly saved across a function call

像这种错误一般是由于C++回调函数声明引起的,在声明回调函数指针的时候,使用
[php]
typedef void (*RecvMessage)(const char* msgContent);
[/php]

只要将声明加上一个回调定义就可以了__stdcall,如下
[php]
#ifdef WIN32
typedef void (__stdcall *RecvMessage)(const char* msgContent);
#else
typedef void (*RecvMessage)(const char* msgContent);
#endif
[/php]

这样就可以解决了。

windows和linux使用printf输出64位长整数

变量定义 输出方式 gcc(mingw32) g++(mingw32) gcc(linux i386) g++(linux i386) MicrosoftVisual C++ 6.0
long long “%lld” 错误 错误 正确 正确 无法编译
long long “%I64d” 正确 正确 错误 错误 无法编译
__int64 “lld” 错误 错误 无法编译 无法编译 错误
__int64 “%I64d” 正确 正确 无法编译 无法编译 正确
long long cout 非C++ 正确 非C++ 正确 无法编译
__int64 cout 非C++ 正确 非C++ 无法编译 无法编译
long long printint64() 正确 正确 正确 正确 无法编译

关于printf函数输出64位数的问题,其实在window下和linux下是不一样的
linux下是
[php]
printf("%lld/n",a);
printf("%llu/n",a);
[/php]
windows下是
[php]
printf("%I64d/n",a);
printf("%I64u/n",a);
[/php]

printf与cout混用输出先后顺序的问题

在代码中若使用了printf与cout,若不注意则会出现输出顺序与预想的不一致的问题。如下代码:

[php]
int main()
{
int i = 0;
for (i = 0; i < 3; i++)
{
std::cout << "i= ";
printf("%d\n", i);
}
return 0;
}
[/php]
Continue reading ‘printf与cout混用输出先后顺序的问题’ »

多字节字符与宽字符的printf输出

有某些情况需要用到输出多字节字符,而直接使用
[php]
printf("%s", xxx);
[/php]
的方式只能输出第一个字符,例如下面的内存块中保存的宽字符:

[php]
0x00294B38 43 00 3a 00 5c 00 57 00 69 00 6e 00 64 00 6f 00 77 00 73 00 5c 00 73 00 79 C.:.\.W.i.n.d.o.w.s.\.s.y
0x00294B51 00 73 00 74 00 65 00 6d 00 33 00 32 00 5c 00 74 00 61 00 73 00 6b 00 68 00 .s.t.e.m.3.2.\.t.a.s.k.h.
0x00294B6A 6f 00 73 00 74 00 2e 00 65 00 78 00 65 00 00 00 cd cd cd cd cd cd cd cd cd o.s.t…e.x.e…?????????
[/php]

如果直接使用
[php]
printf("%s", xxx);
[/php]
输出,则会将0x43后面的0x00当作结束符,也就是只会认为只有C字符就结束了,输出的时候会发现,只输出了C后面的内容则没有输出,而且使用
[php]
strlen(xxx);
[/php]
来计算长度也为1。

如果需要完成输出,则需要将printf中的小写s改为大写即可,即
[php]
printf("%S", xxx);
[/php]

如何双击dsw文件快速打开多个VC++6.0工程

在Win7操作系统下,如果是以Administrator登陆,则VC6.0打开工程文件的时候,不能同时打开多个工程文件,后打开的工程会将前一个工程close掉,这样,VC6.0只能出现一个进程。在xp下,我们可以设置文件打开的默认方式中去掉DDE选项,这样可以使得VC6可以同时打开多个工程,但在win7下,却没有办法找到这个设置窗口。经过实践,可以用以下办法解决:

打开cmd:

1)输入assoc .dsp回车,确认后缀为.dsp的文件类型为dspfile;
2)输入assoc .dsw回车,确认后缀为.dsw的文件类型为dswfile;
3)打开vc6的快捷方式的属性,拷贝vc6的路径,注意连两边的双引号都一起拷贝,比如时候这个路径:
“C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE”
4)在cmd窗口,输入ftype dspfile=”C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE” %1
5)在cmd窗口,输入ftype dswfile=”C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE” %1

设置结束,双击不同的工程文件,看是否可同时打开多个工程文件吧。

c++类的基类构造函数

在c++中子类构造时,会先调用基类的构造函数,可以利用此方法,将所有子类中共用的成员变量放入到基类的构造函数中进行初始化,如下代码

[php]
class B
{
public:
B()
{
printf("class B construct\n");
}
B(int a)
{
printf("class B construct a%d\n", a);
}
virtual ~B(){}
virtual int Add(int a, int b);
};

class C : public B
{
public:
C()
{
printf("class C construct\n");
}
C(int a)
{
printf("class C construct a%d\n", a);
}
virtual ~C(){}
virtual int Add(int a, int b);
};
int main()
{
B* b = new B;
B* c = new C(1);
int result = b->Add(1,2);
printf("result1:%d\n", result);
result = c->Add(1,2);
printf("result2:%d\n", result);
return 0;
}
[/php]
Continue reading ‘c++类的基类构造函数’ »

win7注册com控件失败的问题

现在的win7非常流行,但有时候win7开发软件,需要注册某个com控件,可以使用两种方式

第一种是,直接打开运行,在运行里面输入regsvr32 xxx.dll,再点运行,这种在xp下是可行的,但在win7下需要使用管理员权限,不然始终提示注册失败,模块”xxx.dll”加载失败,请确保该二进制存储在指定的路径中,或者调试它以检查该二进制或相关的.DLL文件是否有问题。找不到指定的程序。

第二种是,打开cmd控制台,输入regsvr32 xxx.dll按回车运行,这种在xp下也是可行,但在win7下需要管理员权限。解决方式是搜索cmd右键使用管理员权限运行,然后再使用regsvr32 xxx.dll命令。

有时候动态库的路径带有空格的文件夹名,比如C:\Program Files目录下的dll文件,那么需要使用双引号将文件路径包含起来,如regsvr32 “C:\Program Files\xxx.dll”

stl中的list,map,vector等的erase循环遍历删除元素

stl中的list,map与vector调用erase删除元素有些区别,都可以使用itor = listInt.erase(itor);的试,但vecotr不能使用listInt.erase(itor++);

[php]
//list方式
std::list<int> listInt;
for (int i = 0; i < 10; i++)
{
listInt.push_back(i);
}

std::list<int>::iterator itor = listInt.begin();
while (itor != listInt.end())
{
int a = (*itor);
if (a%2 == 0)
{
itor = listInt.erase(itor); //此处是将erase返回的指针传给itor
continue;
}
itor++;
}
[/php]
Continue reading ‘stl中的list,map,vector等的erase循环遍历删除元素’ »