EDN Admin
Well-known member
I got this Error : Reference to class ApplicationClass is not allowed when its assembly is linked using No-PIA mode.
This Is My Code:
Imports System<br/>
Imports System.Collections.Generic<br/>
Imports System.Drawing<br/>
Imports System.Reflection<br/>
Imports System.Threading<br/>
Imports System.Windows.Forms<br/>
Imports FastColoredTextBoxNS<br/>
Imports Microsoft.Office.Interop.Word<br/>
Partial Public Class Form1<br/>
Inherits Form<br/>
Private wavyStyle As FastColoredTextBoxNS.Style = New WavyLineStyle(255, Color.Red)<br/>
Public Sub New()<br/>
InitializeComponent()<br/>
Dim fctb As New FastColoredTextBox()<br/>
fctb.Parent = Me<br/>
fctb.Dock = DockStyle.Fill
SpellChecker.Init()<br/>
End Sub
<br/>
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing<br/>
SpellChecker.Dispose()<br/>
End Sub
<br/>
Private Sub fctb_TextChangedDelayed(ByVal sender As Object, ByVal e As TextChangedEventArgs)<br/>
ThreadPool.QueueUserWorkItem(Function(s)<br/>
Dim list As Object
= New List(Of FastColoredTextBoxNS.Range)()<br/>
For Each word As
Object In e.ChangedRange.GetRanges("[w]+")<br/>
If SpellChecker.GetSuggest(word.Text) IsNot Nothing Then<br/>
list.Add(word)<br/>
End If<br/>
Next<br/>
e.ChangedRange.ClearStyle(wavyStyle)<br/>
For Each word As
Object In list<br/>
word.SetStyle(wavyStyle)<br/>
Next
End Function)<br/>
End Sub
Friend WithEvents FastColoredTextBox1 As FastColoredTextBoxNS.FastColoredTextBox<br/>
End Class
Module SpellChecker<br/>
Dim App As ApplicationClass<br/>
Public Sub Init()<br/>
Dim template As Object = Type.Missing<br/>
Dim newtemplate As Object = False<br/>
Dim doctype As Object = WdNewDocumentType.wdNewBlankDocument<br/>
Dim visible As Object = False<br/>
App.DisplayAlerts = WdAlertLevel.wdAlertsNone<br/>
App.Visible = False<br/>
App.Options.SuggestSpellingCorrections = True<br/>
Dim document As Document = App.Documents.Add(template, newtemplate, doctype, visible)<br/>
document.Activate()<br/>
End Sub
<br/>
Public Function GetSuggest(ByVal word As String) As String()<br/>
Dim [nothing] As Object = Missing.Value<br/>
Dim spelledright As Boolean = App.CheckSpelling(word, [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing], [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing])<br/>
If spelledright Then<br/>
Return Nothing<br/>
End If<br/>
Dim suggestions As Object = App.GetSpellingSuggestions(word, [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing], [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing], [nothing])<br/>
Dim words As Object = New List(Of String)()<br/>
For Each suggestion As SpellingSuggestion In suggestions<br/>
words.Add(suggestion.Name)<br/>
Next<br/>
suggestions = Nothing<br/>
Return words.ToArray()<br/>
End Function
<br/>
Public Sub Dispose()<br/>
Dim savenochanges As Object = WdSaveOptions.wdDoNotSaveChanges<br/>
Dim [nothing] As Object = Missing.Value<br/>
If App IsNot Nothing Then<br/>
Try<br/>
App.Quit(savenochanges, [nothing], [nothing])<br/>
Catch<br/>
End Try<br/>
End If<br/>
App = Nothing<br/>
End Sub
End Module
View the full article
This Is My Code:
Imports System<br/>
Imports System.Collections.Generic<br/>
Imports System.Drawing<br/>
Imports System.Reflection<br/>
Imports System.Threading<br/>
Imports System.Windows.Forms<br/>
Imports FastColoredTextBoxNS<br/>
Imports Microsoft.Office.Interop.Word<br/>
Partial Public Class Form1<br/>
Inherits Form<br/>
Private wavyStyle As FastColoredTextBoxNS.Style = New WavyLineStyle(255, Color.Red)<br/>
Public Sub New()<br/>
InitializeComponent()<br/>
Dim fctb As New FastColoredTextBox()<br/>
fctb.Parent = Me<br/>
fctb.Dock = DockStyle.Fill
SpellChecker.Init()<br/>
End Sub
<br/>
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing<br/>
SpellChecker.Dispose()<br/>
End Sub
<br/>
Private Sub fctb_TextChangedDelayed(ByVal sender As Object, ByVal e As TextChangedEventArgs)<br/>
ThreadPool.QueueUserWorkItem(Function(s)<br/>
Dim list As Object
= New List(Of FastColoredTextBoxNS.Range)()<br/>
For Each word As
Object In e.ChangedRange.GetRanges("[w]+")<br/>
If SpellChecker.GetSuggest(word.Text) IsNot Nothing Then<br/>
list.Add(word)<br/>
End If<br/>
Next<br/>
e.ChangedRange.ClearStyle(wavyStyle)<br/>
For Each word As
Object In list<br/>
word.SetStyle(wavyStyle)<br/>
Next
End Function)<br/>
End Sub
Friend WithEvents FastColoredTextBox1 As FastColoredTextBoxNS.FastColoredTextBox<br/>
End Class
Module SpellChecker<br/>
Dim App As ApplicationClass<br/>
Public Sub Init()<br/>
Dim template As Object = Type.Missing<br/>
Dim newtemplate As Object = False<br/>
Dim doctype As Object = WdNewDocumentType.wdNewBlankDocument<br/>
Dim visible As Object = False<br/>
App.DisplayAlerts = WdAlertLevel.wdAlertsNone<br/>
App.Visible = False<br/>
App.Options.SuggestSpellingCorrections = True<br/>
Dim document As Document = App.Documents.Add(template, newtemplate, doctype, visible)<br/>
document.Activate()<br/>
End Sub
<br/>
Public Function GetSuggest(ByVal word As String) As String()<br/>
Dim [nothing] As Object = Missing.Value<br/>
Dim spelledright As Boolean = App.CheckSpelling(word, [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing], [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing])<br/>
If spelledright Then<br/>
Return Nothing<br/>
End If<br/>
Dim suggestions As Object = App.GetSpellingSuggestions(word, [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing], [nothing], [nothing], [nothing], [nothing], [nothing], _<br/>
[nothing], [nothing])<br/>
Dim words As Object = New List(Of String)()<br/>
For Each suggestion As SpellingSuggestion In suggestions<br/>
words.Add(suggestion.Name)<br/>
Next<br/>
suggestions = Nothing<br/>
Return words.ToArray()<br/>
End Function
<br/>
Public Sub Dispose()<br/>
Dim savenochanges As Object = WdSaveOptions.wdDoNotSaveChanges<br/>
Dim [nothing] As Object = Missing.Value<br/>
If App IsNot Nothing Then<br/>
Try<br/>
App.Quit(savenochanges, [nothing], [nothing])<br/>
Catch<br/>
End Try<br/>
End If<br/>
App = Nothing<br/>
End Sub
End Module
View the full article