Home All Groups Group Topic Archive Search About

Calling a VB.NET-DLL FROM VB6

Author
6 Sep 2006 11:48 AM
Peter Piry
hi,

I've writte a DLL in VB.NET which is called from VB6.

When I try to call some methods of the DLL in a sub Procedure I get the following error: "Object reference not set to an instance of
an object."

this is my code in VB6 (simplified)



Sub Main
Dim myDLL as new Wrapper.Wrapper

'this works
myDLL.CallMethod
End Sub

But when i try this, I get an error:

Sub Main

Dim myDLL as new Wrapper.Wrapper

Call callMethodFromDLL


End Sub

Sub callMethodFromDLL(ByRef myDLL as Wrapper.Wrapper)

'here i get the error
myDLL.CallMethod

End Sub

Has anyone an idea?

br
Peter

Author
6 Sep 2006 1:19 PM
Phill W.
Peter Piry wrote:

> I've writte a DLL in VB.NET which is called from VB6.
>
> When I try to call some methods of the DLL in a sub Procedure I get the
> following error: "Object reference not set to an instance of an object."

Do you get this error on /some/ methods, or on *all* of them?

> But when i try this, I get an error:
>
> Sub Main
>
> Dim myDLL as new Wrapper.Wrapper
>
> Call callMethodFromDLL
>
> End Sub
>
> Sub callMethodFromDLL(ByRef myDLL as Wrapper.Wrapper)
>
> 'here i get the error

What error???
/You've/ seen it - /we/ haven't ...

> myDLL.CallMethod
>
> End Sub

Are you /sure/ that's where the error is?
The above code won't even compile.

callMethodFromDLL requires one argument - a reference to your Wrapper
object.  According to the above, you haven't supplied one.

Sub Main
    Dim myDLL as new Wrapper.Wrapper
    Call callMethodFromDLL( myDLL )
End Sub

HTH,
    Phill  W.
Author
6 Sep 2006 2:28 PM
Peter Piry
Show quote Hide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message news:edmhsm$55t$1@south.jnrs.ja.net...
> Peter Piry wrote:
>
>> I've writte a DLL in VB.NET which is called from VB6.
>>
>> When I try to call some methods of the DLL in a sub Procedure I get the
>> following error: "Object reference not set to an instance of an object."
>
> Do you get this error on /some/ methods, or on *all* of them?
>
>> But when i try this, I get an error:
>>
>> Sub Main
>>
>> Dim myDLL as new Wrapper.Wrapper
>>
>> Call callMethodFromDLL
>>
>> End Sub
>>
>> Sub callMethodFromDLL(ByRef myDLL as Wrapper.Wrapper)
>>
>> 'here i get the error
>
> What error???
> /You've/ seen it - /we/ haven't ...
>
>> myDLL.CallMethod
>>
>> End Sub
>
> Are you /sure/ that's where the error is?
> The above code won't even compile.
>
> callMethodFromDLL requires one argument - a reference to your Wrapper
> object.  According to the above, you haven't supplied one.

yes, sorry, i've forgotten to write the Argument. The right line: Call callMethodFromDLL(mydll). i have this line in my code.

Show quoteHide quote
>
> Sub Main
>    Dim myDLL as new Wrapper.Wrapper
>    Call callMethodFromDLL( myDLL )
> End Sub
>
> HTH,
>    Phill  W.
Author
6 Sep 2006 3:58 PM
Kristian Frost
I know we're only working with pseudocode here, but is the problem that =
=

you haven't called your constructor?
I've dug out the one time I ever used a COM object in VB6, and the code =
=

there says, basically:

dim namedCOMObject as COMObject
namedCOMOBJECT =3D new COMObject

If you're calling methods to the COM object directly, they may work  =

without you having an instance of the object, but if you want to use  =

information from an instance of the object, I'm fairly certain you have =
to  =

spread constructing it over two lines, as above.

I'm only a student though. I might be talking nonsense

KF



On Wed, 06 Sep 2006 15:28:56 +0100, Peter Piry <peter.p***@reflex.at>  =

wrote:

Show quoteHide quote
>
> "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message  =

> news:edmhsm$55t$1@south.jnrs.ja.net...
>> Peter Piry wrote:
>>
>>> I've writte a DLL in VB.NET which is called from VB6.
>>>  When I try to call some methods of the DLL in a sub Procedure I get=
  =

>>> the following error: "Object reference not set to an instance of an =
=

>>> object."
>>  Do you get this error on /some/ methods, or on *all* of them?
>>
>>> But when i try this, I get an error:
>>>  Sub Main
>>>  Dim myDLL as new Wrapper.Wrapper
>>>  Call callMethodFromDLL
>>>  End Sub
>>>  Sub callMethodFromDLL(ByRef myDLL as Wrapper.Wrapper)
>>>  'here i get the error
>>  What error???
>> /You've/ seen it - /we/ haven't ...
>>
>>> myDLL.CallMethod
>>>  End Sub
>>  Are you /sure/ that's where the error is?
>> The above code won't even compile.
>>  callMethodFromDLL requires one argument - a reference to your Wrappe=
r  =

>> object.  According to the above, you haven't supplied one.
>
> yes, sorry, i've forgotten to write the Argument. The right line: Call=
  =

> callMethodFromDLL(mydll). i have this line in my code.
>
>>  Sub Main
>>    Dim myDLL as new Wrapper.Wrapper
>>    Call callMethodFromDLL( myDLL )
>> End Sub
>>  HTH,
>>    Phill  W.



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Author
7 Sep 2006 12:15 PM
Peter Piry
"Kristian Frost" <kfr***@gmail.com> wrote in message news:op.tfgrzheml8r4f3@rndskycomwin.domain...
I know we're only working with pseudocode here, but is the problem that 
you haven't called your constructor?
I've dug out the one time I ever used a COM object in VB6, and the code 
there says, basically:

dim namedCOMObject as COMObject
namedCOMOBJECT = new COMObject

If you're calling methods to the COM object directly, they may work 
without you having an instance of the object, but if you want to use 
information from an instance of the object, I'm fairly certain you have to 
spread constructing it over two lines, as above.

I'm only a student though. I might be talking nonsense

KF



On Wed, 06 Sep 2006 15:28:56 +0100, Peter Piry <peter.p***@reflex.at> 
wrote:

Show quoteHide quote
>
> "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message 
> news:edmhsm$55t$1@south.jnrs.ja.net...
>> Peter Piry wrote:
>>
>>> I've writte a DLL in VB.NET which is called from VB6.
>>>  When I try to call some methods of the DLL in a sub Procedure I get 
>>> the following error: "Object reference not set to an instance of an 
>>> object."
>>  Do you get this error on /some/ methods, or on *all* of them?
>>
>>> But when i try this, I get an error:
>>>  Sub Main
>>>  Dim myDLL as new Wrapper.Wrapper
>>>  Call callMethodFromDLL
>>>  End Sub
>>>  Sub callMethodFromDLL(ByRef myDLL as Wrapper.Wrapper)
>>>  'here i get the error
>>  What error???
>> /You've/ seen it - /we/ haven't ...
>>
>>> myDLL.CallMethod
>>>  End Sub
>>  Are you /sure/ that's where the error is?
>> The above code won't even compile.
>>  callMethodFromDLL requires one argument - a reference to your Wrapper 
>> object.  According to the above, you haven't supplied one.
>
> yes, sorry, i've forgotten to write the Argument. The right line: Call 
> callMethodFromDLL(mydll). i have this line in my code.
>
>>  Sub Main
>>    Dim myDLL as new Wrapper.Wrapper
>>    Call callMethodFromDLL( myDLL )
>> End Sub
>>  HTH,
>>    Phill  W.



Hi,

I've solved the problem. It was a writing protection on the document, which the sub procedure opens.

Mysteriously it works at the first time.

br
Peter