DLLImports

J

John Dann

One detail about using DLLImports as part of the PInvoke process that
I don't understand:

I'm trying to access a function (eg MyFunction) in a 3rd party DLL so
I create a class:

Imports System.Runtime.InteropServices
Public Class Myclass
<DllImport("MyDLL")> _
Public Shared Function MyFunction()
End Function
End class

Then is there some way of calling MyFunction from within Myclass?

The only way I can get it to work at present is to instantiate Myclass
in another class and then call MyFunction via oMyclass.MyFunction.

JGD
 
A

Armin Zingler

John Dann said:
One detail about using DLLImports as part of the PInvoke process
that I don't understand:

I'm trying to access a function (eg MyFunction) in a 3rd party DLL
so I create a class:

Imports System.Runtime.InteropServices
Public Class Myclass
<DllImport("MyDLL")> _
Public Shared Function MyFunction()
End Function
End class

Then is there some way of calling MyFunction from within Myclass?

The only way I can get it to work at present is to instantiate
Myclass in another class and then call MyFunction via
oMyclass.MyFunction.

Why? What happens if you call it within Myclass? BTW, I think it is not
really MyClass because it is a reserved word, or it is "public class
[Myclass]". There is also the return type missing. Anyway, I have no problem
calling Myfunction within the class:

Public Class Myclass
<DllImport("MyDLL")> _
Public Shared Function MyFunction() As Integer
End Function

Sub test()
Dim i As Integer
i = MyFunction()
End Sub
End class




--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
H

Herfried K. Wagner [MVP]

John,

* John Dann said:
One detail about using DLLImports as part of the PInvoke process that
I don't understand:

I'm trying to access a function (eg MyFunction) in a 3rd party DLL so
I create a class:

Imports System.Runtime.InteropServices
Public Class Myclass
<DllImport("MyDLL")> _
Public Shared Function MyFunction()
End Function
End class

Then is there some way of calling MyFunction from within Myclass?

'MyClass' is a keyword, so don't call the class 'MyClass'.
The only way I can get it to work at present is to instantiate Myclass
in another class and then call MyFunction via oMyclass.MyFunction.

\\\
<class name>.<function name>(<arguments>)
///

You don't need an instance.
 

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