ファイルストリームへの保存・読込方法

'ファイルストリームに保存する方法
Public Sub SaveObjectAsFile(PersistStream As IPersistStream, PathName As String)
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
    
    Dim pFile As IFile
    Set pFile = pFileStream
    
    pFile.Open PathName, esriReadWrite
    PersistStream.Save pFileStream, 0

End Sub

Function Save(pGeometry As IGeometry, sFile As String)
    Set pGeometry = pFeature.Shape
    Dim pPolycurve As IPolycurve
    Set pPolycurve = pGeometry
    Dim pPersistStream As IPersistStream
    Set pPersistStream = pPolycurve
    
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
    Dim pFile As IFile
    Set pFile = pFileStream
    pFile.Open sFile, esriReadWrite
    pPersistStream.Save pFileStream, 0
End Function

'ファイルストリームを読み込む方法
Function Load(sFile As String) As IGeometry
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
    Dim pFile As IFile
    Set pFile = pFileStream
    pFile.Open sFile, esriReadOnly
    
    Dim pPolyline As IPolyline
    Set pPolyline = New Polyline
    Dim pPersistStream As IPersistStream
    Set pPersistStream = pPolyline
    pPersistStream.Load pFileStream
    Set Load = pPolyline
End Function

Public Sub LoadObjectFromFile(ByRef PersistStream As IPersistStream, PathName As String)
    'PersistStreamはファイルに保存したオブジェクトの型であらかじめインスタンスを作成しておく

    Dim pFileStream As IStream
    Set pFileStream = New FileStream
    
    Dim pFile As IFile
    Set pFile = pFileStream
    pFile.Open PathName, esriReadOnly
    
    PersistStream.Load pFileStream
    
End Sub

'-----------------------------------
'Streamの保存
Public Sub saveobj(v As IGeoTransformation)
    Dim pMemoryBlobStream As IMemoryBlobStream
    Set pMemoryBlobStream = New MemoryBlobStream
    Dim pObjectStream As IObjectStream
    Set pObjectStream = New ObjectStream
    Set pObjectStream.Stream = pMemoryBlobStream
    
    Dim pPersistStream As IPersistStream
    Set pPersistStream = v
    
    pPersistStream.Save pObjectStream, False
    pMemoryBlobStream.SaveToFile "D:\Workspace\Tokyo_To_JGD_2000_NTv2.GeoTransformation"

End Sub

'Streamの読み込み
Dim pObjectStream2 As IObjectStream
Set pObjectStream2 = New ObjectStream

Dim pMemoryBlobStream2 As IMemoryBlobStream
Set pMemoryBlobStream2 = New MemoryBlobStream
pMemoryBlobStream2.LoadFromFile "D:\Workspace\Tokyo_To_JGD_2000_NTv2.GeoTransformation"

Dim pMygeo As IGeoTransformation
Set pMygeo = New NTv2Transformation

Dim pPersistStream2 As IPersistStream
Set pPersistStream2 = pMygeo

Set pObjectStream2.Stream = pMemoryBlobStream2
pPersistStream2.Load pObjectStream2