Imports System.Runtime.InteropServices Imports System.Text Public Partial Class Form1 Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted ListBox1.Items.Clear() Dim cplFile As String = CStr(ComboBox1.SelectedItem) If String.IsNullOrEmpty(cplFile) Then Return End If ListBox1.Items.Add(System.IO.Path.GetFileName(cplFile)) Dim hModule = LoadLibrary(cplFile) Dim szCPLINFO = Marshal.SizeOf(GetType(CPLINFO)) Dim szNEWCPLINFOW = Marshal.SizeOf(GetType(NEWCPLINFOW)) Dim szNEWCPLINFOA = Marshal.SizeOf(GetType(NEWCPLINFOA)) Try Dim hCPlApplet = GetProcAddress(hModule, "CPlApplet") If hCPlApplet = IntPtr.Zero Then ListBox1.Items.Add("は CPlApplet 関数をエクスポートしていません。") Return End If Dim CPlApplet = DirectCast(Marshal.GetDelegateForFunctionPointer(hCPlApplet, GetType(CPlAppletDelegate)), CPlAppletDelegate) If CPlApplet(Handle, CPL_INIT, IntPtr.Zero, IntPtr.Zero) = 0 Then ListBox1.Items.Add("のロードに失敗しました。") Return End If Dim count As Integer = CPlApplet(Handle, CPL_GETCOUNT, IntPtr.Zero, IntPtr.Zero) ListBox1.Items.Add("には、" & CStr(count) & "個のアプレットがあります") For n = 0 To count - 1 ListBox1.Items.Add("===== Applet #" & CStr(n) & " =====") ListBox1.Items.Add("--- CPL_INQUIRE で取得 ---") Dim pCPlInfo = Marshal.AllocCoTaskMem(szCPLINFO) For p = 0 To szCPLINFO - 1 Marshal.WriteByte(pCPlInfo, p, 0) Next CPlApplet(Handle, CPL_INQUIRE, New IntPtr(n), pCPlInfo) Dim oCPlInfo = DirectCast(Marshal.PtrToStructure(pCPlInfo, GetType(CPLINFO)), CPLINFO) Marshal.FreeCoTaskMem(pCPlInfo) ListBox1.Items.Add("CPLINFO: idIcon=" & CStr(oCPlInfo.idIcon)) ListBox1.Items.Add("CPLINFO: idName=" & CStr(oCPlInfo.idName) & ", """ & LoadResString(hModule, oCPlInfo.idName) & """") ListBox1.Items.Add("CPLINFO: idInfo=" & CStr(oCPlInfo.idInfo) & ", """ & LoadResString(hModule, oCPlInfo.idInfo) & """") ListBox1.Items.Add("CPLINFO: lData=" & oCPlInfo.lData.ToString()) ListBox1.Items.Add("--- CPL_NEWINQUIRE で取得 ---") Dim pNewCPlInfo = Marshal.AllocCoTaskMem(szNEWCPLINFOW) For p = 0 To szNEWCPLINFOW - 1 Marshal.WriteByte(pNewCPlInfo, p, 0) Next CPlApplet(Handle, CPL_NEWINQUIRE, New IntPtr(n), pNewCPlInfo) Dim dwSize = Marshal.ReadInt32(pNewCPlInfo, 0) Select Case dwSize Case 0 ListBox1.Items.Add("NEWCPLINFO: 取得できませんでした。") Case szNEWCPLINFOW Dim oNewCPlInfoW = DirectCast(Marshal.PtrToStructure(pNewCPlInfo, GetType(NEWCPLINFOW)), NEWCPLINFOW) ListBox1.Items.Add("NEWCPLINFOW: hIcon=" & oNewCPlInfoW.hIcon.ToString()) ListBox1.Items.Add("NEWCPLINFOW: szName=""" & If(oNewCPlInfoW.szName, "").Split(Char.MinValue)(0) & """") ListBox1.Items.Add("NEWCPLINFOW: szInfo=""" & If(oNewCPlInfoW.szInfo, "").Split(Char.MinValue)(0) & """") ListBox1.Items.Add("NEWCPLINFOW: lpData=" & oNewCPlInfoW.lData.ToString()) Case szNEWCPLINFOA Dim oNewCPlInfoA = DirectCast(Marshal.PtrToStructure(pNewCPlInfo, GetType(NEWCPLINFOA)), NEWCPLINFOA) ListBox1.Items.Add("NEWCPLINFOA: hIcon=" & oNewCPlInfoA.hIcon.ToString()) ListBox1.Items.Add("NEWCPLINFOA: szName=""" & If(oNewCPlInfoA.szName, "").Split(Char.MinValue)(0) & """") ListBox1.Items.Add("NEWCPLINFOA: szInfo=""" & If(oNewCPlInfoA.szInfo, "").Split(Char.MinValue)(0) & """") ListBox1.Items.Add("NEWCPLINFOA: lpData=" & oNewCPlInfoA.lData.ToString()) Case Else ListBox1.Items.Add("NEWCPLINFO: 不明なサイズ:" & CStr(dwSize)) End Select Marshal.FreeCoTaskMem(pNewCPlInfo) Next CPlApplet(Handle, CPL_EXIT, IntPtr.Zero, IntPtr.Zero) Finally FreeLibrary(hModule) End Try End Sub End Class