Home All Groups Group Topic Archive Search About

How to access and use Unmanaged Code

Author
27 Jul 2006 11:10 AM
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

Author
27 Jul 2006 1:30 PM
Chris Dunaway
Michael wrote:

> 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?
Author
28 Jul 2006 12:25 PM
Michael
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.

Show quoteHide quote
"Chris Dunaway" <dunaw***@gmail.com> wrote in message
news:1154007001.060395.168870@b28g2000cwb.googlegroups.com...
> Michael wrote:
>
>> 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?
>
Author
28 Jul 2006 9:50 PM
Michael
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.

Show quoteHide quote
"Michael" <mconnol***@houston.rr.com> wrote in message
news:Dmnyg.22550$Cn6.15875@tornado.texas.rr.com...
> 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 Dunaway" <dunaw***@gmail.com> wrote in message
> news:1154007001.060395.168870@b28g2000cwb.googlegroups.com...
>> Michael wrote:
>>
>>> 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?
>>
>
>