怎样将CString字符串转化为PUSHORT和PULONG类型?

hit1106 2015-05-27 04:07:16
我用GetDlgItemText(IDC_EDIT,Iohex);获取字符串后
再转成PUSHORT PULONG UCHAR USHORT ULONG这些形式,才能在函数中引用
比如CH367mReadIoByte(
ULONG iIndex,
PVOID iADDR,
PUCHAR oByte)函数中就需要将获取的字符串转化为PUCHAR,才能在函数中引用
...全文
219 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hit1106 2015-05-29
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
#ifdef _UNICODE
 (PUSHORT)CString1
#else
 (PUCHAR)CString1
#endif
//或者干脆
(LPCTSTR)CString1
你好!请问怎么将CString类型转换为ULONG类型呢?
hit1106 2015-05-29
  • 打赏
  • 举报
回复
怎么将CString类型转换为ULONG类型呢?
赵4老师 2015-05-29
  • 打赏
  • 举报
回复
#include <afxdisp.h>
#include <windows.h>
#include <stdio.h>
int main() {
    CString cs;
    ULONG ul;

    cs="123";
    if (1==sscanf(cs,"%lu",&ul)) {
        printf("CString [%s] to ULONG is [%lu]\n",cs,ul);
    } else {
        printf("CString [%s] to ULONG fail!\n",cs);
    }

    cs="abc";
    if (1==sscanf(cs,"%lu",&ul)) {
        printf("CString [%s] to ULONG is [%lu]\n",cs,ul);
    } else {
        printf("CString [%s] to ULONG fail!\n",cs);
    }

    return 0;
}
//CString [123] to ULONG is [123]
//CString [abc] to ULONG fail!
//
赵4老师 2015-05-28
  • 打赏
  • 举报
回复
#ifdef _UNICODE
 (PUSHORT)CString1
#else
 (PUCHAR)CString1
#endif
//或者干脆
(LPCTSTR)CString1
hit1106 2015-05-27
  • 打赏
  • 举报
回复
那怎么将CString类型转化为PUSHORT呢?
赵4老师 2015-05-27
  • 打赏
  • 举报
回复
(PUCHAR)CString1
CString::operator LPCTSTR operator LPCTSTR ( ) const; Return Value A character pointer to the string’s data. Remarks This useful casting operator provides an efficient method to access the null-terminated C string contained in a CString object. No characters are copied; only a pointer is returned. Be careful with this operator. If you change a CString object after you have obtained the character pointer, you may cause a reallocation of memory that invalidates the pointer. CString Overview | Class Members | Hierarchy Chart

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧