Click here to Skip to main content
15,896,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
}



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


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.]
Posted
Updated 3-Aug-10 10:09am
v2

AfxGetInstanceHandle() is declared in afxwin.h.

Please include
VB
afxwin.h.
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.
 
Share this answer
 
Comments
KingsGambit 5-Aug-10 1:01am    
Reason for my vote of 5
Correct answer
SenAPI 7-Aug-10 6:47am    
Reason for my vote of 4
solution which i am looking
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900