import vb.net class library to vb6 project

最后都变了- 提交于 2019-12-11 03:00:14

问题


I have created a vb.net class library. It is an interface for a storage device. It gives some objects and methods in order to read and write data to the device.

The problem is that a customer has a vb6 application where we want to add the functionality of the class library in order to manipulate the device. i have changed the classes to com classes, checked the com interopt checkbox and registered the library with .net framework 2.0 regasm.exe.

I added the library as reference to a blank vb6 project and created an object.

dim t as comlib.obj

the object was equal to 'nothing'

when I added:

t = new comlib.obj

or

 t = createobject("comlib.obj")

I got the following error:

run-time error '2147024894 (80070002)': Automation

what am I doing wrong?


回答1:


Just dimming a variable doesn't assign it a value (the same as a .NET private TypeName variableName;), you need to create it first using Set T = New Comlib.Obj.

If you get an error from this, you need to use standard debugging techniques to narrow it down, or maybe post your full error message and someone can advise.




回答2:


I would say that @Deanna has the solution but if that fails then

I would suggest that you need to look at your constructor in the .NET assembly and make sure this is not throwing any sort of runtime error.

Even if you have an error handler in your New Sub it will not be raised up to the VB6 app.

I have followed a convention to keep my .NET constructor to a bare minimum and then use an additional method the do the construction code (LoadData for example). This way you can have an appropriate error handler. If an error is then thrown - it is raised into VB6 correctly.



来源:https://stackoverflow.com/questions/8562819/import-vb-net-class-library-to-vb6-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!