请高手相助:关于Resource function 的一些古怪 呵呵,高分相送

sdwtao 2002-12-30 05:20:45
我呢需要一个便历指定exe文件指定类型资源的一个程序
然后我这么写了
HMODULE hExe;
hExe = LoadLibrary(szFile);
if (hExe == NULL)
{
AfxMessageBox("Could not load .EXE.");
}

EnumResourceNames(hExe,RT_MENU, // module handle
(ENUMRESNAMEPROC)EnumNamesFunc, // callback function
(LPARAM)GetSafeHwnd()); // extra parameter
// Unload the executable file whose resources were
// enumerated and close the file created to contain
// the resource information.
FreeLibrary(hExe);
return 0;


BOOL CALLBACK EnumNamesFunc(
HMODULE hModule, // module handle
LPCTSTR lpszType, // resource type
LPTSTR lpszName, // resource name
LONG_PTR lParam // application-defined parameter
)
{

CString szString;
// Write the resource name to a resource information file.
// The name may be a string or an unsigned decimal
// integer, so test before printing.
char tmp[100];
strcpy(tmp,lpszName);
if ((ULONG)lpszName & 0xFFFF0000)
{
szString.Format("%s", lpszName);
}
g_szlRet->AddTail(szString);
return TRUE;

}

但是当我跟踪到回调函数EnumNamesFunc内部时 却发现 lpszType 和lpszName 是错误的指针(当然,这是在调试界面的监视窗口看的) 不知道是为什么??

我用的是vc7.0 ,win2000



...全文
90 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdwtao 2002-12-30
  • 打赏
  • 举报
回复
realdreamer(楼主英明,贫僧久仰大名,特来拜见) 兄

确实是 IS_INTRESOURCE(lpszName) 是真

但是我想得到的是个字符串的名字啊,得到这个id有什么用处啊
In355Hz 2002-12-30
  • 打赏
  • 举报
回复
lpszType 和lpszName 可能是一些 <= 0xFFFF 的预定义值:

关于 lpszName 的 MSDN 解释:

If the lpszName parameter is less than 65536 (that is, the upper three words are zero), the low-order word specifies the integer identifier of the given resource. Otherwise, it is a pointer to a null-terminated string.

以下是预定义的Type值:

#define RT_CURSOR MAKEINTRESOURCE(1)
#define RT_BITMAP MAKEINTRESOURCE(2)
#define RT_ICON MAKEINTRESOURCE(3)
#define RT_MENU MAKEINTRESOURCE(4)
#define RT_DIALOG MAKEINTRESOURCE(5)
#define RT_STRING MAKEINTRESOURCE(6)
#define RT_FONTDIR MAKEINTRESOURCE(7)
#define RT_FONT MAKEINTRESOURCE(8)
#define RT_ACCELERATOR MAKEINTRESOURCE(9)
#define RT_RCDATA MAKEINTRESOURCE(10)
#define RT_MESSAGETABLE MAKEINTRESOURCE(11)

注:
#define MAKEINTRESOURCE(i) (LPTSTR)((DWORD)((WORD)(i)))
realdreamer 2002-12-30
  • 打赏
  • 举报
回复
那个CALLBACK 函数在 MSDN 中的备注说明, 看了后就一切皆明了

If IS_INTRESOURCE(x) is TRUE for lpszName or lpszType, x specifies the integer identifier of the given resource. Otherwise, it is a pointer to a null-terminated string. If the first character of the string is a pound sign (#), the remaining characters represent a decimal number that specifies the integer identifier of the resource. For example, the string "#258" represents the identifier 258.

An application must register this function by passing its address to the EnumResourceNames function

sdwtao 2002-12-30
  • 打赏
  • 举报
回复
up

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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