#include Local $sPath = ".\WebView2.h" ; <-- get it from the following link ; https://www.autoitscript.com/forum/topic/205154-using-objcreateinterface-and-objectfromtag-functions ; in the 'Includes' folder within the ObjectFromTag.7z file If Not FileExists($sPath) Then Exit MsgBox(16, 'Error', "Header file not found") Local $sHeader = FileRead($sPath) ClipPut(_CppHeaderParser($sHeader)) ; result to clipboard ConsoleWrite(ClipGet()) ; show result Func _CppHeaderParser(ByRef $sHeader) ; retrieve data from the c++ header file ; Retrieve cplusplus zones Local $a3 = _FindChunks($sHeader, '#if defined(__cplusplus) && !defined(CINTERFACE)', '#else /* C style interface */', 3) ; _ArrayDisplay($a3, "Debug: $a3") If @error Then Exit MsgBox(16, 'Sorry!', "errors occured." & @CRLF & @CRLF & 'needed data not found in the file' & @CRLF & "not possible to proceed.") Local $sObjDefinitions = '', $dtag Local $a4, $aNtf, $sNtf, $sMIDL_INTERFACE, $aRemarks, $sInterfaceDescription For $i = 1 To $a3[0] $aNtf = _FindChunks(StringStripWS($a3[$i], 8), '")', ':publicIUnknown', 0) If Not @error Then $sNtf = $aNtf[1] ; --- generate related global variables and interface identifier $sIID_* ----------------- $sMIDL_INTERFACE = _FindChunks($a3[$i], 'MIDL_INTERFACE("', '")', 0)[1] ; "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" $sObjDefinitions &= "Global const $o" & $sNtf & ", $p" & $sNtf & @CRLF $sObjDefinitions &= "Global Const $sIID_" & $sNtf & ' = "{' & $sMIDL_INTERFACE & '}"' & @CRLF & ";" ; ----------------------------------------------------------------------------------------- ; -- remove all remarks and all @crlf following a comma ----------------------------------- ; (to be replaced by an regexpreplace?) ; - find all remarks $aRemarks = _FindChunks(StringStripWS($a3[$i], 3), '/*', '*/', 3) ; - remove all remarks For $ii = 1 To $aRemarks[0] $a3[$i] = StringReplace(StringReplace($a3[$i], $aRemarks[$ii], ''), ',' & @CRLF, ", ") Next ; ----------------------------------------------------------------------------------------- ; Find all methods $a4 = _FindChunks(StringStripWS($a3[$i], 4), "virtual HRESULT STDMETHODCALLTYPE ", "= 0;", 3) ; Methods ; attempt to adapt the syntax to AutoIt ; ------------------------------------------------- If Not IsArray($a4) Then ; MsgBox(0,'',"Not Array", 1) $sObjDefinitions &= @CRLF & "Global Const $dtag_" & $sNtf & ' = ""' & @CRLF Else ; _ArrayDisplay($a4, 'Debug') $sInterfaceDescription = @CRLF & "Global Const $dtag_" & $sNtf & " = _" & @CRLF For $Method = 1 To $a4[0] $sBuild = @TAB & @TAB & '"' & _ StringReplace( _ StringReplace( _ StringReplace( _ StringReplace( _ $a4[$Method], "virtual HRESULT STDMETHODCALLTYPE ", "", 1), _ ; remove "virtual HRESULT STDMETHODCALLTYPE " " = 0;", "", -1), _ ; remove " = 0;" "(", " hresult("), _ ; replace "(" with -> " hresult(" '"', '""') & _ ; replace " with -> "" ';" & _ ' & @CRLF ; find the position of the data types in the string (in brackets) $iOpenParenthesis = StringInStr($sBuild, '(') $iClosedParenthesis = StringInStr($sBuild, ')', 0, -1) $sLeftSide = StringLeft($sBuild, $iOpenParenthesis) $sRightSide = StringTrimLeft($sBuild, $iClosedParenthesis - 1) ; Attempt to translate Windows Data Types to AutoIt Data Types in dtag ; -------------------------------------------------------------------- $sVarTypes = StringMid($sBuild, $iOpenParenthesis + 1, $iClosedParenthesis - $iOpenParenthesis - 1) ; data types are in brackets $aVarTypes = _StringTo2DArray($sVarTypes) ; place elements in a 2D array If Not @error Then $dtag = '' ; _ArrayDisplay($aVarTypes, 'Debug: $aVarTypes') For $ii = 0 To UBound($aVarTypes) - 1 $sConverted = _MSDNDataType($aVarTypes[$ii][0]) $dtag &= $sConverted & ";" Next Else $dtag &= ' -ANOMALY' & ";" EndIf $dtag = StringTrimRight($dtag, 1) $sInterfaceDescription &= $sLeftSide & $dtag & $sRightSide Next $sObjDefinitions &= StringTrimRight($sInterfaceDescription, 6) & @CRLF & @CRLF EndIf $sObjDefinitions &= "; - - original MSDN types in the c++ header for the above - - - - - - - -" & @CRLF For $ii = 1 To $a4[0] $aMethods = _FindChunks($a4[$ii], "(", ") = 0;", 0) $sObjDefinitions &= '; ' & $aMethods[1] & @CRLF Next $sObjDefinitions &= "; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" & @CRLF & @CRLF EndIf Next Return SetError(0, 0, $sObjDefinitions) EndFunc ;==>_CppHeaderParser ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FindChunks ; Description ...: searches and extract all portions of text within opening and closing tags ; Returns an array containing a collection of strings, one in each element ; Syntax ........: __FindChunks($sText, $sOpening, $sClosing [, $iChunkType]) ; Parameters ....: $sText - A string value containing the entire text to search in ; $sOpening - A string value indicating the opening tag ; $sClosing - A string value indicating the closing tag ; $iChunkType - [optional] an integer value. Default is 0. ; you can choose which parts of the recovery should be returned ; by setting this parameter as follows: ; ; 0 tag1|chunk|tag2 ; <---> (Default) returns only inner chunk text ; located between the search tags. ; ; 1 tag1|chunk|tag2 ; <--------> return left tag & inner chunk text ; ; 2 tag1|chunk|tag2 ; <--------> return inner chunk text & right tag ; ; else tag1|chunk|tag2 ; <-------------> return left tag & inner chunk text & right tag ; ; Return values .: success: an 1D 1 based array containing all the portions of text found related to the two search tags ; element [0] af the array contains the counter of found elements ; faillure: An empty string and sets @error as following: ; @error: 1 - no pair of such tags found in text ; Author ........: Gianni Addiego ; =============================================================================================================================== Func _FindChunks($sText, $sOpening, $sClosing, $iChunkType = 0) ; it counts how many of such tags are in the Text StringReplace($sText, $sOpening, $sOpening) ; in @xtended nr. of occurences Local $iNrOfOpeningTag = @extended StringReplace($sText, $sClosing, $sClosing) ; in @xtended nr. of occurences Local $iNrOfClosingTag = @extended Local $aPointer[5] = [1] ; Start search from beginning of text If ($iNrOfOpeningTag And $iNrOfClosingTag) Then ; if at least one of these tag pairs exists Local Const $iLen1 = StringLen($sOpening) Local Const $iLen2 = StringLen($sClosing) Local Const $iLoop = ($iNrOfOpeningTag > $iNrOfClosingTag) ? $iNrOfClosingTag : $iNrOfOpeningTag ; get the lower of the 2 numbers Local $aChunk[$iLoop + 1] = [$iLoop] ; Array to store found text chunks For $i = 1 To $iLoop $aPointer[0] = StringInStr($sText, $sOpening, 0, 1, $aPointer[0]) ; position in text of this opening tag $aPointer[1] = $aPointer[0] + $iLen1 ; start position of this inner chunk $aPointer[3] = StringInStr($sText, $sClosing, 0, 1, $aPointer[1]) ; position in text of this closing tag $aPointer[2] = $aPointer[3] - $aPointer[1] ; len of the chunk Switch $iChunkType Case 0 ; tag1|chunk|tag2 ; <---> $aChunk[$i] = StringMid($sText, $aPointer[1], $aPointer[2]) Case 1 ; tag1|chunk|tag2 ; <--------> $aChunk[$i] = StringMid($sText, $aPointer[0], $aPointer[2] + $iLen1) Case 2 ; tag1|chunk|tag2 ; <--------> $aChunk[$i] = StringMid($sText, $aPointer[1], $aPointer[2] + $iLen2) Case Else ; tag1|chunk|tag2 ; <-------------> $aChunk[$i] = StringMid($sText, $aPointer[0], $aPointer[2] + $iLen1 + $iLen2) EndSwitch $aPointer[0] = $aPointer[3] + $iLen2 ; Set new starting position for next search Next Return SetError(0, 0, $aChunk) Else Return SetError(1, 0, "") ; there are no pair of such tags in this text EndIf EndFunc ;==>_FindChunks ; https://www.autoitscript.com/forum/topic/113824-windows-data-types/?do=findComment&comment=979380 Func _MSDNDataType($sType) ; Idea by wolf9228, code by guinness. Local Static $aType[157][2] = [[156, 2], ['ATOM', 'WORD'], ['BOOL', 'BOOL'], ['BOOLEAN', 'BOOLEAN'], ['BYTE', 'BYTE'], ['CHAR', 'str'], _ ['COLORREF', 'DWORD'], ['CONST', 'const'], ['DWORD', 'DWORD'], ['DWORDLONG', 'ULONG'], ['DWORD_PTR', 'DWORD_PTR'], _ ['DWORD32', 'UINT'], ['DWORD64', 'INT64'], ['FLOAT', 'FLOAT'], ['HACCEL', 'HANDLE'], ['HALF_PTR', 'ptr'], _ ['HANDLE', 'HANDLE'], ['HBITMAP', 'HANDLE'], ['HBRUSH', 'HANDLE'], ['HCONV', 'HANDLE'], ['HCONVLIST', 'HANDLE'], _ ['HCURSOR', 'HANDLE'], ['HDC', 'HANDLE'], ['HDDEDATA', 'HANDLE'], ['HDESK', 'HANDLE'], ['HDROP', 'HANDLE'], _ ['HDWP', 'HANDLE'], ['HENHMETAFILE', 'HANDLE'], ['HFILE', 'int'], ['HFONT', 'HANDLE'], ['HGIDOBJ', 'HANDLE'], _ ['HGLOBAL', 'HANDLE'], ['HHOOK', 'HANDLE'], ['HICON', 'HANDLE'], ['HINSTANCE', 'HANDLE'], ['HKEY', 'HANDLE'], _ ['HKL', 'HANDLE'], ['HLOCAL', 'HANDLE'], ['HMENU', 'HANDLE'], ['HMETAFILE', 'HANDLE'], ['HMODULE', 'HANDLE'], _ ['HMONITOR', 'HANDLE'], ['HPALETTE', 'HANDLE'], ['HPEN', 'HANDLE'], ['HRESULT', 'LONG'], ['HRGN', 'HANDLE'], _ ['HRSRC', 'HANDLE'], ['HSZ', 'HANDLE'], ['HWINSTA', 'HANDLE'], ['HWND', 'HWND'], ['INT_PTR', 'INT_PTR'], _ ['INT32', 'int'], ['INT64', 'INT64'], ['LANGID', 'WORD'], ['LCID', 'DWORD'], ['LGRPID', 'DWORD'], _ ['LONG', 'LONG'], ['LONGLONG', 'INT64'], ['LONG_PTR', 'LONG_PTR'], ['LONG32', 'int'], ['LONG64', 'INT64'], _ ['LPARAM', 'LPARAM'], ['LPBOOL', 'int*'], ['LPBYTE', 'int*'], ['LPCOLORREF', 'DWORD*'], ['LPCSTR', 'str'], _ ['LPCTSTR', 'str'], ['LPCWSTR', 'wstr'], ['LPDWORD', 'DWORD*'], ['LPHANDLE', 'HANDLE*'], ['LPINT', 'int*'], _ ['LPLONG', 'long*'], ['LPSTR', 'str'], ['LPTSTR', 'str'], ['LPVOID', 'ptr'], ['LPWORD', 'WORD*'], _ ['LPWSTR', 'wstr'], ['LRESULT', 'LRESULT'], ['PBOOL', 'BOOL*'], ['PBOOLEAN', 'BOOLEAN*'], ['PBYTE', 'BYTE*'], _ ['PCHAR', 'str'], ['PCSTR', 'str'], ['PCTSTR', 'str'], ['PCWSTR', 'wstr'], ['PDWORD', 'DWORD*'], _ ['PDWORDLONG', 'UINT64'], ['PDWORD_PTR', 'DWORD_PTR*'], ['PDWORD32', 'UINT*'], ['PDWORD64', 'INT64*'], ['PFLOAT', 'FLOAT*'], _ ['PHALF_PTR', 'ptr'], ['PHANDLE', 'HANDLE*'], ['PHKEY', 'HANDLE*'], ['PINT', 'int*'], ['PINT_PTR', 'INT_PTR*'], _ ['PINT32', 'int*'], ['PINT64', 'INT64*'], ['PLCID', 'DWORD*'], ['PLONG', 'LONG*'], ['PLONGLONG', 'INT64*'], _ ['PLONG_PTR', 'LONG_PTR*'], ['PLONG32', 'long*'], ['PLONG64', 'INT64*'], ['POINTER_32', 'ptr'], ['POINTER_64', 'ptr'], _ ['POINTER_SIGNED', 'ptr'], ['POINTER_UNSIGNED', 'ULONG_PTR'], ['PSHORT', 'SHORT*'], ['PSIZE_T', 'ULONG_PTR*'], ['PSSIZE_T', 'LONG_PTR*'], _ ['PSTR', 'str'], ['PTBYTE', 'BYTE*'], ['PTCHAR', 'wstr'], ['PTSTR', 'wstr'], ['PUCHAR', 'BYTE*'], _ ['PUHALF_PTR', 'ptr*'], ['PUINT', 'UINT*'], ['PUINT_PTR', 'UINT_PTR*'], ['PUINT32', 'UINT*'], ['PUINT64', 'UINT64*'], _ ['PULONG', 'ULONG*'], ['PULONGLONG', 'UINT64*'], ['PULONG_PTR', 'ULONG_PTR*'], ['PULONG32', 'ULONG*'], ['PULONG64', 'UINT64*'], _ ['PUSHORT', 'USHORT*'], ['PVOID', 'ptr'], ['PWCHAR', 'wstr'], ['PWORD', 'WORD*'], ['PWSTR', 'wstr'], _ ['SC_HANDLE', 'HANDLE'], ['SC_LOCK', 'ptr'], ['SERVICE_STATUS_HANDLE', 'HANDLE'], ['SHORT', 'SHORT'], ['SIZE_T', 'ULONG_PTR'], _ ['SSIZE_T', 'LONG_PTR'], ['TBYTE', 'wstr'], ['TCHAR', 'wstr'], ['UCHAR', 'BYTE'], ['UHALF_PTR', 'ptr'], _ ['UINT', 'UINT'], ['UINT_PTR', 'UINT_PTR'], ['UINT32', 'UINT'], ['UINT64', 'UINT64'], ['ULONG', 'ULONG'], _ ['ULONGLONG', 'UINT64'], ['ULONG_PTR', 'ULONG_PTR'], ['ULONG32', 'ULONG'], ['ULONG64', 'UINT64'], ['UNICODE_STRING', 'ptr'], _ ['USHORT', 'USHORT'], ['USN', 'INT64'], ['VOID', 'none'], ['WCHAR', 'wstr'], ['WORD', 'WORD'], _ ['WPARAM', 'WPARAM']] If StringStripWS($sType, 8) <> '' Then For $i = 1 To $aType[0][0] If $sType = $aType[$i][0] Then Return $aType[$i][1] EndIf Next EndIf Return SetError(1, 0, '????') EndFunc ;==>_MSDNDataType Func _StringTo2DArray($var, $sRowSeparator = ',', $sColumnSeparator = ' ') Local $aRows = StringSplit(StringStripWS($var, 7), $sRowSeparator), $aColumns, $aResult[$aRows[0]][2] For $iRow = 1 To $aRows[0] $aColumns = StringSplit(StringStripWS($aRows[$iRow], 7), $sColumnSeparator) If $aColumns[0] > 3 Then Return SetError(1, 0, '!!!') EndIf If $aColumns[0] > UBound($aResult, 2) Then ; the 'const' prefix or something other was in declaration ; _ArrayDisplay($aColumns, 'Debug') $aColumns[0] -= 1 _ArrayDelete($aColumns, 1) EndIf For $iColumn = 1 To $aColumns[0] $aResult[$iRow - 1][$iColumn - 1] = $aColumns[$iColumn] Next Next Return $aResult EndFunc ;==>_StringTo2DArray