How to access and use Unmanaged Code

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Newbie question

I am trying to access external code from within VB using DLLimport in the
form below where testsub is the procedure name within the DLL

<DllImport("MyDll.dll", EntryPoint:="testsub", SetLastError:=True, _
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub _
Test(ByVal JOB As Char, ByRef A(,) as Double)

When calling the routine from VB.Net I keep on getting an "Object reference
not set to instance object" error

Have tried to register the DLL but can't and tblimp will not work either as
the code is created outside of VB net

Does anyone have any ideas on what the issue is and how to solve it. Any
references to articles on how to work with DLL's from within VB would also
be appreciated

Thanks

Mike
 
Michael said:
I am trying to access external code from within VB using DLLimport in the
form below where testsub is the procedure name within the DLL

<DllImport("MyDll.dll", EntryPoint:="testsub", SetLastError:=True, _
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub _
Test(ByVal JOB As Char, ByRef A(,) as Double)

When calling the routine from VB.Net I keep on getting an "Object reference
not set to instance object" error

Can you post the stack trace when you get that exception? Where does
the error occur? Can you debug the app and step through the code to
find the line where the exception is thrown?
 
Chris

Thanks for the reply

I have managed to get past the Object reference but now I am encountering an
error when running the application.

The error I am getting is "Unable to load DLL filename"

I have tried to reference the DLL within net but can't as net does not
recognize it as a valid assembly or COM object. I know its OK as I can get
Microsoft Depends to open it and read the import/export ordinal and other
data etc.

I have tried to register it via regasm and AL neither will accept it.

I have tried putting the dll in the system folder, windows folder, along
with the default project path

Nothing seems to work.

To investigate further I created a simple fortran function to add two
integers and reference it using the using the declare statement in VB. The
same exact problem results - unable to load DLL during execution.

I guess the issue is how do you get net to recognize a dll that was
constructed outside of net ie "unmanaged"?????????

Can you help?

Thanks

Mike C.
 
Chris

Solved the problem. the dll had to be placed in the bin directory when
using the Development interface not the vbproj directory.

Thanks for the help

Mike C.
 
Back
Top