Calling a Win32 Dll

  • Thread starter Thread starter nbotw
  • Start date Start date
N

nbotw

Hi,

I need a function call in my xml web service. I have an old win32 dll and i
have created a class to have my declaration in.

Imports System.Runtime.InteropServices

[...]

Public Class Win32
<Declaration>
End Class


Public Class myClass
Dim objW32 as new Win32()
sRet = objW32.myFunction()

[...]
End Class

If i declare the library with:
Declare Function calcular_firma Lib "c:\VInetRT\componentes\libtpv.dll" (
....params...) as short

i get ERROR: 91 "Referencia a objeto no establecida como instancia de un
objeto."
mmm ... i guess this is like: "Object not set ..."

And if i use the declaration:
<DllImport("c:\VInetRT\componentes\libtpv.dll")> _
Public Function calcular_firma( ...params... ) As Short
End Function

i get: ERROR 5: "Error: el elemento PInvoke (campo,método) debe ser
estático."
Something like "PInvoke element must be static"


Did anybody deales with this ??
Thank you in advance
 
i get: ERROR 5: "Error: el elemento PInvoke (campo,método) debe ser
estático."
Something like "PInvoke element must be static"

All functions with DllImport attribute must be declared with "Shared"
keyword
 
Thank you for your answer,

I added de "Shared" keyword, but the problem remains
:(

91 "Referencia a objeto no establecida como instancia de un
objeto."
my translation: "Objet reference nos stablished as an object instance"

Best
 
Thank you for your answer,
I added de "Shared" keyword, but the problem remains
:(

91 "Referencia a objeto no establecida como instancia de un
objeto."
my translation: "Objet reference nos stablished as an object instance"
Show your code, maybe we will find the solution
 
The problem were that the function needed one of the params as s fixed
length string, and when i used the migration wizard from VB6, this was
modified.

I did a little routine form dimension the string to a size needed, and it
works !
So the sentence "Declare Function" was enough, but ..

How can i define a fixed lenght string in VB.NET ??? :-)

Thank you for your help.
 
nbotw said:
The problem were that the function needed one of the params as s fixed
length string, and when i used the migration wizard from VB6, this was
modified.

I did a little routine form dimension the string to a size needed, and it
works !
So the sentence "Declare Function" was enough, but ..

How can i define a fixed lenght string in VB.NET ??? :-)
Try to experiment with MarshalAs attribute
Don't know how to write it in VB, so C#: [MarshalAs(UnmanagedType.(try here
some variations), SizeConst=8)]
 
Back
Top