What is this error (process 16500) exited with code -1073740940. ?

VKSB 176 Reputation points
2020-12-08T11:59:07.78+00:00

Hi,

When I build my small Visual Basic Console program I get this message on the console;

"
H:\My Program Projects MS VS 2019 Community\Swe_Version Function Testing\bin\Debug\netcoreapp3.1\Swe_Version Function Testing.exe (process 16500) exited with code -1073740940."

What does this mean?

Please let me know how to rectify it.

Thanks
VKSBK

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,578 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 40,571 Reputation points
    2020-12-09T00:20:52.947+00:00

    I suspect that even when you tried to use StringBuilder that you declared the function as returning a String. This is a problem. The char* pointer that the unmanaged function _swe_version@4 returns will not be properly marshaled to a managed string and this is a source of the heap corruption error.

    This will fail -

        Public Declare Function swe_version Lib "swedll32.dll" Alias "_swe_version@4" (ByVal strVersion As StringBuilder) As String  
    

    This will succeed -

        Public Declare Function swe_version Lib "swedll32.dll" Alias "_swe_version@4" (ByVal strVersion As StringBuilder) As IntPtr  
    

    This will succeed -

        Public Declare Sub swe_version Lib "swedll32.dll" Alias "_swe_version@4" (ByVal strVersion As StringBuilder)  
      
    
    0 comments No comments

13 additional answers

Sort by: Most helpful
  1. RLWA32 40,571 Reputation points
    2020-12-08T12:06:16.907+00:00

    The -1073740940 value corresponds to the status code C0000374. This code is STATUS_HEAP_CORRUPTION (A heap has been corrupted).


  2. Michael Taylor 48,576 Reputation points
    2020-12-08T15:07:06.5+00:00

    Run your VB app in the Visual Studio debugger. When your app crashes it should throw you into the code that is crashing. At that point you'll have the exception type, message and stack trace on how it got there. Post that information along with the relevant lines of code.

    0 comments No comments

  3. VKSB 176 Reputation points
    2020-12-08T18:33:45.6+00:00

    Dear cooldadtx & RLWA32-6355,

    Thanks for the reply.

    I am using "swedll32.dll" file from "Swiss Ephmeris" (From https://www.astro.com/ftp/swisseph/ -- Download "sweph.zip - 2020-09-01 10:39 -18M) for this.

    The Functions I am using are given in the code.

    Module Module1
    
        Sub Main()
            'To Call Ephemeris Path
            swe_set_ephe_path("C:\sweph\ephe")
    
            Dim Sweph_Version As String = Space(256)
    
            swe_version(Sweph_Version) ' This Function is NOT Working when .Net Framework is anything higher the 4.0.
    
            Console.WriteLine("Sweph Version : " & Sweph_Version)
    
            Console.ReadLine()
    
        End Sub
    
    
        Public Declare Sub swe_set_ephe_path Lib "swedll32.dll" _
            Alias "_swe_set_ephe_path@4" (
              ByVal path As String
            )
    
    
        Private Declare Function swe_version Lib "swedll32.dll" _
            Alias "_swe_version@4" (
              ByVal svers As String
            ) As String
        ' svers must be able to hold 256 bytes
    
    
    End Module
    

    Please note that when the ".Net Framework" is 4.0 this works fine & the console shows "Sweph Version : 2.09.01"; when ".Net Framework" is anything higher than 4.0 for eg 4.8, it does NOT work. When I click "Start without Debugging" the Console shows "Press any key to continue.."; when I click /"Start Debugging", empty console pops up & closes very quickly.

    So, I don't get any "Information" from debugging to post here.... I hope I am doing it properly... please correct me if I am wrong.

    Thanks
    Kind regards

    VKSBK.

    0 comments No comments

  4. Castorix31 81,741 Reputation points
    2020-12-08T19:05:02.393+00:00

    I did a quick test with .NET 4.7.2 and this works for me =>

    <DllImport("Swedll32.dll", SetLastError:=True, EntryPoint:="_swe_version@4", CharSet:=CharSet.Ansi)>
    Public Shared Sub swe_version(sbVersion As StringBuilder)
    End Sub
    
    Dim sbVersion As StringBuilder = New StringBuilder(128)
    swe_version(sbVersion)
    
    0 comments No comments