problem with com object
Hi,
I must create a com object that has some methods described in an interface.
One of this methods isnew(par1,par2,par3) as short
The only problem is that i can't create a method with such name because it is seen as the constructor of the com object (and the constructor for the com object must have no parameters).
So when i write
Public
Functionnew(...) as shorti get the messageThe constructor must be declared as Sub and not as Function
I am not sure if there is way of solving this problem in VB.NET since what you are trying to achieve conflicts with the reserved method name New...but one way is to use C# for implementing this portion of the code and using the C# assembly from VB.NET.
Regards,
Vikram
http://dotnetupdate.blogspot.com/
Sergio VB wrote: |
Hi, I must create a com object that has some methods described in an interface. One of this methods is new(par1,par2,par3) as short
The only problem is that i can't create a method with such name because it is seen as the constructor of the com object (and the constructor for the com object must have no parameters). So when i write Public Function new(...) as shorti get the messageThe constructor must be declared as Sub and not as Function |
|
Sergio VB,
In order to get around this, you will have to create a parameterless constructor, and then have a method (most likely called Initialized) which you make sure is called every time a new instance is constructed.
If you are worried about this not being called, then you could create a class factory that will create the object, and make the call as well in one method.
Hope this helps.
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
Thanks for your answer, i did not knew this feature of .net.
However my problem is that i am writing the com "server" but the com "client" is already developed and so i can't force the client to call server.[New](par1,...).
Any other suggestion?