WebBrowser / My.Resources question

  • Thread starter Thread starter William Cruz
  • Start date Start date
W

William Cruz

Can I call a file (*.html) within My.Resources to show-up in my
WebBrowser control? If so, please provide a sample code or a link.
Thanks in advance for your help.

William Cruz
 
This is what I am doing and it gives me an error:

WebBrowser1.Navigate(My.Resources.Software_License_Agreement)


Error:
"Error HRESULT E_FAIL has been returned from a call to a COM component."


William
 
You should load the HTML content directly into the webbrowser and not trying
to load from a location.

Here is a code to load dynamicaly the HTML into the webbrowser (You will
have to change the PageForText to your control name or if this code is
within the browser itself, Me).

Private Sub LoadContent(ByVal HTML As String)
' ensure that the document is loaded, otherwise the next line
fails...
If PageForText.Document Is Nothing Then
PageForText.Navigate2("about:blank")
' get a reference to the document...
Dim clsDocument As mshtml.HTMLDocument = CType(PageForText.Document,
mshtml.HTMLDocument)
' initiailize the document using the IPersistStreamInit COM
interface...
DirectCast(clsDocument, IPersistStreamInit).InitNew()
' Marshal the content into a interop stream...
Dim ptrValue As IntPtr =
System.Runtime.InteropServices.Marshal.StringToHGlobalAuto(HTML)
Dim clsStream As System.Runtime.InteropServices.UCOMIStream =
Nothing
CreateStreamOnHGlobal(ptrValue, True, clsStream)
' load the content into the browser..
DirectCast(clsDocument, IPersistStreamInit).Load(clsStream)
End Sub


Jonathan Boivin
 
You will need these too .. (Let me know if something is missing)

Public Enum HRESULT
S_OK = 0
S_FALSE = 1
E_NOTIMPL = &H80004001
E_INVALIDARG = &H80070057
E_NOINTERFACE = &H80004002
E_FAIL = &H80004005
E_UNEXPECTED = &H8000FFFF
End Enum

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit : Inherits IPersist
Shadows Sub GetClassID(ByRef pClassID As Guid)
<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As HRESULT
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream,
<MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean) As HRESULT
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(), _
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As HRESULT
<PreserveSig()> Function InitNew() As HRESULT
End Interface

<ComVisible(True), ComImport(),
Guid("0000010c-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersist
Sub GetClassID(ByRef pClassID As Guid)
End Interface

Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As
IntPtr, ByVal fDeleteOnRelease As Boolean, ByRef ppstm As UCOMIStream) As
Long


Jonathan Boivin
 
Back
Top