#include once "window9.bi"
Using GDIPLUS
Dim shared ULONG_PTR_01 AS ULONG_PTR
DIM GDIPLUSSTARTUPINPUT_01 AS GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
IF (GDIPLUSSTARTUP(@ULONG_PTR_01, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) THEN
	PRINT "FAIL"
EndIf
Function SAVE_image alias "SAVE_image" (ByVal hBitmap As HBITMAP, ByVal NAMES As string) as Integer Export
  Dim clssid As String
	If LCase(Right(Names,3))="bmp" Then
		clssid="{557CF400-1A04-11D3-9A73-0000F81EF32E}"
	ElseIf LCase(Right(Names,4))="jpeg" Or LCase(Right(Names,3))="jpg" Then
		clssid="{557CF401-1A04-11D3-9A73-0000F81EF32E}"
	ElseIf LCase(Right(Names,3))="gif" Then
		clssid="{557CF402-1A04-11D3-9A73-0000F81EF32E}"
	ElseIf LCase(Right(Names,4))="tiff" Then
		clssid="{557CF405-1A04-11D3-9A73-0000F81EF32E}"
	ElseIf LCase(Right(Names,3))="png" Then
		clssid="{557CF406-1A04-11D3-9A73-0000F81EF32E}"
	EndIf
  Dim As GpBitmap Ptr GPIMAGE_01
  GdipCreateBitmapFromHBITMAP(hBitmap, NULL, @GPIMAGE_01)
  DIM CLSID_01 AS CLSID
  CLSIDFROMSTRING WSTR(clssid), @CLSID_01
  Var blen = (Len(names)*2)+2
  Dim As WString Ptr wbuf
  wbuf  = Allocate( blen )
  MultiByteToWideChar(CP_ACP, 0, StrPtr(names), -1, wbuf, blen)
  IF (GDIPSAVEIMAGETOFILE(Cast(GpImage Ptr,GPIMAGE_01), *wbuf, @CLSID_01 , 0) <> 0) Then
    PRINT "FAIL"
  EndIf
  DeAllocate(wbuf)
  GDIPDISPOSEIMAGE (Cast(GpImage Ptr,GPIMAGE_01))
  Return 1
End Function
