Leaderboard
Popular Content
Showing content with the highest reputation on 01/09/2014 in all areas
-
First Interface call '?do=embed' frameborder='0' data-embedContent>> By the project you can call methods of classes And Interface through DispCallFunc function I think the project is important for all ... Thanks All project files Other_InterfaceCall.zip InterfaceCall.au3 ;enum $tagCALLCONV Global $CC_FASTCALL = 0 Global $CC_CDECL = 1 Global $CC_MSCPASCAL = $CC_CDECL + 1 Global $CC_PASCAL = $CC_MSCPASCAL Global $CC_MACPASCAL = $CC_PASCAL + 1 Global $CC_STDCALL = $CC_MACPASCAL + 1 Global $CC_FPFASTCALL = $CC_STDCALL + 1 Global $CC_SYSCALL = $CC_FPFASTCALL + 1 Global $CC_MPWCDECL = $CC_SYSCALL + 1 Global $CC_MPWPASCAL = $CC_MPWCDECL + 1 Global $CC_MAX = $CC_MPWPASCAL + 1 ;enum $tagCALLCONV Global $OleAut32 = DllOpen("OleAut32.dll") Global $tagVariant = "USHORT vt;WORD wReserved1;WORD wReserved2;WORD wReserved3;byte union[8]" Global $SizeOfUlong_Ptr = DllStructGetSize(DllStructCreate("ULONG_PTR")) 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) ;Call Only Virtual Methods 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 ((@NumParams > 3) And (Mod((@NumParams - 3),2) <> 0)) Then Return SetError(1,0,0) Local $NumParams = ((@NumParams - 3) / 2) Local $nReturn[$NumParams + 1][3], $Variant = 0,$BOOLREF = 0,$RtVariant = 0 Local $Value = "",$DataType = "",$DataTypeNu = 0,$RtTypeNu = 0,$CALLCONV = $CC_STDCALL Local $VARIANTARG = DllStructCreate("PTR[" & $NumParams & "]") Local $VARTYPE = DllStructCreate("WORD[" & $NumParams & "]") $ReturnType = StringUpper($ReturnType) if (StringRight($ReturnType,6) == ";CDECL") Then $ReturnType = StringReplace($ReturnType,";CDECL","") $CALLCONV = $CC_CDECL EndIf For $i = 0 To $NumParams if ($i = 0) Then ; $i = 0 Is Return $DataType = $ReturnType $Value = "" $DataTypeNu = InfaceDataTypeNu($DataType) if @error Then Return SetError(2,0,0) $BOOLREF = @extended $RtTypeNu = $DataTypeNu $Variant = DllStructCreate($tagVariant) $RtVariant = $Variant $nReturn[$i][0] = $Variant DllStructSetData($Variant,"vt",$DataTypeNu) $DataType = StringReplace($DataType,"*","") Else $Value = Eval("Param" & $i) $DataType = Eval("Type" & $i) $DataTypeNu = InfaceDataTypeNu($DataType) if @error Then Return SetError(2,0,0) $BOOLREF = @extended $Variant = DllStructCreate($tagVariant) $nReturn[$i][0] = $Variant DllStructSetData($Variant,"vt",$DataTypeNu) DllStructSetData($VARTYPE,1,$DataTypeNu,$i) DllStructSetData($VARIANTARG,1,DllStructGetPtr($Variant),$i) EndIf $DataType = StringReplace(StringUpper($DataType),"*","") Switch $DataType Case "STR" if ($i = 0) Then $BOOLREF = True ; $i = 0 Is Return Switch $BOOLREF Case True $nReturn[$i][1] = MakByRef() $nReturn[$i][2] = 3 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($nReturn[$i][1])) Case False $StringSt = DllStructCreate("CHAR[" & (StringLen($Value) + 1) & "]") DllStructSetData($StringSt,1,$Value) $nReturn[$i][1] = $StringSt $nReturn[$i][2] = 2 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($StringSt)) EndSwitch Case "WSTR" if ($i = 0) Then $BOOLREF = True ; $i = 0 Is Return Switch $BOOLREF Case True $nReturn[$i][1] = MakByRef() $nReturn[$i][2] = 4 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($nReturn[$i][1])) Case False $StringSt = DllStructCreate("WCHAR[" & (StringLen($Value) + 1) & "]") DllStructSetData($StringSt,1,$Value) $nReturn[$i][1] = $StringSt $nReturn[$i][2] = 2 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($StringSt)) EndSwitch Case "STRUCT" $nReturn[$i][1] = $Value SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($Value)) $nReturn[$i][2] = 0 Case Else Switch $BOOLREF Case True $nReturn[$i][1] = MakByRef($DataType) $nReturn[$i][2] = 1 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($nReturn[$i][1])) Case False $nReturn[$i][1] = $Value $nReturn[$i][2] = 0 SetUnionOfVariant($Variant,$DataType,$Value) EndSwitch EndSwitch Next Local $oVft = ($SizeOfUlong_Ptr * ($MethodNum - 1));$MethodNum ==> Virtual Method Number In Virtual Methods Table Start From 1 $HRESULT = DllCall($OleAut32,"long","DispCallFunc","ptr",$Inface,"ULONG_PTR",$oVft,"int",$CALLCONV _ ,"WORD",$RtTypeNu,"UINT",$NumParams,"struct*",$VARTYPE,"struct*",$VARIANTARG ,"struct*",$RtVariant) if @error Or $HRESULT[0] <> 0 Then Return SetError(3,0,0) Local $vReturn[($NumParams + 1)] For $i = 0 To $NumParams $Value = $nReturn[$i][1] $IsOutDllStruct = $nReturn[$i][2] if ($i = 0) Then ; $i = 0 Is Return Switch $IsOutDllStruct Case 0 ;WtheOut ByRef $vReturn[$i] = GetUnionOfVariant($RtVariant,$ReturnType) Case 1 ;Wthe ByRef $vReturn[$i] = GetByRefValue($Value) Case 3 ;Wthe ByRef Ans String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),False) Case 4 ;Wthe ByRef UniCode String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),True) EndSwitch Else ; Else Params Switch $IsOutDllStruct Case 0 ;WtheOut ByRef $vReturn[$i] = $Value Case 1 ;Wthe ByRef $vReturn[$i] = GetByRefValue($Value) Case 2 ;WtheOut ByRef Ans Or UniCode String Data Type $vReturn[$i] = DllStructGetData($Value,1) ;Get String From $StringSt Case 3 ;Wthe ByRef Ans String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),False) Case 4 ;Wthe ByRef UniCode String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),True) EndSwitch EndIf Next Return $vReturn EndFunc Func StringFromPtr($StringPtr,$UniCode = False) if (Not(IsPtr($StringPtr)) Or $StringPtr = Ptr(0)) Then Return SetError(1,0,"") if ($UniCode) Then $StrLen = DllCall("Kernel32.dll","int","lstrlenW","ptr",$StringPtr) if @error Then Return SetError(2,0,"") $StrLen = $StrLen[0] Return DllStructGetData(DllStructCreate("WCHAR[" & ($StrLen + 1) & "]",$StringPtr),1) Else $StrLen = DllCall("Kernel32.dll","int","lstrlenA","ptr",$StringPtr) if @error Then Return SetError(2,0,"") $StrLen = $StrLen[0] Return DllStructGetData(DllStructCreate("CHAR[" & ($StrLen + 1) & "]",$StringPtr),1) EndIf EndFunc Func InfaceDataTypeNu($DataType) ;VARIANT structure ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221627%28v=vs.85%29.aspx ;VARENUM enumeration ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221170%28v=vs.85%29.aspx Local $DataTypeNu , $VT_BYREF = 0x4000 $DataType = StringUpper($DataType) Switch $DataType Case "STRUCT*","STR","WSTR" $DataType = "PTR" Case "STR*","WSTR*" $DataType = "PTR*" EndSwitch Local $BOOLREF = (StringInStr($DataType,"*") <> 0) $DataType = StringReplace($DataType,"*","") Switch $DataType Case "NONE" $DataTypeNu = 24 Case "BYTE","BOOLEAN" $DataTypeNu = 17 Case "SHORT" $DataTypeNu = 2 Case "USHORT","WORD" $DataTypeNu = 18 Case "INT","LONG","BOOL" $DataTypeNu = 22 Case "UINT","ULONG","DWORD" $DataTypeNu = 23 Case "INT64" $DataTypeNu = 20 Case "UINT64" $DataTypeNu = 21 Case "FLOAT" $DataTypeNu = 4 Case "DOUBLE" $DataTypeNu = 5 ;--------------------------------------------------------------------------------------------- ;_____________ C++ 6.0 wtypes.h __________ ;VT_I8 = 20 ;VT_UI8 = 21 ;VT_I4 = 3 ;VT_UI4 = 19 ;#ifdef _WIN64 ;#define VT_INT_PTR VT_I8 ;#define VT_UINT_PTR VT_UI8 ;#else ;#define VT_INT_PTR VT_I4 ;#define VT_UINT_PTR VT_UI4 ;#endif ;_____________ C++ 6.0 wtypes.h __________ ; _WIN64 Macro Defined for applications for Win64. ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt. Case "HWND" ;32bit(4bytes) integer $DataTypeNu = 3 ;VT_I4 Case "HANDLE" ;32bit(4bytes) integer $DataTypeNu = 3 ;VT_I4 Case "LPARAM","INT_PTR","LONG_PTR","LRESULT" ;32 or 64bit signed integer if (@AutoItX64) Then $DataTypeNu = 20 ;VT_I8 Else $DataTypeNu = 3 ;VT_I4 EndIf Case "PTR","UINT_PTR","ULONG_PTR","DWORD_PTR","WPARAM" ;32 or 64bit unsigned integer if (@AutoItX64) Then $DataTypeNu = 21 ;VT_UI8 Else $DataTypeNu = 19 ;VT_UI4 EndIf ;_____________ C++ 6.0 wtypes.h __________ ;VT_I8 = 20 ;VT_UI8 = 21 ;VT_I4 = 3 ;VT_UI4 = 19 ;#ifdef _WIN64 ;#define VT_INT_PTR VT_I8 ;#define VT_UINT_PTR VT_UI8 ;#else ;#define VT_INT_PTR VT_I4 ;#define VT_UINT_PTR VT_UI4 ;#endif ;_____________ C++ 6.0 wtypes.h __________ ; _WIN64 Macro Defined for applications for Win64. ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt ;--------------------------------------------------------------------------------------------- Case Else Return SetError(1,0,-1) EndSwitch if ($BOOLREF) Then $DataTypeNu = BitOR($VT_BYREF,$DataTypeNu) Return SetError(0,$BOOLREF,$DataTypeNu) EndFunc Func MakByRef($DataType = "ptr") Return DllStructCreate(String($DataType & " ByRef")) EndFunc Func GetByRefValue($ByRefSt) Return DllStructGetData($ByRefSt,1) EndFunc Func SetUnionOfVariant($VariantSt,$DataType,$Value) Return DllStructSetData(DllStructCreate($DataType,DllStructGetPtr($VariantSt,"union")),1,$Value) EndFunc Func GetUnionOfVariant($VariantSt,$DataType) Return DllStructGetData(DllStructCreate($DataType,DllStructGetPtr($VariantSt,"union")),1) 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 IPictureInterface.au3 #include "InterfaceCall.au3" #include <WinAPI.au3> ;IPicture interface---------------------------------------------------------;IPicture interface ;EXTERN_C const IID IID_IPicture; ; ; ; ;#if defined(__cplusplus) && !defined(CINTERFACE) ; ; ; ; MIDL_INTERFACE("7BF80980-BF32-101A-8BBB-00AA00300CAB") ; ; IPicture : public IUnknown ; ; { ; ; public: ; ; virtual HRESULT STDMETHODCALLTYPE get_Handle( ; ; /* [out] */ OLE_HANDLE __RPC_FAR *pHandle) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_hPal( ; ; /* [out] */ OLE_HANDLE __RPC_FAR *phPal) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Type( ; ; /* [out] */ SHORT __RPC_FAR *pType) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Width( ; ; /* [out] */ OLE_XSIZE_HIMETRIC __RPC_FAR *pWidth) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Height( ; ; /* [out] */ OLE_YSIZE_HIMETRIC __RPC_FAR *pHeight) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE Render( ; ; /* [in] */ HDC hDC, ; ; /* [in] */ LONG x, ; ; /* [in] */ LONG y, ; ; /* [in] */ LONG cx, ; ; /* [in] */ LONG cy, ; ; /* [in] */ OLE_XPOS_HIMETRIC xSrc, ; ; /* [in] */ OLE_YPOS_HIMETRIC ySrc, ; ; /* [in] */ OLE_XSIZE_HIMETRIC cxSrc, ; ; /* [in] */ OLE_YSIZE_HIMETRIC cySrc, ; ; /* [in] */ LPCRECT pRcWBounds) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE set_hPal( ; ; /* [in] */ OLE_HANDLE hPal) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_CurDC( ; ; /* [out] */ HDC __RPC_FAR *phDC) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE SelectPicture( ; ; /* [in] */ HDC hDCIn, ; ; /* [out] */ HDC __RPC_FAR *phDCOut, ; ; /* [out] */ OLE_HANDLE __RPC_FAR *phBmpOut) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_KeepOriginalFormat( ; ; /* [out] */ BOOL __RPC_FAR *pKeep) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE put_KeepOriginalFormat( ; ; /* [in] */ BOOL keep) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE PictureChanged( void) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE SaveAsFile( ; ; /* [in] */ LPSTREAM pStream, ; ; /* [in] */ BOOL fSaveMemCopy, ; ; /* [out] */ LONG __RPC_FAR *pCbSize) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Attributes( ; ; /* [out] */ DWORD __RPC_FAR *pDwAttr) = 0; ; ; ; ; }; ;IPicture interface---------------------------------------------------------;IPicture interface ;------------------------------- ;IPicture : public IUnknown ;-------------------------------- ;base class ==> IUnknown ;derived class ==> IPicture ;--------------------------------- ;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. ;--------------------------------- ;IUnknown interface---------------------------------------------------------;IUnknown interface ;#if (_MSC_VER >= 1100) && defined(__cplusplus) && !defined(CINTERFACE) ; ; EXTERN_C const IID IID_IUnknown; ; ; extern "C++" ; ; { ; ; MIDL_INTERFACE("00000000-0000-0000-C000-000000000046") ; ; IUnknown ; ; { ; ; public: ; ; BEGIN_INTERFACE ; ; virtual HRESULT STDMETHODCALLTYPE QueryInterface( ; ; /* [in] */ REFIID riid, ; ; /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject) = 0; ; ; ; ; virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0; ; ; ; ; virtual ULONG STDMETHODCALLTYPE Release( void) = 0; ; ; ; ; template<class Q> ; ; HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp) ; ; { ; ; return QueryInterface(__uuidof(Q), (void **)pp); ; ; } ; ; ; ; END_INTERFACE ; ; }; ;IUnknown interface---------------------------------------------------------;IUnknown interface ;------------------------------------------;Virtual Methods Table Of IPicture interface ;Virtual Methods Table Of IPicture interface ;virtual HRESULT QueryInterface() In (IUnknown interface) ==> Virtual Method Number Is 1 ;virtual ULONG AddRef() In (IUnknown interface) ==> Virtual Method Number Is 2 ;virtual ULONG Release() In (IUnknown interface) ==> Virtual Method Number Is 3 ;virtual HRESULT get_Handle() In (IPicture interface) ==> Virtual Method Number Is 4 ;virtual HRESULT get_hPal() In (IPicture interface) ==> Virtual Method Number Is 5 ;virtual HRESULT get_Type() In (IPicture interface) ==> Virtual Method Number Is 6 ;virtual HRESULT get_Width() In (IPicture interface) ==> Virtual Method Number Is 7 ;virtual HRESULT get_Height() In (IPicture interface) ==> Virtual Method Number Is 8 ;virtual HRESULT Render() In (IPicture interface) ==> Virtual Method Number Is 9 ;virtual HRESULT set_hPal() In (IPicture interface) ==> Virtual Method Number Is 10 ;virtual HRESULT get_CurDC() In (IPicture interface) ==> Virtual Method Number Is 11 ;virtual HRESULT SelectPicture() In (IPicture interface) ==> Virtual Method Number Is 12 ;virtual HRESULT get_KeepOriginalFormat() In (IPicture interface) ==> Virtual Method Number Is 13 ;virtual HRESULT put_KeepOriginalFormat() In (IPicture interface) ==> Virtual Method Number Is 14 ;virtual HRESULT PictureChanged() In (IPicture interface) ==> Virtual Method Number Is 15 ;virtual HRESULT SaveAsFile() In (IPicture interface) ==> Virtual Method Number Is 16 ;virtual HRESULT get_Attributes() In (IPicture interface) ==> Virtual Method Number Is 17 ;The Count Of Virtual Methods Is 17 ;------------------------------------------;Virtual Methods Table Of IPicture interface $IPicture = GetIPictureInterface("Image.jpg") ;-------------------------------------------------- ;-------------------------------------------------- ;////////////////////////////////////////////////// ;-------------------------------------------------- ; C++ virtual HRESULT STDMETHODCALLTYPE get_Handle(OLE_HANDLE __RPC_FAR *pHandle); ;get_Handle() Virtual Method Number Is 4 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 4 // Virtual Method Number ;$Type1 = "ptr*" Out Ptr ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",4,"ptr*",0) ;Return Array Of DllCallAddress if Not @error Then $Handle = $Rt[1] MsgBox(0,"get_Handle","Image Handle Is " & $Handle) EndIf ;-------------------------------------------------- ;////////////////////////////////////////////////// ;C ++ virtual HRESULT STDMETHODCALLTYPE get_Type(SHORT __RPC_FAR *pType); ;get_Type() Virtual Method Number Is 6 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 6 // Virtual Method Number ;$Type1 = "SHORT*" Out SHORT ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",6,"SHORT*",0) ;Return Array Of DllCallAddress if Not @error Then $Type = $Rt[1] MsgBox(0,"get_Type()","Image Type Is " & $Type) EndIf ;virtual HRESULT STDMETHODCALLTYPE get_Width(OLE_XSIZE_HIMETRIC __RPC_FAR *pWidth); ;get_Width() Virtual Method Number Is 7 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 7 // Virtual Method Number ;$Type1 = "LONG*" Out LONG Or Out OLE_XSIZE_HIMETRIC ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",7,"LONG*",0) ;Return Array Of DllCallAddress if Not @error Then $Width = $Rt[1] $Width = MulDiv($Width,GetDeviceCaps(GetDC(0),88),2540); 88 => LOGPIXELSX MsgBox(0,"get_Width()","Image Width Is " & $Width) EndIf ;C++ virtual HRESULT STDMETHODCALLTYPE get_Height(OLE_YSIZE_HIMETRIC __RPC_FAR *pHeight) ;get_Height() Virtual Method Number Is 8 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 8 // Virtual Method Number ;$Type1 = "LONG*" Out LONG Or Out OLE_YSIZE_HIMETRIC ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",8,"LONG*",0) ;Return Array Of DllCallAddress if Not @error Then $Height = $Rt[1] $Height = MulDiv($Height,GetDeviceCaps(GetDC(0),90),2540); 90 => LOGPIXELSY MsgBox(0,"get_Height()","Image Height Is " & $Height) EndIf Func GetIPictureInterface($ImageFileName) Local $nBytes $FileSize = FileGetSize($ImageFileName) + 1 if @error Then Return SetError(1,0,0) $tBuffer = DllStructCreate("byte[" & $FileSize & "]") $hFile = _WinAPI_CreateFile($ImageFileName, 2, 2) if @error Then Return SetError(2,0,0) _WinAPI_ReadFile($hFile,DllStructGetPtr($tBuffer),$FileSize,$nBytes) if @error Then Return SetError(3,0,0) _WinAPI_CloseHandle($hFile) $LPVOID = DllStructGetPtr($tBuffer) $hMem = GlobalAlloc(0x0042,$FileSize) ;$GHND = 0x0042 if @error Then SetError(4,0,0) $hLock = GlobalLock($hMem) if @error Then GlobalFree($hMem) Return SetError(5,0,0) EndIf MoveMemory($LPVOID,$hLock,$FileSize) $lpstream = CreateStreamOnHGlobal($hLock,True) if @error Then SetError(6,0,0) $riid = IIDFromString("{7BF80980-BF32-101A-8BBB-00AA00300CAB}") if @error Then SetError(7,0,0) $HRESULT = DllCall($OleAut32,"LONG","OleLoadPicture","PTR",$lpstream,"LONG", _ $FileSize,"BOOL",True,"ptr",DllStructGetPtr($riid),"PTR*",0) if @error Or $HRESULT[0] <> 0 Then GlobalUnlock($hMem) GlobalFree($hMem) Return SetError(8,0,0) EndIf GlobalUnlock($hMem) GlobalFree($hMem) $IPicture = $HRESULT[5] Return SetError(0,0,$IPicture) EndFunc Func GlobalAlloc($uFlags,$dwBytes) $HGLOBAL = DllCall("Kernel32.dll","ptr","GlobalAlloc","UINT",$uFlags,"ULONG_PTR",$dwBytes) if @error Or $HGLOBAL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$HGLOBAL[0]) EndFunc Func GlobalLock($hMem) $LPVOID = DllCall("Kernel32.dll","ptr","GlobalLock","ptr",$hMem) if @error Or $LPVOID[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$LPVOID[0]) EndFunc Func GlobalUnlock($hMem) $BOOL = DllCall("Kernel32.dll","BOOL","GlobalUnlock","ptr",$hMem) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,$BOOL[0]) EndFunc Func GlobalFree($hMem) $HGLOBAL = DllCall("Kernel32.dll","ULONG_PTR","GlobalFree","ptr",$hMem) if (@error Or ($HGLOBAL[0])) Then Return SetError(1,0,$HGLOBAL[0]) Return SetError(0,0,0) EndFunc Func CreateStreamOnHGlobal($hGlobal,$fDeleteOnRelease) $WINOLE = DllCall("Ole32.dll","PTR","CreateStreamOnHGlobal","ptr",$hGlobal,"BOOL",$fDeleteOnRelease _ ,"PTR*",0) if @error Or $WINOLE[0] <> 0 Then Return SetError(1,0,0) Return SetError(0,0,$WINOLE[3]) EndFunc Func MulDiv($nNumber,$nNumerator,$nDenominator) $Rt = DllCall("Kernel32.dll","int","MulDiv","int",$nNumber,"int",$nNumerator,"int",$nDenominator) Return $Rt[0] EndFunc Func GetDeviceCaps($hdc,$nIndex) $Rt = DllCall("Gdi32.dll","int","GetDeviceCaps","ptr",$hdc,"int",$nIndex) Return $Rt[0] EndFunc Func GetDC($hWnd) $HDC = DllCall("User32.dll","ptr","GetDC","ptr",$hWnd) if @error Or $HDC[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$HDC[0]) EndFunc Func MoveMemory($Source,$Destination,$Length) DllCall("Kernel32.dll","none","RtlMoveMemory","PTR",$Destination,"PTR",$Source,"INT",$Length) EndFunc IRichEditOleInterface.au3 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <SendMessage.au3> #include "InterfaceCall.au3" $hGui = GUICreate("InsertObject Example",500,390) $hRichEdit = _GUICtrlRichEdit_Create($hGui,"", 10, 10,480,300, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $Button1 = GUICtrlCreateButton("InsertObject",10,320,200,50) GUICtrlSetFont(-1,18,600) GUISetState() InsertObject($hRichEdit,@ScriptDir & "\Image.bmp") While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit Case $iMsg = $Button1 $var = FileOpenDialog("", @MyDocumentsDir & "\","All (*.*)", 1 + 4) if Not @error Then InsertObject($hRichEdit,$var) EndIf EndSelect WEnd ;http://msdn.microsoft.com/en-us/library/windows/desktop/dd387916%28v=vs.85%29.aspx ;Use a Rich Edit Interface ;Rich edit controls expose some of their functionality through Component Object Model ;(COM) interfaces. By obtaining an interface from a control, you gain the ability to ;work with other objects within the control. You can obtain this interface by sending ;the EM_GETOLEINTERFACE message. From the IRichEditOle interface, you can then obtain ;interfaces used in the Text Object Model. ;Another interface, IRichEditOleCallback, is implemented by applications to define the ;behavior of the control when it interacts with objects. ;Insert an Object into a Rich Edit Control ;The following code example inserts a file object into a rich edit control. If a program ;is associated with the file type on the user's machine (for example, Microsoft Excel for ;an .xls file), the contents of the file display in the control; otherwise, an icon appears. Func InsertObject($hRichEdit,$pszFileName) Local $hr = 0, $Rt = 0 , $EM_GETOLEINTERFACE = 1084 , $pRichEditOle = 0 $pRichEditOle = _SendMessage($hRichEdit,$EM_GETOLEINTERFACE,0,0,4,"wparam","ptr*") if ($pRichEditOle == 0) Then return FALSE; EndIf Local $pLockBytes = 0 $hr = DllCall("Ole32.dll","long","CreateILockBytesOnHGlobal","ptr",0,"BOOL",True,"Ptr*",0) if (@error Or $hr[0] <> 0) Then return FALSE; EndIf $pLockBytes = $hr[3] Local $pStorage = 0 $hr = DllCall("Ole32.dll","long","StgCreateDocfileOnILockBytes","ptr",$pLockBytes, _ "DWORD",BitOR(0x00000010,0x00001000,0x00000002), _ "DWORD",0,"Ptr*",0) if (@error Or $hr[0] <> 0) Then return FALSE; EndIf $pStorage = $hr[4] $tagFORMATETC = "int cfFormat;ptr ptd;DWORD dwAspect;LONG lindex;DWORD tymed" $formatEtc = DllStructCreate($tagFORMATETC) DllStructSetData($formatEtc,"cfFormat",0) DllStructSetData($formatEtc,"ptd",0) DllStructSetData($formatEtc,"dwAspect",1) DllStructSetData($formatEtc,"lindex",-1) DllStructSetData($formatEtc,"tymed",0) Local $pClientSite ;hr = pRichEditOle->GetClientSite(&pClientSite); ;GetClientSite Virtual Method Number Of GetClientSite Is 4 in (IRichEditOle interface) $hr = InterfaceCall($pRichEditOle,"long",4,"ptr*",0) if (@error Or $hr[0] <> 0) Then return FALSE; EndIf $pClientSite = $hr[1] Local $pUnk,$clsid = CLSIDFromString("{00000000-0000-0000-0000-000000000000}") Local $IID_IUnknown = IIDFromString("{00000000-0000-0000-C000-000000000046}") $hr = DllCall("Ole32.dll","long","OleCreateFromFile","ptr",DllStructGetPtr($clsid),"wstr", _ $pszFileName,"ptr",DllStructGetPtr($IID_IUnknown),"DWORD",1,"ptr",DllStructGetPtr($formatEtc) _ ,"ptr",$pClientSite,"ptr",$pStorage,"Ptr*",0) ;pClientSite->Release(); ;IOleClientSite interface inherits from the IUnknown Or IOleClientSite : public IUnknown ;Release() Virtual Method Number Of Release() Is 3 In (IOleClientSite interface) InterfaceCall($pClientSite,"long",3) if ($hr[0] <> 0) Then return FALSE; EndIf $pUnk = $hr[8] Local $pObject,$IID_IOleObject = IIDFromString("{00000112-0000-0000-C000-000000000046}") ;hr = pUnk->QueryInterface(IID_IOleObject, (void**)&pObject); ;New pUnk (IOleObject) interface inherits from the IUnknown Or IOleObject : public IUnknown ;QueryInterface() Virtual Method Number Of QueryInterface() Is 1 In (IOleObject) $hr = InterfaceCall($pUnk,"long",1,"ptr",DllStructGetPtr($IID_IOleObject),"ptr*",0) ;Release() Virtual Method Number Of Release() Is 3 In (IOleObject interface) ;pUnk->Release(); InterfaceCall($pUnk,"long",3) if ($hr[0] <> 0) Then return FALSE; EndIf $pObject = $hr[2] DllCall("Ole32.dll","long","OleSetContainedObject","ptr",$pObject,"BOOL",True) $tagREOBJECT = "DWORD cbStruct;LONG cp;ulong Data1;ushort Data2;ushort Data3;byte Data4[8]" & _ ";ptr poleobj;ptr pstg;ptr polesite;long x;long y;DWORD dvaspect;DWORD dwFlags;DWORD dwUser" $reobject = DllStructCreate($tagREOBJECT) DllStructSetData($reobject,"cbStruct",DllStructGetSize($reobject)) ;hr = pObject->GetUserClassID(&clsid); ;GetUserClassID Virtual Method Number Of GetUserClassID Is 16 in (IOleObject interface) $hr = InterfaceCall($pObject,"long",16,"ptr",DllStructGetPtr($clsid)) if (@error Or $hr[0] <> 0) Then ;pObject->Release(); ;Release() Virtual Method Number Of Release() Is 3 In (IOleObject interface) InterfaceCall($pObject,"long",3) return FALSE EndIf MoveMemory(DllStructGetPtr($clsid),DllStructGetPtr($reobject) + 8,16) ;8 ==> SizeOf "DWORD cbStruct;LONG cp;" ;16 ==> sizeOf $clsid DllStructSetData($reobject,"cp",-1) DllStructSetData($reobject,"dvaspect",1) DllStructSetData($reobject,"dwFlags",BitOR(0x00000001,0x00000002)) DllStructSetData($reobject,"dwUser",0) DllStructSetData($reobject,"poleobj",$pObject) DllStructSetData($reobject,"polesite",$pClientSite) DllStructSetData($reobject,"pstg",$pStorage) $SIZEL = DllStructCreate("long;long"); DllStructSetData($reobject,"SIZEL",DllStructGetPtr($SIZEL)) _SendMessage($hRichEdit, 0xB1, 0, -1);EM_SETSEL $Rt = _SendMessage($hRichEdit, 0xB0,0,0,-1,"DWORD*","DWORD*");EM_GETSEL Local $dwStart = $Rt[3], $dwEnd = $Rt[4] _SendMessage($hRichEdit,0xB1, $dwEnd+1, $dwEnd+1);EM_SETSEL _SendMessage($hRichEdit, 0xC2, TRUE,@CRLF,0,"BOOL","wstr");EM_REPLACESEL ;hr = pRichEditOle->InsertObject(&reobject); ;InsertObject Virtual Method Number Of InsertObject Is 8 in (IRichEditOle interface) $hr = InterfaceCall($pRichEditOle,"long",8,"ptr",DllStructGetPtr($reobject)) ;pObject->Release(); ;Release() Virtual Method Number Of Release() Is 3 In (IOleObject interface) InterfaceCall($pObject,"long",3) ;pRichEditOle->Release(); ;Release() Virtual Method Number Of Release() Is 3 In (IRichEditOle interface) InterfaceCall($pRichEditOle,"long",3) if ($hr[0] <> 0) Then return FALSE; EndIf return TRUE; EndFunc Func MoveMemory($Source,$Destination,$Length) DllCall("Kernel32.dll","none","RtlMoveMemory","PTR",$Destination,"PTR",$Source,"INT",$Length) EndFunc3 points
-
SHELLHOOK example of using WinAPI functions.
BinaryBrother reacted to guinness for a topic
An example of monitoring when windows are created, closed or re-drawn. I just noticed there is an example (similar to mine) in the AutoIt beta v3.3.9.6+, though the more examples there are the better understanding users will have. #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> Example() Func Example() Local $hGUI = GUICreate('An(other) example by guinness - 2013', Default, Default) ; Create a GUI. GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK') ; Define a window message and assign to the WM_SHELLHOOK function. _WinAPI_RegisterShellHookWindow($hGUI) ; Register the shell hook message to our GUI. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _WinAPI_DeregisterShellHookWindow($hGUI) GUIDelete($hGUI) EndFunc ;==>Example Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg Switch $wParam Case $HSHELL_GETMINRECT ConsoleWrite('Minimised/Maximised: ' & @CRLF & _ @TAB & 'PID: ' & WinGetProcess($lParam) & @CRLF & _ ; This is the PID. @TAB & 'Filename: ' & _WinAPI_GetWindowFileName($lParam) & @CRLF & _ ; This is the filepath of the window. @TAB & 'hWnd: ' & $lParam & @CRLF) ; This will be the handle of the window closed. Case $HSHELL_REDRAW ConsoleWrite('Redrawn: ' & @CRLF & _ @TAB & 'PID: ' & WinGetProcess($lParam) & @CRLF & _ ; This is the PID. @TAB & 'Filename: ' & _WinAPI_GetWindowFileName($lParam) & @CRLF & _ ; This is the filepath of the window. @TAB & 'hWnd: ' & $lParam & @CRLF) ; This will be the handle of the window closed. Case $HSHELL_WINDOWCREATED ConsoleWrite('Created: ' & @CRLF & _ @TAB & 'PID: ' & WinGetProcess($lParam) & @CRLF & _ ; This is the PID. @TAB & 'Filename: ' & _WinAPI_GetWindowFileName($lParam) & @CRLF & _ ; This is the filepath of the window. @TAB & 'hWnd: ' & $lParam & @CRLF) ; This will be the handle of the window closed. Case $HSHELL_WINDOWDESTROYED ConsoleWrite('Destroyed: ' & @CRLF & _ @TAB & 'PID: ' & WinGetProcess($lParam) & @CRLF & _ ; This will be -1. @TAB & 'Filename: ' & _WinAPI_GetWindowFileName($lParam) & @CRLF & _ ; This will be empty. @TAB & 'hWnd: ' & $lParam & @CRLF) ; This will be the handle of the window closed. Case $HSHELL_WINDOWREPLACED ConsoleWrite('Replaced: ' & @CRLF & _ @TAB & 'PID: ' & WinGetProcess($lParam) & @CRLF & _ ; This is the PID. @TAB & 'Filename: ' & _WinAPI_GetWindowFileName($lParam) & @CRLF & _ ; This is the filepath of the window. @TAB & 'hWnd: ' & $lParam & @CRLF) ; This will be the handle of the window closed. EndSwitch EndFunc ;==>WM_SHELLHOOK1 point -
1 point
-
Servant, That file, along with a whole raft of other ###Constants files, was introduced with the new 3.3.10.# release - the idea was to reduce the size of the individual #include files by splitting the previous larger ones. So download and install the latest release (and perhaps the latest Beta) and these files will be available to you. M231 point
-
Cursor part is done. To encorporate multiple edit lists global variables just should be converted to arrays so that data of multiple items could be added and retreived, converting the whole script back to using arrays would consume much time. I leave it to you as this isn't that hard. Regards1 point
-
close youtube when opening game launcher
Antron99 reacted to kaotkbliss for a topic
oops, looks like the $ before gamexe got removed. should have been easy enough for you to figure out. btw, that code as-is won't do anything because I doubt you actually have processes called game1.exe, game2.exe and game3.exe running on your pc. You're supposed to replace that with the exes for the games you want to check for.1 point -
I'm finding users adjusting the default screen DPI setting far more often in Windows 7 than I ever experienced with Windows XP. Perhaps the setting is now more prominently displayed or easily found than when is was in the advanced section of the settings tab of the display options window. Most commercial applications seem to adapt to the DPI value without a glitch, but Autoit only partially conforms to this system-wide setting. The fonts within controls are affected, yet the overall control dimensions are not. The result are labels, buttons, etc, with txt that is truncated or unreadable. Some special controls or API functions in Autoit, like calendar, are also affected by the DPI setting. I've overridden non-default DPI settings by calling this at the top of programs: Func GetDPI_Ratio() Local $hWnd = 0 Local $hDC = DllCall("user32.dll", "long", "GetDC", "long", $hWnd) Local $aRet = DllCall("gdi32.dll", "long", "GetDeviceCaps", "long", $hDC[0], "long", 90) $hDC = DllCall("user32.dll", "long", "ReleaseDC", "long", $hWnd, "long", $hDC) If $aRet[0] = 0 Then $aRet[0] = 96 Return $aRet[0] / 96 EndFunc It returns an $iDPI_Ratio global such as 1 or 1.25. I then replace all calls to GUISetFont() and GUICtrlSetFont() with calls to user functions like GUISetFont_DPI() and GUICtrlSetFont_DPI() which apply the $iDPI_Ratio variable as a divisor to the font size parameter like this: Func GUISetFont_DPI($isize, $iweight = "", $iattribute = "", $sfontname = "") GUISetFont($isize / $iDPI_Ratio, $iweight, $iattribute, $sfontname) EndFunc I'm still left with a few uncorrected issues like calendar controls. I considered a bugtracker to request an extra parm for GUISetFont() and GUICtrlSetFont(), that would act as a DPI divisor and default to 1. That would greatly simplify programatically suppressing a non-standard DPI setting. Then I wonder if perhaps the goal should be to move in the opposite direction... that of making Autoit fully DPI-aware? It appears the available values for the DPI setting are: .75 1.00 (default) 1.25 1.50 2.001 point
-
It's bad practice to use a MsgBox in a UDF to return an error. You should settle for SetError instead and let the user decide how to display the error.1 point
-
OS Architecture Help
behdadsoft reacted to JFX for a topic
%PROGRAMFILES% will be different if you run the x86 version of Autoit under x64 Windows IF @OSArch = 'x86' Then ConsoleWrite(EnvGet("PROGRAMFILES") & @CRLF) Else ConsoleWrite(EnvGet("ProgramW6432") & @CRLF) ConsoleWrite(EnvGet("PROGRAMFILES(X86)") & @CRLF) EndIf1 point -
1 point