-
Notifications
You must be signed in to change notification settings - Fork 72
/
ConvertHTMLToText.ahk
51 lines (42 loc) · 1.54 KB
/
ConvertHTMLToText.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
; Title:
; Link: https://www.autohotkey.com/boards/viewtopic.php?p=319141#p319141
; Author: malcev
; Date:
; for: AHK_L
/*
HTM := "<a href='https://en.wikipedia.org/wiki/Romeo_and_Juliet'><b>Romeo & Juliet</b></a>"
msgbox % ConvertToText(HTM)
*/
ConvertToText(string){
static HtmlUtilities
if (HtmlUtilities = "")
CreateClass("Windows.Data.Html.HtmlUtilities", IHtmlUtilities := "{FEC00ADD-2399-4FAC-B5A7-05E9ACD7181D}", HtmlUtilities)
CreateHString(string, hHtml)
DllCall(NumGet(NumGet(HtmlUtilities+0)+6*A_PtrSize), "ptr", HtmlUtilities, "ptr", hHtml, "ptr*", hText) ; ConvertToText
DeleteHString(hHtml)
buffer := DllCall("Combase.dll\WindowsGetStringRawBuffer", "ptr", hText, "uint*", length, "ptr")
return StrGet(buffer, "UTF-16")
}
CreateClass(string, interface, ByRef Class){
CreateHString(string, hString)
VarSetCapacity(GUID, 16)
DllCall("ole32\CLSIDFromString", "wstr", interface, "ptr", &GUID)
result := DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", &GUID, "ptr*", Class, "uint")
if (result != 0)
{
if (result = 0x80004002)
msgbox No such interface supported
else if (result = 0x80040154)
msgbox Class not registered
else
msgbox error: %result%
ExitApp
}
DeleteHString(hString)
}
CreateHString(string, ByRef hString){
DllCall("Combase.dll\WindowsCreateString", "wstr", string, "uint", StrLen(string), "ptr*", hString)
}
DeleteHString(hString){
DllCall("Combase.dll\WindowsDeleteString", "ptr", hString)
}