Problem with calling a dll written in c - System.DllNotFoundException

P

pgugel

Hi!

I just got that Problem by calling a c-written dll - at runtime the
dll will not found: System.DllNotFoundException
I copied the dll in both project folders (debug/release), i imported
it into project-explorer and set property "copy always". I checked
methodname with dependens.exe - name is correct.
The documentation for the dll is:
Function Prototype :
extern "C" __declspec(dllexport) bool RHIO_SockConnect
(BYTE bAddr1, BYTE bAddr2, BYTE bAddr3, BYTE bAddr4,
int iPort);

I don't know the Problem???
I upload my vs-sample-project to: http://www.FastShare.org/download/SenaRHIO.zip

Here is my code that imports and calls a method:

Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")> _
Public Shared Function RHIO_SockConnect(ByVal bAddr1 As Byte,
ByVal bAddr2 As Byte, _
ByVal bAddr3 As Byte, ByVal bAddr4 As Byte, ByVal iPort As
Integer) As Boolean
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) _
Handles Button1.Click
If RHIO_SockConnect(192, 168, 0, 10, 6001) Then
MsgBox("Connection successful!")
Else
MsgBox("Connection failed!")
End If
End Sub
End Class


Thanx for your help!
 
O

Onur Güzel

Hi!

I just got that Problem by calling a c-written dll - at runtime the
dll will not found: System.DllNotFoundException
I copied the dll in both project folders (debug/release), i imported
it into project-explorer and set property "copy always". I checked
methodname with dependens.exe - name is correct.
The documentation for the dll is:
      Function Prototype :
               extern "C" __declspec(dllexport) bool RHIO_SockConnect
               (BYTE bAddr1, BYTE bAddr2, BYTE bAddr3, BYTE bAddr4,
int iPort);

I don't know the Problem???
I upload my vs-sample-project to:http://www.FastShare.org/download/SenaRHIO.zip

Here is my code that imports and calls a method:

Imports System.Runtime.InteropServices
Public Class Form1
    <DllImport("RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")> _
    Public Shared Function RHIO_SockConnect(ByVal bAddr1 As Byte,
ByVal bAddr2 As Byte, _
            ByVal bAddr3 As Byte, ByVal bAddr4 As Byte, ByValiPort As
Integer) As Boolean
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) _
        Handles Button1.Click
        If RHIO_SockConnect(192, 168, 0, 10, 6001) Then
            MsgBox("Connection successful!")
        Else
            MsgBox("Connection failed!")
        End If
    End Sub
End Class

Thanx for your help!

Hi,
You may need your dll located in system32 or root windows folder ("c:
\windows\system32" or "c:\windows" folder").

Plus, with no confirmation, try to specify the exact path of dll if
location is fixed as DllImport's first argument:
Like:
' eg: if it's in c:\RHIO folder
<DllImport("c:\RHIO\RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")>
_

' .....rest is same.

That also can be useful for searching hierachy:
http://msdn.microsoft.com/en-us/library/ms682586.aspx

HTH,

Onur Güzel
 
P

Patrick

Thanks for your comment, but after copy the dll to nearly everywhere
and testing to specify all the paths the Problem is still the same :(

Any other ideas?
 
P

Patrick

Hi!

I got the solution! It was the dll-path:

<DllImport("RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")> ... do
not work
<DllImport("../RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")> ...
work fine

So a few dots and a line sometimes makes the different...
 
O

Onur Güzel

Hi!

I got the solution! It was the dll-path:

<DllImport("RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")> ... do
not work
<DllImport("../RHIO_Proc.dll", EntryPoint:="RHIO_SockConnect")> ...
work fine

So a few dots and a line sometimes makes the different...

Glad you did it :)

Onur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top