Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieve images from EXE
Message
 
To
28/08/2007 08:57:27
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01250756
Message ID:
01251300
Views:
31
Hi Cesar,

the following code loads an image that has been loaded into memory with FILETOSTR(). I tested it in the xfcBitmap class.
*========================================================================================
* This function bases on code published by Karl E. Peterson for VB:
*  http://vb.mvps.org/samples/project.asp?id=netcam
* His code was inspired by the work of Brad Martinez.
*  http://btmtz.mvps.org/_misc/index.htm
*========================================================================================
FUNCTION FromMemory( tcPicture )

	*--------------------------------------------------------------------------------------
	* API declarations
	*
	* Source: http://news2news.com
	*--------------------------------------------------------------------------------------
	DECLARE INTEGER GlobalAlloc IN kernel32;
    INTEGER wFlags,;
    INTEGER dwBytes
	DECLARE INTEGER GlobalLock IN kernel32;
    INTEGER hMem
	DECLARE RtlMoveMemory IN kernel32 As CopyMemory; 
    Integer Destination,; 
    String @  Source,; 
    INTEGER   nLength
	DECLARE INTEGER GlobalUnlock IN kernel32;
    INTEGER hMem
	DECLARE INTEGER CreateStreamOnHGlobal IN ole32;
    INTEGER   hGlobal,;
    INTEGER   fDeleteOnRelease,;
    INTEGER @ ppstm
  DECLARE INTEGER GlobalFree IN kernel32;
    INTEGER hMem          
     
	*--------------------------------------------------------------------------------------
	* Calculate the array size
	*--------------------------------------------------------------------------------------
	Local nBytes
	nBytes = Len(m.tcPicture)

	*--------------------------------------------------------------------------------------
	* Create and lock a memory buffer for image bytes. Copy image bytes to memory buffer, 
	* and unlock. Create an IStream object in global memory buffer.
	*--------------------------------------------------------------------------------------
	Local hMem, lpMem, oStream
	hMem = GlobalAlloc(GMEM_MOVEABLE, nBytes)
	If hMem != 0
		lpMem = GlobalLock(hMem)
    If lpMem != 0
			CopyMemory(lpMem, m.tcPicture, nBytes)
			GlobalUnlock(hMem)
			oStream = 0
			If CreateStreamOnHGlobal(hMem, 0, @oStream) = 0
				LOCAL loBitmap, lhBitmap
				m.lhBitmap = 0
				m.loBitmap = NULL
				This.SetStatus(xfcGdipCreateBitmapFromStream(m.oStream, @lhBitmap))
				IF(m.lhBitmap <> 0)
					m.loBitmap = CREATEOBJECT("xfcBitmap")
					m.loBitmap.Handle = m.lhBitmap
				ENDIF			
			EndIf 
		EndIf 
		GlobalFree(hMem)
	EndIf

RETURN m.loBitmap
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform