|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Calling a VB.NET-DLL FROM VB6I'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 Peter Piry wrote:
> I've writte a DLL in VB.NET which is called from VB6. Do you get this error on /some/ methods, or on *all* of them?> > 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." > But when i try this, I get an error: What 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 /You've/ seen it - /we/ haven't ... > myDLL.CallMethod Are you /sure/ that's where the error is?> > End Sub 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.
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... yes, sorry, i've forgotten to write the Argument. The right line: Call callMethodFromDLL(mydll). i have this line in my code.> 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. Show quoteHide quote > > Sub Main > Dim myDLL as new Wrapper.Wrapper > Call callMethodFromDLL( myDLL ) > End Sub > > HTH, > Phill W. 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/ "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 > Hi,> "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. 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
Registry Reading
Remove certain characters from a string/RichTextBox? Better way to process many conditions with If Then Iterating through the records in a dataset Crystal Reports in VB.NET Determining max number of characters in a TextBox how to get a file to display from relative filespec Deleting a folder Save Radio Button setting SQL Server |
|||||||||||||||||||||||