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

VKSB 236 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.
336 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,723 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 45,476 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. VKSB 236 Reputation points
    2020-12-09T15:11:36.393+00:00

    Dear cooldadtx & RLWA32,

    Good news :-)

    Imports System.Text  
      
    Module Module1  
      
        Sub Main()  
            'To Call Ephemeris Path  
            swe_set_ephe_path("C:\sweph\ephe")  
      
            Dim Sweph_Version As New StringBuilder(128)  
            swe_version(Sweph_Version)   
      
            Console.WriteLine(Sweph_Version)  
            Console.ReadLine()  
      
        End Sub  
      
      
        Private 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 StringBuilder  
            ) As IntPtr  
        ' svers must be able to hold 256 bytes  
      
    End Module  
    

    This works fine.

    Then, I tried this:

    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)  
      
            Console.WriteLine("Sweph_Version : " & Sweph_Version)  
            Console.ReadLine()  
      
        End Sub  
      
      
        Private 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 IntPtr  
        ' svers must be able to hold 256 bytes  
      
    End Module  
    

    This also worked okay. Please note, here I used "ByVal svers As String) As IntPtr".

    "ByRef svers As String) As IntPtr" failed.

    Thanks
    Kind regards

    VKSBK

    0 comments No comments

  2. VKSB 236 Reputation points
    2020-12-09T15:16:15.147+00:00

    Hi,

    Why did all of a sudden few replies disappear?

    VKSBK

    0 comments No comments

  3. RLWA32 45,476 Reputation points
    2020-12-09T15:26:00.457+00:00

    As I previously indicated, the heap corruption was caused by the interop attempting to marshal the char* return value to a managed string. When the function declarations use IntPtr, that problem is resolved.

    0 comments No comments

  4. VKSB 236 Reputation points
    2020-12-09T17:37:02.063+00:00

    Dear RLWA32,

    "the heap corruption was caused by the interop attempting to marshal the char* return value to a managed string. When the function declarations use IntPtr, that problem is resolved".

    46665-download.jpg

    Can you please explain it to me in simple language. I still don't know what "IntPtr" is? Is it "Integer Pointer"???

    Googling gave me this;
    https://video2.skills-academy.com/en-us/dotnet/api/system.intptr?view=net-5.0

    A bit too complicated....

    Kind regards
    VKSBK


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.