0

UPDATE: Thanks for everyones help. I had no idea about Marshaling my Strings and after doing so everything is now working correctly. I have edited my code below for others who may find this issue

I am currently working on porting some VB6 code to .net the vb6 application is using a precompiled .dll (made in C++ I beleive) and I do not have any access to its source code.

When googling the function name I get only one google result which DOES have information on its return value and its parameters and I believe I have declared the .DLL correctly

http://jelleybee.com/fun/vgames/emulate/snes/setup/super%20jukebox/Uematsu.html

.DLL function declaration

 Declare Function Uematsu_LoadID666Tag Lib "uematsu.dll" (ByVal lpszFileName As String, ByRef lpTag As ID666_tag) As Boolean

I have defined my structure like this

Public Structure ID666_tag
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Song As String             'Title of song
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Game As String             'Name of game
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Artist As String           'Name of artist
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Dumper As String           'Name of dumper
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Dated As String             'Date dumped
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Emu As String              'Emulator used to dump
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Comment As String          'Optional comment
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public OST As String              'Origonal soundtrak title
    Public SongLength As Integer         'Length of song
    Public LoopLength As Integer         'Length of the loop (extended ID666)
    Public EndLength As Integer          'Length of end (extended ID666)
    Public FadeLength As Integer         'length of fade out
    Public OSTDiscNum As Byte         'Origonal sound track disc number
    Public OSTTrack As Short        'Original sound track track number
    Public Publisher As String        'Name Of Publisher
    Public Copyright As Short       'Date of Copyright
    Public Mute As Byte               'Channels to mute
End Structure

I am using the function like this

Function Extract_ID666(Fname As String) As ID666_tag

Dim TempExtr As ID666_tag

If Uematsu_LoadID666Tag(Fname, TempExtr) = True Then
    MessageBox.Show("DONE")
Else
    MessageBox.Show("FAIL")
End If
End Function

However when ever I run my Extract_ID666 function I receive an access violation error.

I know this has something to do with the way I setup to use TempExtr or how I have declared my .dll function. But I can not track it down.

Any ideas or solutions to this problem would be much appreciated. I have searched SO for a long time trying to find a similar question but could not find a solution.

user2307545
  • 165
  • 1
  • 1
  • 7
  • 1
    Seeing `As Long` in your structure declaration is a Red Flag. That's appropriate in VB6 but not in VB.NET. Long = Integer, Integer = Short. The strings are fishy too, they typically require an attribute to declare them UnmanagedType.ByValTStr. – Hans Passant Jul 13 '13 at 15:11
  • Unfortunately this did not solve my issue but I have gone ahead and changed my longs to integer and my integers to short. Not sure on what you mean about the strings but i appreciate the help and will look into it some more. – user2307545 Jul 13 '13 at 15:22
  • `If Uematsu_LoadID666Tag(Fname, TempExtr) = True Then`? Why not `If Uematsu_LoadID666Tag(Fname, TempExtr) Then`? Anyways, the attribute would be ``, I think. – Ry- Jul 13 '13 at 16:07
  • I am unsure of how to use and am getting SizeConst is required for a fixed string. and the reason I am using = true is just readability for me and its an old habbit of mine. – user2307545 Jul 14 '13 at 01:37

1 Answers1

0

Access Violations are usually caused by an external .DLL trying to write to memory which is not designated. Here is an SO question with great detail on Access Violations Common causes of - Access Violation errors under .NET

Marshaling is the process of converting a data field, or an entire set of related structures, into a serialized string that can be sent in a message. Here is an SO question with more information on Marshaling What is marshalling? What is happening when something is "marshalled?"

Here is MSDN information on Marshaling Strings http://msdn.microsoft.com/en-us/library/s9ts558h%28v=vs.71%29.aspx

Community
  • 1
  • 1
user2307545
  • 165
  • 1
  • 1
  • 7