Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Developers, i am going to get IMAGE in C# FROM a c++ DIB Win32 Handler.
Using manage wrapping techniques i wrap all other function and get all other value from unmanageable LIB File.. this time i wanna Wrap this Function

C++
HGLOBAL XRaySensorGetDIB(void);   


and Return Bitmap or byte Array (Image) and get Output Bitmap or byte Array Image in my C# Project....

thanks in advance

What I have tried:

here is some code of my c++/CLI Managed Wrapping
C++
HBITMAP managedDllWrapper::ManageFunctionWrapper::SaveImageWrapper()
{
	  HGLOBAL m_hDib;
	 int retval = XRaySensorIsImageAvailable();

        if ( 0 < retval )
        {
            if (m_hDib ) ::GlobalFree(m_hDib);
            m_hDib = XRaySensorGetDIB();
		}
	
		HBITMAP bmi=new HBITMAP();
		bmi=&m_hDib;
		return bmi;  
}
Posted
Updated 23-May-16 22:14pm
v2

This might help: DIB to System.Bitmap[^]
 
Share this answer
 
Comments
George Jonsson 24-May-16 4:20am    
Wouldn't this method do the job?
Image.FromHbitmap Method (IntPtr) (System.Drawing)[^]
I am sorry to tell you, that you are missing the needed knowledge about bitmaps. Here is a good starting point in the Microsoft documentation. Please take a deeper look at the different CreateBitmap and BitBlt function to understand the HBITMAP. It is a handle to a system object and needs a lot of care. ;-)

My idea and knowledge would go the other way by providing the data from C# and fill it in C++.

cook book

1. ask for the size
2. allocate in C# a bitmap and transfer the handle or the buffer
3. copy the bitmap into the bitmap handle or get the bits filled in C++

Tip: use the search box and look at different samples
 
Share this answer
 
Comments
Mouzam Basheer 24-May-16 4:25am    
Thanks Karstenk..
i have lack knowledge about c++. please write some code for me.. to wrap this function
HGLOBAL XRaySensorGetDIB(void);

and get any return type that is return an image in my c# project..
KarstenK 26-May-16 5:27am    
Sorry I wont, but a tip for the last step: if you have the bits, you can use https://msdn.microsoft.com/library/zy1a2d14(v=vs.110).aspx

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