Jump to content

Recommended Posts

Posted

All Files

ImageStream.zip

ImageStream.au3

#include <GDIPlus.au3>
#include "InterfaceCall.au3"
#include <ScreenCapture.au3>

$hBMP = _ScreenCapture_Capture("")
$ByteStruct = SaveImageToStream($hBMP,"png")
FileWrite("NewImage.png",Binary(DllStructGetData($ByteStruct,1)))
$hBMP = LoadImageFromStream($ByteStruct)
MsgBox(0,"hBMP","$hBMP ==>" & $hBMP)

Func SaveImageToStream($hBMP,$ImageExt)
;$ImageExt File extension to search for (BMP, JPG, TIF, etc.)
Local $grfMode = BitOR(0x00000002,0x00001000,0x00000010)
Local $HRESULT = DllCall("Ole32.dll","long","StgCreateDocfile","wstr", _
@TempDir & "\CompoundFile.cmp","DWORD",$grfMode,"DWORD",0,"ptr*",0)
if @error Or $HRESULT[0] <> 0 Then Return SetError(1,0,0)
Local $pIStorage = $HRESULT[4]
Local $grfMode = BitOR(0x00000002,0x00000010)
$HRESULT = InterfaceCall($pIStorage,"long",4,"wstr","StreamImage1","DWORD",$grfMode, _
"DWORD",0,"DWORD",0,"ptr*",0) ;CreateStream METHOD
if @error Or $HRESULT[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
Return SetError(2,0,0)
EndIf
Local $IStream = $HRESULT[5] , $BOOL = ($ghGDIPDll == 0)
_GDIPlus_Startup()
Local $sCLSID =_GDIPlus_EncodersGetCLSID($ImageExt)
if @error Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(3,0,0)
EndIf
Local $Bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
if @error Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(4,0,0)
EndIf
Local $tGUID = _WinAPI_GUIDFromString($sCLSID)
if @error Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(5,0,0)
EndIf
Local $Return = DllCall($ghGDIPDll,"int","GdipSaveImageToStream","ptr",$Bitmap,"ptr",$IStream _
, "struct*", $tGUID ,"struct*", 0)
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(6,0,0)
EndIf
Local $tagSTATSTG = "ptr pwcsName;DWORD type;UINT64 cbSize;BYTE mtime[8];BYTE ctime[8];" & _
"BYTE atime[8];DWORD grfMode;DWORD grfLocksSupported;ulong Data1;ushort Data2;" & _
"ushort Data3;byte Data4[8];DWORD grfStateBits;DWORD reserved"
Local $STATSTG = DllStructCreate($tagSTATSTG)
$Return = InterfaceCall($IStream,"long",13,"struct*",$STATSTG,"DWORD",0) ; Stat METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(7,0,0)
EndIf
$cbSize = DllStructGetData($STATSTG,"cbSize")
$ByteStruct = DllStructCreate("BYTE[" & $cbSize & "]")
$Return = InterfaceCall($IStream,"long",6,"INT64",0,"DWORD",0,"UINT64*",0) ; Seek METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(8,0,0)
EndIf
$Return = InterfaceCall($IStream,"long",4,"struct*",$ByteStruct,"ULONG",$cbSize,"ULONG*",0) ;Read METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(9,0,0)
EndIf
InterfaceCall($pIStorage,"long",3) ; Release METHOD
InterfaceCall($IStream,"long",3) ; Release METHOD
if ($BOOL) Then _GDIPlus_Shutdown()
Return $ByteStruct
EndFunc

Func LoadImageFromStream($ByteStruct)
if Not(IsDllStruct($ByteStruct)) Then Return SetError(1,0,0)
Local $grfMode = BitOR(0x00000002,0x00001000,0x00000010)
Local $HRESULT = DllCall("Ole32.dll","long","StgCreateDocfile","wstr", _
@TempDir & "\CompoundFile.cmp","DWORD",$grfMode,"DWORD",0,"ptr*",0)
if @error Or $HRESULT[0] <> 0 Then Return SetError(2,0,0)
Local $pIStorage = $HRESULT[4]
$grfMode = BitOR(0x00000002,0x00000010)
$HRESULT = InterfaceCall($pIStorage,"long",4,"wstr","StreamImage2","DWORD",$grfMode, _
"DWORD",0,"DWORD",0,"ptr*",0) ;CreateStream METHOD
if @error Or $HRESULT[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
Return SetError(3,0,0)
EndIf
Local $IStream = $HRESULT[5]
Local $cbSize = DllStructGetSize($ByteStruct)
$Return = InterfaceCall($IStream,"long",7,"UINT64",$cbSize) ;SetSize METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
Return SetError(4,0,0)
EndIf
$Return = InterfaceCall($IStream,"long",6,"INT64",0,"DWORD",0,"UINT64*",0) ; Seek METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
Return SetError(5,0,0)
EndIf
$Return = InterfaceCall($IStream,"long",5,"struct*",$ByteStruct,"ULONG",$cbSize,"ULONG*",0) ;Write METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
Return SetError(6,0,0)
EndIf
$Return = InterfaceCall($IStream,"long",6,"INT64",0,"DWORD",0,"UINT64*",0) ; Seek METHOD
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
Return SetError(7,0,0)
EndIf
Local $BOOL = ($ghGDIPDll == 0)
_GDIPlus_Startup()
Local $Return = DllCall($ghGDIPDll,"int","GdipLoadImageFromStream","ptr",$IStream,"ptr*", 0)
if @error Or $Return[0] <> 0 Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(8,0,0)
EndIf
Local $image = $Return[2]
Local $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($image)
if @error Then
InterfaceCall($pIStorage,"long",3)
InterfaceCall($IStream,"long",3)
if ($BOOL) Then _GDIPlus_Shutdown()
Return SetError(9,0,0)
EndIf
InterfaceCall($pIStorage,"long",3) ; Release METHOD
InterfaceCall($IStream,"long",3) ; Release METHOD
if ($BOOL) Then _GDIPlus_Shutdown()
Return $hBMP
EndFunc

InterfaceCall.au3

Func InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0,$Type2 = 0,$Param2 = 0 _
,$Type3 = 0,$Param3 = 0, $Type4 = 0,$Param4 = 0 ,$Type5 = 0 ,$Param5 = 0,$Type6 = 0,$Param6 = 0 _
,$Type7 = 0,$Param7 = 0, $Type8 = 0,$Param8 = 0,$Type9 = 0,$Param9 = 0,$Type10 = 0,$Param10 = 0 _
,$Type11= 0,$Param11= 0,$Type12= 0,$Param12= 0,$Type13= 0,$Param13 = 0,$Type14 = 0,$Param14 = 0 _
,$Type15= 0,$Param15= 0,$Type16= 0,$Param16= 0,$Type17= 0,$Param17 = 0,$Type18 = 0,$Param18 = 0 _
,$Type19= 0,$Param19= 0,$Type20= 0,$Param20= 0,$Type21= 0,$Param21 = 0,$Type22 = 0,$Param22 = 0 _
,$Type23= 0,$Param23= 0,$Type24= 0,$Param24= 0,$Type25= 0,$Param25 = 0,$Type26 = 0,$Param26 = 0 _
,$Type27= 0,$Param27= 0,$Type28= 0,$Param28= 0,$Type29= 0,$Param29 = 0,$Type30 = 0,$Param30 = 0)
;;Return Array Of DllCallAddress
;Only Call Virtual Method Form any Class Or From any Interface
;$MethodNum ==> Virtual Method Number In (Virtual Methods Table) ;See the examples
;-------------------------------------------------------------------;C++ Example1
;C++ Example1
;class iClass
;{
;public:
;void MethodA()
;{
;MessageBox(0,"MethodA","MSG",0);
;}
;virtual void VirtualMethodB()
;{
;MessageBox(0,"VirtualMethodB","MSG",0);
;}
;virtual void VirtualMethodC()
;{
;MessageBox(0,"VirtualMethodC","MSG",0);
;}
;void MethodB()
;{
;MessageBox(0,"MethodB","MSG",0);
;}
;virtual void VirtualMethodA()
;{
;MessageBox(0,"VirtualMethodA","MSG",0);
;}
;};
;-----------------------------------------------------------;Virtual Methods Table
;Virtual Methods Table
;virtual void VirtualMethodB() ==> Virtual Method Number Is 1
;virtual void VirtualMethodC() ==> Virtual Method Number Is 2
;virtual void VirtualMethodA() ==> Virtual Method Number Is 3
;-----------------------------------------------------------;Virtual Methods Table
;-------------------------------------------------------------------;C++ Example1

;////////////////////////////////////////////////////////////////////////////////

;-------------------------------------------------------------------;C++ Example2
;C++ Example2
;class iClassA
;{
;public:
;void MethodA()
;{
;MessageBox(0,"MethodA","MSG",0);
;}
;virtual void VirtualMethodB()
;{
;MessageBox(0,"VirtualMethodB","MSG",0);
;}
;virtual void VirtualMethodC()
;{
;MessageBox(0,"VirtualMethodC","MSG",0);
;}
;};

;class iClassB : public iClassA
;{
;public:
;void MethodD()
;{
;MessageBox(0,"MethodD","MSG",0);
;}
;virtual void VirtualMethodF()
;{
;MessageBox(0,"VirtualMethodF","MSG",0);
;}
;virtual void VirtualMethodE()
;{
;MessageBox(0,"VirtualMethodE","MSG",0);
;}
;};
;////////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////////
;------------------------------------------;Virtual Methods Table Of iClassA Class
;Virtual Methods Table Of iClassA Class
;virtual void VirtualMethodB() ==> Virtual Method Number Is 1
;virtual void VirtualMethodC() ==> Virtual Method Number Is 2
;------------------------------------------;Virtual Methods Table Of iClassA Class
;////////////////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////////////
;------------------------------------------;Virtual Methods Table Of iClassB Class
;class iClassB : public iClassA
;base class ==> iClassA
;derived class ==> iClassB
;http://msdn.microsoft.com/en-us/library/hzk8a7d3.aspx
;When preceding the name of a base class, the public keyword specifies that the public
;and protected members of the base class are public and protected members, respectively,
;of the derived class.
;-------------------------------------------------------------------------------------
;Virtual Methods Table Of iClassB Class
;virtual void VirtualMethodB() In (iClassA) ==> Virtual Method Number Is 1
;virtual void VirtualMethodC() In (iClassA) ==> Virtual Method Number Is 2
;virtual void VirtualMethodF() In (iClassB) ==> Virtual Method Number Is 3
;virtual void VirtualMethodE() In (iClassB) ==> Virtual Method Number Is 4
;------------------------------------------;Virtual Methods Table Of iClassB Class
;-------------------------------------------------------------------;C++ Example2
;////////////////////////////////////////////////////////////////////////////////
if Not IsPtr($Inface) Or ($MethodNum < 1) Then Return SetError(1,0,0)
if (@NumParams > 3) And (Mod((@NumParams - 3),2) <> 0) Then Return SetError(2,0,0)
Local $iMethAddress = GetMethodAddress($Inface,$MethodNum)
if Not ($iMethAddress) Then Return SetError(3,0,0)
Local $iDataType = "",$iFuncParam = "",$iCommand = "",$iReturn = 0
;Why use Inface Param In DllCallAddress Function Because the Function of the method
;starts from the (Interface Or class)
;See here
;int class::MethodFunction( int Param ){return 0;};
$iCommand = 'DllCallAddress("' & $ReturnType & '",Eval("iMethAddress"),"ptr",Eval("Inface"),'
For $i = 1 To ((@NumParams - 3) / 2)
$iDataType = Eval("Type" & $i)
$iCommand &= '"' & $iDataType & '",'
$iFuncParam = 'Eval("Param' & $i & '"),'
$iCommand &= $iFuncParam
Next
$iCommand = StringTrimRight($iCommand,1)
$iCommand &= ")"
$iReturn = Execute($iCommand)
if @error Then Return SetError(4,0,0)
Local $nReturn[UBound($iReturn) -1] , $j = 0
For $i = 0 To UBound($iReturn) - 1
if ($i = 1) Then ContinueLoop ;Skip $Inface Element
$nReturn[$j] = $iReturn[$i]
$j += 1
Next
Return SetError(0,0,$nReturn)
EndFunc

Func GetMethodAddress($Inface,$MethodNum)
;$MethodNum ==> Virtual Method Number In (Virtual Methods Table)
Local $SizeOfUlong_Ptr = 4,$iMethAddress = 0,$OutCastStruct1 = 0
Local $OutCast1 = 0 , $OutCastStruct2 = 0
if Not IsPtr($Inface) Or ($MethodNum < 1) Then Return SetError(1,0,0)
;-------------------------------------------------------
$OutCastStruct1 = DllStructCreate("ULONG_PTR",$Inface)
$OutCast1 = DllStructGetData($OutCastStruct1,1)
;In C++ ==> unsigned long** OutCast1 = *(unsigned long***)Inface;
;--------------------------------------------------------
;-------------------------------------------------------
$OutCastStruct2 = DllStructCreate("ULONG_PTR",$OutCast1 + ($SizeOfUlong_Ptr * ($MethodNum - 1)))
$iMethAddress = DllStructGetData($OutCastStruct2,1)
;$OutCast1 + ($SizeOfUlong_Ptr * ($MethodNum - 1)) ==> $OutCast1 Is PTR Array Of Virtual Methods Table // Method PTR = Array[MethodNum - 1]
;In C++ ==> unsigned long* iMethAddress = *(unsigned long**)((BYTE*)OutCast1 + (SizeOfUlong_Ptr * (MethodNum - 1)));
;Or In C++ ==> unsigned long* iMethAddress = OutCast1[MethodNum - 1];
;--------------------------------------------------------
if (IsBadCodePtr($iMethAddress)) Then Return SetError(2,0,0)
Return SetError(0,0,$iMethAddress)
EndFunc

Func GetCount_Of_VirtualMethods($Inface)
Local $SizeOfUlong_Ptr = 4,$iMethAddress = 0,$OutCastStruct1 = 0
Local $OutCast1 = 0 , $OutCastStruct2 = 0 , $MethodNum = 1
if Not IsPtr($Inface) Then Return SetError(1,0,0)
;-------------------------------------------------------
$OutCastStruct1 = DllStructCreate("ULONG_PTR",$Inface)
$OutCast1 = DllStructGetData($OutCastStruct1,1)
;In C++ ==> unsigned long** OutCast1 = *(unsigned long***)Inface;
;--------------------------------------------------------
While 1
;-------------------------------------------------------
$OutCastStruct2 = DllStructCreate("ULONG_PTR",DllStructGetData($OutCastStruct1,1) + ($SizeOfUlong_Ptr * ($MethodNum - 1)))
$iMethAddress = DllStructGetData($OutCastStruct2,1)
;$OutCast1 + ($SizeOfUlong_Ptr * ($MethodNum - 1)) ==> $OutCast1 Is PTR Array Of Virtual Methods Table // Method PTR = Array[MethodNum - 1]
;In C++ ==> unsigned long* iMethAddress = *(unsigned long**)((BYTE*)OutCast1 + (SizeOfUlong_Ptr * (MethodNum - 1)));
;Or In C++ ==> unsigned long* iMethAddress = OutCast1[MethodNum - 1];
;--------------------------------------------------------
if (IsBadCodePtr($iMethAddress)) Then
$MethodNum -= 1
ExitLoop
Else
$MethodNum += 1
EndIf
WEnd
Return SetError(0,0,$MethodNum)
EndFunc

Func IsBadCodePtr($lpfn)
Local $iReturn
$iReturn = DllCall("Kernel32.dll","BOOL","IsBadCodePtr","ptr",$lpfn)
if @error Then Return SetError(1,0,0)
Return SetError(0,0,$iReturn[0])
EndFunc

Func CLSIDFromString($psz)
$GUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
$Oleerror = DllCall("Ole32.dll","int","CLSIDFromString","WSTR",$psz,"struct*",$GUID)
if @error Or $Oleerror[0] <> 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Oleerror[2])
EndFunc

Func IIDFromString($psz)
$GUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
$Oleerror = DllCall("Ole32.dll","int","IIDFromString","WSTR",$psz,"struct*",$GUID)
if @error Or $Oleerror[0] <> 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Oleerror[2])
EndFunc

صرح السماء كان هنا

 

Posted

Any description? :whistle:

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted (edited)

  On 12/13/2012 at 8:34 PM, 'MrCreatoR said:

Any description? :whistle:

Save the image in the stream and Load it from the stream

Two methods are opening the use of images from the memory without

saving the images on the hard disk so that it can send images directly

to another computer on the network

Edited by wolf9228

صرح السماء كان هنا

 

Posted

  On 12/13/2012 at 8:45 PM, 'UEZ said:

A flew over the code and it looks like these functions: and but using OO interface.

Br,

UEZ

Thank you

Many ways enrich the understanding of the receiver

صرح السماء كان هنا

 

Posted

Indeed, many ways lead to rome. I like your way of coding - it's WinAPI under the hood any many things to learn from it!

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...