Reputation: 1352
I have an unmanaged c++ dll (my creation) that has a function with a bunch of input variables (scalars and arrays) and output array. I want to call this from a visual basic program. I have a simple form + one button that calls the function in the dll when clicked. In the vb file it is imported as follows:
Module MyDLLModule
<DllImport("mydll.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> Public Function fun(ByVal var1 As Double, _
ByVal var2 As Double, _
<MarshalAs(UnmanagedType.SafeArray)> ByRef arr1() As Double, _
<MarshalAs(UnmanagedType.SafeArray)> ByRef arr2() As Double, _
<MarshalAs(UnmanagedType.SafeArray)> ByRef arr3() As Double, _
ByVal var3 As Double, _
ByVal var4 As Double, _
ByVal var5 As Double, _
ByVal var6 As Double, _
ByVal var7 As Double, _
ByVal var8 As Double, _
ByVal var9 As Double, _
ByVal var10 As Double, _
ByVal var11 As Integer, _
<MarshalAs(UnmanagedType.SafeArray)> ByRef arr4() As Double, _
<MarshalAs(UnmanagedType.SafeArray)> ByRef arrout() As Double) As Integer
End Function
End Module
It is later used just as any other function.
This all works well on the machine I develop with, both when debugging in MSVS and when just running the app. BUT when I move all the files to another computer it complains when clicking the button to call the dll:
"Unable to loadl DLL "mydll.dll": The specified module could not be found. (Exception form HRESULT: 0x8007007E).
I have been reading and testing some different possibilities:
None of these works. Does anyone have an idea for a solution to this?
Upvotes: 2
Views: 170
Reputation: 1352
Thanks to paulsm4 : the msvc runtime seemed to have been the problem. Using the /MT flag (static linking as far as I understand) when compiling mydll.dll solved it.
Upvotes: 1
Reputation: 121669
SUGGESTION:
Try running depends.exe or dumpbin.exe on your .dll to see what dependencies it might have.
You're correct: PATH is the first thing you need to look at. Copying your .dll to \windows\system32 (at least for debugging purposes) if all else fails.
Otherwise, your .dll might be dependent on "something else". Such as a specific MSVC runtime. "depends" (GUI) or "dumpbin" (cmd-line)_ should tell you.
I'm assuming your .dll is NOT a COM/ActiveX .dll, and the problem is that you haven't registered it. Frankly, that's worth double-checking, too.
PS:
You can run dumpbin from the "MSVS Developer Command Prompt".
You can type dumpbin /?
to see the options. You want dumpbin /dependents mydll.dll
.
If it turns out you need MSVC runtime, you can download it here:
https://www.microsoft.com/en-us/download/details.aspx?id=48145
Upvotes: 1