在dll中加载位图 [英] Load Bitmap in a dll

查看:92
本文介绍了在dll中加载位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

Hello,

HDC LoadBitmapToHDC(LPCTSTR bitmap_name, HBITMAP& hBitmap )
{
	hBitmap = ::LoadBitmap(::AfxGetInstanceHandle(), bitmap_name);
	// Create a MemDC to draw to.
	HDC MemDC = ::CreateCompatibleDC(NULL);
	SelectObject(MemDC, hBitmap);
	return MemDC;
}




我已经能够在应用程序中使用以上内容.

但是,我现在正尝试将函数移到DLL中.

我收到错误消息:




I have been able to use the above in an application.

However, I am now trying to move the function into a DLL.

I am getting an error message:

error C2039: AfxGetInstanceHandle: is not a member of global namespace



如何更正此错误?

在此先感谢.

[更新:]
谢谢您的回复.
添加头文件后,我已经能够编译应用程序.

我现在遇到运行时错误.

我不尝试导出此功能.我正在尝试减少将相同的位图加载到内存中的所有应用程序实例.
也许我在做什么是错误的.我可能别无选择,只能用相同的位图加载所有正在运行的实例.

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

示例:如果我正在应用程序的所有3个实例中加载猫,狮子和桌子的位图.我要将它们加载3次3位图.
我希望这一次将所有3个文件加载到dll中,并使用其余的逻辑向我返回整数值.

我希望我对我打算做的事情解释得更清楚了吗?

[修改:通过发布不是答案的答案",不要在您的原始问题上添加更多内容.修改原始帖子以包含新信息或提出新问题.]



How do I correct this error?

Thanks in Advance.

[Update:]
Thank you for your response.
I have been able to compile the application after adding the header file.

I am getting a runtime error now.

I am not trying to export this function. I am trying to reduce all instances of applications from loading the same bitmaps into memory.
Maybe what I am doing is wrong. I might have no choice but to load all my running instances with the same bitmaps.

I would just like to load the bitmaps in a dll, and use the dll for returning values.

Example: If I am loading a bitmap of a cat, lion and table, in all 3 instances of my application. I am going to be loading them 3 times 3 bitmaps.
I want this to became load all 3 in a dll once and use the rest of the logic to return me values which are integer.

I hope I have explained a bit clearer as to what I intend to do?

[Modified: do not add more to your original question by posting an "answer" that isn''t an answer. Modify the original post to include the new information or ask a new question.]

推荐答案

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.


这篇关于在dll中加载位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆