0

I am getting error “System.DllNotFoundException: 'Unable to load DLL 'swedll32.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)'” while Button1.Click. That dll is a native or unmanaged dll written in C. I am using 64 bit Windows 10 and visual studio 2019. Please help. Thanks

 Public Class Form1

Public Declare Sub swe_set_ephe_path Lib "swedll32.dll" Alias "_swe_set_ephe_path@4" (ByVal path As String)
Public Shared Function swe_get_planet_name(ByVal ipl As Int32) As String
    Dim Pointer As IntPtr
    Dim ReturnParam As New StringBuilder(255)
    Dim Result As String

    Pointer = _swe_get_planet_name(ipl, ReturnParam)
    Result = Marshal.PtrToStringAnsi(Pointer)

    Return Result
End Function
Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
swe_set_ephe_path(System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\SwEph")
    
End Sub
End Class
user12647598
  • 21
  • 1
  • 3
  • 2
    The message says everthing. The *.dll wasn't found. So check your folders. Sounds like you copied the file not into the right directory. – user743414 Dec 17 '20 at 09:06
  • @user743414 When a DLL is not found, the error is "The system cannot find the file specified", not "Invalid access to memory location". – GSerg Dec 17 '20 at 09:09
  • Does this answer your question? [Native loading works good. Loading from .net gives error Unable to load DLL 'my.dll': Invalid access to memory location](https://stackoverflow.com/questions/5375675/native-loading-works-good-loading-from-net-gives-error-unable-to-load-dll-my) – GSerg Dec 17 '20 at 09:11
  • Does this answer your question? [Win 7 DllImport C# Odd error, Invalid access to memory location?](https://stackoverflow.com/q/3327096/11683) – GSerg Dec 17 '20 at 09:11
  • Does this answer your question? [Windows Vista: Unable to load DLL 'x.dll': Invalid access to memory location. (DllNotFoundException)](https://stackoverflow.com/q/29284/11683) – GSerg Dec 17 '20 at 09:12
  • The function signature is stdcall, so I would guess this is a 32-bit dll. Therefore, recommend that you ensure that your VB is building as 32-bit. – Craig Dec 17 '20 at 14:31
  • I completely disabled DEP and UAC and also run visual studio in administrator mode but there is no positive effect. Please help. – user12647598 Dec 19 '20 at 07:00

0 Answers0