Calling a VB.NET-DLL FROM VB6

P

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
 
P

Phill W.

Peter said:
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.
 
P

Peter Piry

Phill W. said:
Do you get this error on /some/ methods, or on *all* of them?


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


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.
 
K

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 = 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
 
P

Peter Piry

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



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



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
 

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