VS2019: VB.NET to C: Unable to load DLL: HRESULT: 0x8007007E (worked in VS2017)

0

This question relates to Stackoverflow Question: Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

But I am not good enough to post comments there!

In VS2017, I have this VB.NET code which successfully calls a C DLL:


' MY_DLL: the simple [no path] DLL name
' *_STR: structs
' DLL_DIR: string, absolute directory path
<DllImport(MY_DLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> Public Sub MyCFunction(ByRef status As STATUS_STR, ByRef inputs As IN_STR, ByRef inOut As IO_STR, ByRef outputs As OUT_STR)
End Sub

Public Sub Call_MyCFunction(ByRef statRec As STATUS_STR, ByRef inputRec As IN_STR, ByRef ioRec As IO_STR, ByRef outputRec As OUT_STR)
    Dim holdDir As String = CurDir()
    ChDir(DLL_DIR) 'change directory to where the DLL lives
    FileSystem.CurDir() 'debugging

    'CALL THE "C" FUNCTION
    MyCFunction(statRec, inputRec, ioRec, outputRec) ' <== EXCEPTION THROWN HERE

    ChDir(holdDir)
    ...

This code worked until I upgraded to VS2019. I now get the above error.

BUT: I tried the kludge suggested in the related question - and it works! If I hard-code the absolute path into

<DllImport(<absolute path to dll>, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> Public Sub MyCFunction(ByRef status As STATUS_STR, ByRef inputs As IN_STR, ByRef inOut As IO_STR, ByRef outputs As OUT_STR)
End Sub

I solve the problem.

Any explanations? I'd prefer to access the "C" function using my original tactic...

UPDATE The above issue occurred on a virtual machine. The DLL in question resides on a network drive. I've just installed the VS2019 solution on my own physical machine, and of course it works fine!

Moderators: Can delete this one if it is of no value. Still curious tho'.

c
vb.net
visual-studio-2017
visual-studio-2019
asked on Stack Overflow Mar 3, 2021 by Stephen Baldwin • edited Mar 3, 2021 by Stephen Baldwin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0