LoginSignup
8

More than 5 years have passed since last update.

VB.NETでExcelの参照設定を使わずに[漢字-かな]変換をする

Last updated at Posted at 2015-12-16

仕事で使うことがあったので、メモを残しておきました。
あんまり活用する場面はなさそうですが、せっかくなので。

ここでは、
[JPReverseConv]というクラスを作っています。
このクラスを新しい.vbファイルにコピペしてやれば、使えます。
.Mainメソッドの中に、変換したい感じを入れると、日本語にして返します。

Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Runtime.CompilerServices

Public Class Form1
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

       Dim str As String

       str = JPReverseConv.Main(“東京最高京都最高山口最高愛媛最高香川最高”)

   End Sub

   Class JPReverseConv
       <ComImport>
       <Guid(“019F7152-E6DB-11D0-83C3-00C04FDDB82E”)>
       <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
       Private Interface IFELanguage
           Sub Open()
           Sub Close()
           Sub Dummy5()
           ’ DO NOT CALL 
           Sub Dummy6()
           ’ DO NOT CALL 
           Function GetPhonetic(<MarshalAs(UnmanagedType.BStr)> str As String, start As Integer, length As Integer) As <MarshalAs(UnmanagedType.BStr)> String
           Sub Dummy8()
           ’ DO NOT CALL 
       End Interface

       Public Shared Function Main(args As String)
           Dim fel = TryCast(Activator.CreateInstance(Type.GetTypeFromProgID(“MSIME.Japan”)), IFELanguage)
           Dim str As String
           fel.Open()
           str = fel.GetPhonetic(args, 1, -1)
           fel.Close()
           Return str
       End Function
   End Class

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8