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.
337 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,738 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 45,701 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. Michael Taylor 54,816 Reputation points
    2020-12-08T19:11:34.61+00:00

    My guess is that is blowing up on line 5. Set a breakpoint on that line to confirm.

    I notice in the zip file you linked to that they support both x86 and x64. They are using different names for each of the binaries. If your VB app is compiling for x86 platform then your import statement should be correct. However there are several DLLs in this zip so you need to ensure that all those DLLs are in your project's output directory.

    You mention that if NF is higher than 4.0 then it doesn't work. Does that mean you have 2 test machines. One that has 4.0 installed and one that has a newer version installed? .NET 4 installs over the top of itself so the only way to "downgrade" from a newer install is to uninstall. But Windows ships with a newer version of .NET than 4.0 so you couldn't downgrade to 4.0 RTM. If this is multiple machines then the problem is less likely .NET Framework and more about a dependency issue.

    Probably an issue with your import.

    0 comments No comments

  2. VKSB 236 Reputation points
    2020-12-08T19:48:18.937+00:00

    Dear cooldadtx,

    Thanks for the reply.

    I've been using this .dll for many years.... and created (for fun & personal use) many projects and they work okay. I use only one DLL ie: "swedll32.dll". Even other functions of swiss ephemeris work okay except this one ( "swe_version").
    I started to use this function very recently; so tried with adding this function to other projects to see whether it works in those projects; by doing this I came to know that it works with .Net Framework 4.0 & not with anything higher than 4.0.

    Re:
    "You mention that if NF is higher than 4.0 then it doesn't work. Does that mean you have 2 test machines. One that has 4.0 installed and one that has a newer version installed? ".

    No I don't have two computers. What I did was I selected the ".Net Framework 4.0" Or ".Net Framework 4.8" from the drop down menu under "Target Framework:"; (In the Menu "Project" ---> "Swe_version Function Testing Properties" ---> "Application" Tab ---> "Target Framework:").

    I hope this is okay. I've checked this changing the "Target Framework:" on the my other projects also. They too give problem for this function only others work fine. This function simply shows the version of the Swiss Ephemeris used in the project nothing else.

    Please let me know what I am doing ( ie: changing the "Target Framework:") is okay / wrong.

    Thanks
    Kind regards
    VKSBK


  3. VKSB 236 Reputation points
    2020-12-08T22:59:44.053+00:00

    Dear cooldadtx,

    Thanks for the helping.

    Tried using "Stringbuilder" after writing "Imports System.Text"; it didn't work & didn't give any error messages.

    Then tried "ByRef" and a String with 256 characters. It caused the console to show the following message when "Start without Debugging" was clicked.

    "Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    at System.String..ctor(SByte* value)
    at System.StubHelpers.AnsiBSTRMarshaler.ConvertToManaged(IntPtr bstr)
    at Swe_version_Function_Testing_2_NetFramework.Module1.swe_version(String& svers)
    at Swe_version_Function_Testing_2_NetFramework.Module1.Main() in H:\My Program Projects MS VS 2019 Community\Swe_version Function Testing 2 NetFramework\Module1.vb:line 15
    Press any key to continue . . ."

    When I clicked "Start Debugging" it showed this - see the screenshot.

    46392-capture.png

    I don't understand the error message shown. Hope you will find it useful to solve the problem.

    Thanks
    Kind regards
    VKSBK


  4. VKSB 236 Reputation points
    2020-12-09T14:33:29.383+00:00

    Dear cooldadtx & RLWA32,

    Thanks for the replies.

    "RLWA32-6355 :
    I suspect that even when you tried to use StringBuilder that you declared the function as returning a String.."

    No, I had to use Stringbuilder for that too; otherwise it caused error on building. I'll try your other suggestions. Thanks.

    "cooldadtx :
    It shows the string isn't going to work so use StringBuilder with ByVal. Did you also set the character set attribute to Ansi?"

    Please let me know how to do "set the character set attribute to Ansi"; Never done this so far.
    I think I tried "Stringbuilder" with "ByVal". Not a big problem, I'll try it now.

    Thanks
    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.