CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004
    Posts
    9

    Converting VB6 dll declare to VB.net dll declare

    I am converting a VB6 app to VS2013 VB.net.

    In my VB6 app I have the following:

    Private Declare Function vbInit Lib "MyTest.dll" ( _
    ByVal myRegRootPath As String, _
    ByVal myPath As String, _
    ByVal myClassPath As String, _
    ByVal myStorePath As String, _
    ByVal UndoBuff As Long) As Long

    Which works just fine in the VB6 app.

    Using this function in VB.net I get the following error :

    An unhandled exception of type 'System.AccessViolationException' occurred in My_test.exe
    Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    I have tried changing the call as follows:

    <DllImport("MyTest.dll", CharSet:=CharSet.Ansi)> _
    Public Function vbInit(<MarshalAs(UnmanagedType.LPStr)> ByVal myRegRootPath As String, _
    <MarshalAs(UnmanagedType.LPStr)> ByVal myPath As String, _
    <MarshalAs(UnmanagedType.LPStr)> ByVal myClassPath As String, _
    <MarshalAs(UnmanagedType.LPStr)> ByVal myStorePath As String, _
    ByVal UndoBuff As Integer) As Integer

    I do know that the dll was created in C++ vs2008 and it is unmanaged and that the strings are Multibyte CHarset.

    Is using the DLLImport the proper thing to do? If so why do I get the error using the above DLLImport? Am I using the wrong UnmanagedTYpe?

    ANy light anyone can shine on this error is greatly appreciated.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Converting VB6 dll declare to VB.net dll declare

    Could you show the call you made to this DLL Function?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured