且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在dll中加载位图

更新时间:2021-12-01 05:47:18

AfxGetInstanceHandle()在afxwin.h中声明.

请在DLL的头文件中包含
AfxGetInstanceHandle() is declared in afxwin.h.

Please include
afxwin.h.

.

在加载资源之前,需要记住调用AFX_MANAGE_STATE(AfxGetStaticModuleState()).如果我们不调用此函数,则将从AfxGetInstanceHandle()返回应用程序的模块状态.从DLL调用AfxGetInstanceHandle()之前,需要切换实例句柄. AFX_MANAGE_STATE(AfxGetStaticModuleState())将通过在调用此宏时更改模块状态,并在退出函数时将模块状态更改为上一个状态来简单地执行此操作.

in ur header file of dll.

Need to remember call AFX_MANAGE_STATE(AfxGetStaticModuleState( )) before loading the resource. If we are not calling this function, the module state of the application will be returned from AfxGetInstanceHandle(). Switching of instance handle is required before calling AfxGetInstanceHandle() from a Dll. AFX_MANAGE_STATE(AfxGetStaticModuleState( )) will simply perform this by changing module state on calling this macro, and changing module state to previous one on exiting the function.


我只想加载位图在dll中,并使用dll返回值.

我认为您需要在两个流程之间共享资源.然后,您应该实现任何进程间通信机制(例如共享内存).

我认为以下方法没问题,
创建一个将读取位图的库(无论何时第一次读取请求来自某个进程),并将其复制到共享内存中.每当进程的其他实例请求相同的位图时,都可以从共享内存中读取它,而无需文件i/o.

您应该处理共享内存名称的任何通用命名机制.
I would just like to load the bitmaps in a dll, and use the dll for returning values.

I think you need to share resource between two processes. Then you should implement any inter process communication mechanism( such as shared memory).

I think following method will be ok,
Create a library which will read bitmap(whenever first read request come from a process) and copy it to shared memory. Whenever other instance of the process request same bitmap, you can read it from shared memory, without file i/o.

You should handle any common naming mechanism for the shared memory name.