首页 > 编程语言 >C++ AFX_MANAGE_STATE(AfxGetStaticModuleState())的作用

C++ AFX_MANAGE_STATE(AfxGetStaticModuleState())的作用

时间:2022-10-11 21:01:09浏览次数:52  
标签:AfxGetStaticModuleState MANAGE C++ DLL STATE AFX 资源


从AFX_MANAGE_STATE(AfxGetStaticModuleState())说起

 

AFX_MANAGE_STATE(AfxGetStaticModuleState())的作用:用于模块切换时的状态保护,

1.AfxGetStaticModuleState()指向当前模块状态;

2.当前函数调用结束后原模块的状态自动被恢复;

3.用于DLL中所调用MFC函数、类、资源时的模块状态切换;

[MSDN]

By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:

AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope

也就是说,并不是每一个dll的输出函数前都要调用它,只有在要输出对话框等用到资源时才要调用!

dll中资源是共享的,用这个函数的目的是防止不同的进程修改资源从而产生错误!

 

缺省情况下MFC使用主应用程序的资源句柄来载入资源模板,而DLL中的资源模板是存在于DLL模板中,

因此要使用这一语句切换到 DLL 。

 

 

 



标签:AfxGetStaticModuleState,MANAGE,C++,DLL,STATE,AFX,资源
From: https://blog.51cto.com/csnd/5747952

相关文章

  • C++继承模型漫谈
    1、创建子类对象时,会优先创建父类部分,再创建子类部分,也就是子类对象是包含了两部分内容,(父类部分+子类部分)(图1)classTypeA{public:inta=10;voidv(){......
  • <三>从编译器角度理解C++代码的编译和链接原理
    代码点击查看代码**sum.cpp**intgdata=10;intsum(inta,intb){returna+b;}**main.cpp**externintgdata;intsum(int,int);intdata=20;intmain(......
  • C++中class关键字
    在C++语言中​​class​​​是定义类的关键字,C++中也可以使用struct定义类。两者区别是,用​​class​​​定义的类,如果​​数据成员​​​或成员函数没有说明则默认为priva......
  • windows C++ 异常调用栈简析
    楔子以win11+vs2022运行VC++编译观察的结果。如果安装了VisualStudio2022,比如安装在D盘,则路径:D:\VisualStudio\IDE\VC\Tools\MSVC\14.33.31629下面包含了vcrun......
  • C++STL
    STL1.说说STL的基本组成部分STL由6部分组成:容器(Container)、算法(Algorithm)、迭代器(Iterator)、仿函数(Functionobject)、适配器(Adaptor)、空间配制器(Allocator)。容器......
  • Linux下的lua和boost c++的搭建和安装
    先下载lua,boostc++​​http://www.lua.org/versions.html#5.2​​​​http://www.boost.org/​​ ​​http://sourceforge.net/projects/luabind/​​1.安装lua[root@l......
  • 开源状态机代码生成 StateSmith 支持C/C++
     StateSmithStateSmithisacrossplatform,free/opensourcetoolforgeneratingstatemachines.Thegeneratedcodeishumanreadable,haszerodependencies......
  • Java Style的C++容器流式处理类
    很久没有上博客园了,最近一段时间,因为工作的关系时间上比较闲,利用闲暇时间重新翻了一下丢弃很久的C++语言。C++从98、11、14、17目前已经也走到了20版本,发生了很多变化,也引......
  • C++之可变模板参数打印及Pari的逐块式构造(Piecewise Construction)
    classFoo{public:Foo(tuple<int,double>){cout<<"Foo(tuple<int,double>)"<<endl;}template<typenameT>voidprint(Tt)......
  • C++ 右值引用与一级指针
    将右值引用用于一级指针,在初始化时等号右边必须为右值,有以下几种用法://方式一:引用一级指针,常规用法inta=5;int*&&rrpa=&a;//右值:例子一int*getPx(){......