当前位置:软件学习 > 其它软件 >>

关于使用LoadResource、EndUpdateResource的问题

需要操作资源DLL中的资源,自作聪明的将其写成一个如下的类:

[cpp]
#ifndef Unit2H  
#define Unit2H  
#include <windows.h>  
#include <assert.h>  
//---------------------------------------------------------------------------  
class ResDll 

   HMODULE hDll; 
public: 
   ResDll():hDll(NULL) 
   { 
       hDll=LoadLibraryA("res.dll"); 
       assert(hDll); 
   } 
   ~ResDll() 
   { 
       if(hDll) 
       { 
           FreeLibrary(hDll); 
       } 
   } 
   bool GetRes(BYTE *res,int len) 
   { 
       //do something  
   } 
   bool UpdateRes(BYTE *res,int len) 
   { 
       //do something  
   } 
}; 
#endif  
  
//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
#include <windows.h>
#include <assert.h>
//---------------------------------------------------------------------------
class ResDll
{
   HMODULE hDll;
public:
   ResDll():hDll(NULL)
   {
       hDll=LoadLibraryA("res.dll");
       assert(hDll);
   }
   ~ResDll()
   {
       if(hDll)
       {
           FreeLibrary(hDll);
       }
   }
   bool GetRes(BYTE *res,int len)
   {
       //do something
   }
   bool UpdateRes(BYTE *res,int len)
   {
       //do something
   }
};
#endif
 
结果悲剧了,发现只能读,不能写(GetRes成功完成,UpdateRes总是出错)。

出错在EndUpdateResource这句,返回总是为FALSE。

GetLastError为110,原因:系统无法打开指定的设备或文件。

纠结了半天-_-!,突然想起来,windows文件载入时,是禁止写操作的!

而上面的类实例在其生命周期内目标资源模块始终是已载入状态的(析构时才卸载),当然是禁止write的!

所以,

模块的载入卸载应该放在成员函数内的。

郁闷吧,- - 。

记录下这个低级错误。

 

摘自 qq752923276
补充:软件开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,