Hi,
I am writing my first DVD burning app with the SDK in VB.NET but am getting the error below whenever I call library routine
StarBurn_ISO9660JolietFileTree_Add
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The full code is below and the video files are in a sub-dir c:\avi which is set as ISO Root. Can you help me please - I'm not a low level or C# programmer and am totally stumped
Thanks
Public Sub BuildImage()
Dim Excp As EXCEPTION_NUMBER
Dim ISOFileTree As Integer
Dim FileTree As FILE_TREE
Dim isoLevel2 As Boolean
Dim isoLevels As Integer
Dim imageSize As Long
Dim remainingBytes As Long
Dim currentwriteSize As Integer
Dim imageSizeLowPart As Integer
Dim imageSizeHighPart As Integer
Dim Buffer() As Byte
Dim dirs As String()
Dim files As String()
Dim dir As String
Dim file As String
Try
If isoLevel < 2 Then isoLevel2 = False Else isoLevel2 = True
If isoIncludeJoliet Then
FileTree = FILE_TREE.FILE_TREE_JOLIET
Else
FileTree = FILE_TREE.FILE_TREE_ISO9660
End If
Try
dirs = Directory.GetDirectories(isoRoot)
files = Directory.GetFiles(isoRoot)
Catch ex As Exception
MsgBox("Invalid Root Directory")
Excp = -1
End Try
If Not dirs Is Nothing And Not files Is Nothing Then
Try
Excp = StarBurn_ISO9660JolietFileTree_Create(ISOFileTree, pExceptionText, ExceptionTextSize, SystemError, _
ISOCallBack, IntPtr.Zero, True, False, isoLevel2, FileTree)
If Excp <> EXCEPTION_NUMBER.EN_SUCCESS Then
ExceptionText = Marshal.PtrToStringAnsi(pExceptionText)
MsgBox(ExceptionText, MsgBoxStyle.Exclamation)
Exit Try
End If
' Get the tree root
Excp = StarBurn_ISO9660JolietFileTree_GetRoot(ISOFileTree)
If Excp <> EXCEPTION_NUMBER.EN_SUCCESS Then
ExceptionText = Marshal.PtrToStringAnsi(pExceptionText)
MsgBox(ExceptionText, MsgBoxStyle.Exclamation)
Exit Try
End If
' Directory first
For Each dir In dirs
Excp = StarBurn_ISO9660JolietFileTree_Add(ISOFileTree, pExceptionText, ExceptionTextSize, SystemError, _
dir, Nothing, FILE_TIME.FILE_TIME_CREATION, 0, 0)
If Excp <> EXCEPTION_NUMBER.EN_SUCCESS Then
ExceptionText = Marshal.PtrToStringAnsi(pExceptionText)
MsgBox(ExceptionText, MsgBoxStyle.Exclamation)
Exit Try
End If
Next
' Then the files
For Each file In files
Excp = StarBurn_ISO9660JolietFileTree_Add(ISOFileTree, pExceptionText, ExceptionTextSize, SystemError, _
file, Nothing, FILE_TIME.FILE_TIME_CREATION, 0, 0)
If Excp <> EXCEPTION_NUMBER.EN_SUCCESS Then
ExceptionText = Marshal.PtrToStringAnsi(pExceptionText)
MsgBox(ExceptionText, MsgBoxStyle.Exclamation)
Exit Try
End If
Next
isoLevels = StarBurn_ISO9660JolietFileTree_GetLevel(ISOFileTree)
Excp = StarBurn_ISO9660JolietFileTree_BuildImage(ISOFileTree, pExceptionText, ExceptionTextSize, SystemError, _
0, isoLevels, False, isoVolume, isoPublisher, isoApplication)
If Excp <> EXCEPTION_NUMBER.EN_SUCCESS Then
ExceptionText = Marshal.PtrToStringAnsi(pExceptionText)
MsgBox(ExceptionText, MsgBoxStyle.Exclamation)
Exit Try
End If
imageSizeLowPart = StarBurn_ISO9660JolietFileTree_GetSizeInUCHARs(ISOFileTree, imageSizeHighPart)
imageSize = imageSizeHighPart * &H100000000 + imageSizeLowPart
remainingBytes = imageSize
' Write binary file to disk
Dim fs As New FileStream(FileName, FileMode.Create)
Dim w As New BinaryWriter(fs)
While remainingBytes > 0
If remainingBytes > ImageBufferSize Then
currentwriteSize = ImageBufferSize
Else
currentwriteSize = remainingBytes
End If
ReDim Buffer(currentwriteSize - 1)
Excp = StarBurn_ISO9660JolietFileTree_Read(ISOFileTree, pExceptionText, ExceptionTextSize, SystemError, _
currentwriteSize, Buffer)
w.Write(Buffer)
remainingBytes = remainingBytes - currentwriteSize
End While
w.Close()
fs.Close()
Catch e As IOException
Excp = -1
MsgBox("Error writing file " & FileName)
Catch ex As Exception
Excp = -1
MsgBox(ex.ToString, MsgBoxStyle.Exclamation)
End Try
End If
If Not ISOCallBack Is Nothing Then
If Excp <> EXCEPTION_NUMBER.EN_SUCCESS Then
'ISOCallBack(CALLBACK_NUMBER.CN_PROCESS_COMPLETE_ERROR, Context, IntPtr.Zero, IntPtr.Zero)
Else
'ISOCallBack(CALLBACK_NUMBER.CN_PROCESS_COMPLETE_SUCCESFULLY, Context, IntPtr.Zero, IntPtr.Zero)
End If
End If
Catch ex As System.Exception
MsgBox("Error " & ex.Message & " occurred while building the ISO file")
End Try
End Sub
|