I think the project is important for all ... Thanks
New All project files
InterfaceCall.zip 8.15K
89 downloadsInterfaceCall.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
Example1
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") ;-------------------------------------------------- $Count = GetCount_Of_VirtualMethods($IPicture) if Not @error Then MsgBox(0,"Count Of Virtual Methods",$Count) EndIf ;-------------------------------------------------- ;////////////////////////////////////////////////// ;-------------------------------------------------- ; 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.dll","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
Example2
http://msdn.microsoft.com/en-us/library/windows/desktop/dd387916%28v=vs.85%29.aspx
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.
#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) EndFunc
Edited by wolf9228, 08 July 2012 - 06:40 PM.









