在D:\Program Files\Microsoft Visual Studio\VC98\Include\WINUSER.H 中有这样一段代码:
#define MAKEINTRESOURCEA(i) (LPSTR)((DWORD)((WORD)(i)))
#define MAKEINTRESOURCEW(i) (LPWSTR)((DWORD)((WORD)(i)))
#ifdef UNICODE
#define MAKEINTRESOURCE  MAKEINTRESOURCEW
#else
#define MAKEINTRESOURCE  MAKEINTRESOURCEA
#endif // !UNICODE请问各位大虾强制类型内部是如何实现的?为啥上面的
(LPSTR)((DWORD)((WORD)(i)))
不可以简化成
(LPSTR)(i)呢?

解决方案 »

  1.   

    资源的id不能大于65535, 也就是只能用WORD类型(2个字节)来表示(on x86).
    (WORD)(i)确保了这一点 so as to trim unwanted high bytes.
    then force convert to pointer, because a pointer is expressed by 4 bytes on x86 
    so we have to convert again the WORD to DWORD(4 bytes), finally, convert into LPSTR or LPWSTR for successfully compiling.
      

  2.   

    大虾可否再讲明白点,我在MFC的OnLButtonDown函数做了一个测试程序如下:
    LPSTR pStr1 = (LPSTR)((DWORD)((WORD)(56)));
    LPSTR pStr2 = (LPSTR)((DWORD)(56));
    LPSTR pStr3 = (LPSTR)(56);
    CString str;
    str.Format("pStr1 = %p, pStr2 = %p, pStr3 = %p", pStr1, pStr2, pStr3);
    AfxMessageBox(str);结果是:pStr1 = 00000038, pStr2 = 00000038, pStr3 = 00000038