画像を表示するアプリケーションがあり、それらを別のサーバーに移動しています。既存のサーバーでは、必要な数の画像を表示でき、再度ログインする必要はありません。新しいサーバーでは、ブラウザー コントロールに資格情報がある場合でも、画像を表示する前にログインするように求められます。Web ブラウザーの absoluteUri プロパティの値を取得して IE に貼り付けると、ログインを求めることなく画像が読み込まれます。
IAuthenticate を実装して、ユーザー ID とパスワードの資格情報をフォームの webBrowser コントロールに渡そうとしています。オンラインで見つけたすべての例は C# です。問題の場所を絞り込むために、IAuthenticate 実装をコメントアウトしました。これは、実装が呼び出される前にエラーが発生するためです。今私は持っています:
Imports System.Runtime.InteropServices
<ComImport(),
Guid("00000112-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IOleObject
Sub SetClientSite(pClientSite As IOleClientSite)
Sub GetClientSite(ppClientSite As IOleClientSite)
Sub SetHostNames(szContainerApp As Object, szContainerObj As Object)
Sub Close(dwSaveOption As UInteger)
Sub SetMoniker(dwWhichMoniker As UInteger, pmk As Object)
Sub GetMoniker(dwAssign As UInteger, dwWhichMoniker As UInteger, ppmk As Object)
Sub InitFromData(pDataObject As IDataObject, fCreation As Boolean, dwReserved As UInteger)
Sub GetClipboardData(dwReserved As UInteger, ppDataObject As IDataObject)
Sub DoVerb(iVerb As UInteger, lpmsg As UInteger, pActiveSite As Object, lindex As UInteger, hwndParent As UInteger, lprcPosRect As UInteger)
Sub EnumVerbs(ppEnumOleVerb As Object)
Sub Update()
Sub IsUpToDate()
Sub GetUserClassID(pClsid As UInteger)
Sub GetUserType(dwFormOfType As UInteger, pszUserType As UInteger)
Sub SetExtent(dwDrawAspect As UInteger, psizel As UInteger)
Sub GetExtent(dwDrawAspect As UInteger, psizel As UInteger)
Sub Advise(pAdvSink As Object, pdwConnection As UInteger)
Sub Unadvise(dwConnection As UInteger)
Sub EnumAdvise(ppenumAdvise As Object)
Sub GetMiscStatus(dwAspect As UInteger, pdwStatus As UInteger)
Sub SetColorScheme(pLogpal As Object)
End Interface
<ComImport(),
Guid("00000118-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IOleClientSite
Sub SaveObject()
Sub GetMoniker(ByVal dwAssign As Integer, ByVal dwWhichMoniker As Integer, ByRef ppmk As Object)
Sub GetContainer(ByRef ppContainer As Object)
Sub ShowObject()
Sub OnShowWindow(ByVal fShow As Boolean)
Sub RequestNewObjectLayout()
End Interface
<ComImport(),
Guid("6d5140c1-7436-11ce-8034-00aa006009fa"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IServiceProvider
<PreserveSig()>
Sub QueryService(ByRef guidService As Guid, ByRef riid As Guid,
<Out(), MarshalAs(UnmanagedType.Interface)> ByRef ppvObject As Object)
End Interface
<ComImport> _
<Guid("79EAC9D0-BAF9-11CE-8C82-00AA004BA90B")> _
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IAuthenticate
'<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)
Sub Authenticate(phwnd As IntPtr,
<MarshalAs(UnmanagedType.LPWStr)> ByRef pszUsername As String,
<MarshalAs(UnmanagedType.LPWStr)> ByRef pszPassword As String)
End Interface
Public Class frmIE
Implements IOleClientSite
Implements IServiceProvider
Public Shared IID_IAuthenticate As New Guid("79eac9d0-baf9-11ce-8c82-00aa004ba90b")
Private _user As String
Private _pwd As String
Friend WriteOnly Property url(user As String, pwd As String) As System.Uri
Set(ByVal value As System.Uri)
Dim oc As IOleObject
webIE.Navigate("about:blank") ' iAuthenticate not always called on first run
oc = DirectCast(webIE.ActiveXInstance, IOleObject)
' if I comment the following line out, it loads the image ok and asks for credentials
oc.SetClientSite(DirectCast(Me, IOleClientSite)) ' instead of trycast, so can see error: An unhandled exception of type 'System.ExecutionEngineException' occurred in System.Windows.Forms.dll
_user = user
_pwd = pwd
webIE.Navigate(value)
End Set
End Property
Public Sub GetContainer(ByRef ppContainer As Object) Implements IOleClientSite.GetContainer
ppContainer = Me ' doesn't reach stop placed here
End Sub
Public Sub GetMoniker(dwAssign As Integer, dwWhichMoniker As Integer, ByRef ppmk As Object) Implements IOleClientSite.GetMoniker
Dim i As Integer
i = 0 ' doesn't reach stop placed here
End Sub
Public Sub OnShowWindow(fShow As Boolean) Implements IOleClientSite.OnShowWindow
Dim i As Integer
i = 0 ' doesn't reach stop placed here
End Sub
Public Sub RequestNewObjectLayout() Implements IOleClientSite.RequestNewObjectLayout
Dim i As Integer
i = 0 ' doesn't reach stop placed here
End Sub
Public Sub SaveObject() Implements IOleClientSite.SaveObject
Dim i As Integer
i = 0 ' doesn't reach stop placed here
End Sub
Public Sub ShowObject() Implements IOleClientSite.ShowObject
Dim i As Integer
i = 0 ' doesn't reach stop placed here
End Sub
Public Sub QueryService(ByRef guidService As System.Guid, ByRef riid As System.Guid,
<Out(), MarshalAs(UnmanagedType.Interface)> ByRef ppvObject As Object) Implements IServiceProvider.QueryService
If guidService.CompareTo(IID_IAuthenticate) = 0 AndAlso riid.CompareTo(IID_IAuthenticate) = 0 Then
'ppvObject = Marshal.GetComInterfaceForObject(Me, GetType(IAuthenticate)) ' doesn't reach stop placed here
Else
ppvObject = IntPtr.Zero ' does reach stop placed here, 2x
' 1st guid is 4c96be40-915c-11cf-99d3-00aa004ae837 = SID_SToplevelBrowser
' 1st riid is 02ba3b52-0547-11d1-b833-00c04fc9b31f
' 2nd guid is SID_SToplevelBrowser
' 2nd riid is 6d5140c1-7436-11ce-8034-00aa006009fa
End If
End Sub
End Class
しかし、それは私にエラーを与えています
oc.SetClientSite(DirectCast(Me, IOleClientSite))
「System.Windows.Forms.dll で 'System.ExecutionEngineException' 型の未処理の例外が発生しました」と言って、多くの原因が考えられる一般的なエラーのように見えます。
宣言や使用法の詳細を見逃していると思いますが、それがどこにあるのか、それが本当に問題なのかさえわかりません。
すべての助けに感謝します、
-ベス