关于unicode

最近做了个项目,获得cpu占用率,动态引用ntdll.dll里的函数,编译环境:visual studio 2008,但是调试时发现在LoadLibrary函数返回的值无法解析,这样在GetProcAddress时返回null,郁闷了一下午,终于在一个老外的论坛上找到答案,如下:

 

ask:

I'm using MS Visual Studio C++ 2008 Express.  I've included all the paths to the DLL, "visa32.dll" but the LoadLibrary("visa32.dll") call returns the statement that can't convert character string to LPCSTR (pointer).  I ran the same code with the Portland Group compiler (which I no longer have) and there was not a problem accessing the DLL.  Is there some requirement for the C++ 2008 Express compiler that needs to be met?

 

answer:

Hello jterry,

If you compile as Unicode you need to pass Unicode strings to Win32 APIs which have LPTSTR or LPWSTR string. When you want to write code compilable for Unicode and Ansi just enclose all string constants in _T(). In your case: 

LoadLibrary(_T("visa32.dll")) 

You can look at this post on the microsoft discussion forums for more information.  Have a great day.

 

PS:定义 _T() 的头文件tchar.h。

 

为什么这种问题都是在老外的帖子上找到答案呢,唉~~不专业。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值