|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Interop and Constants ProblemI have built a VB.NET, VS 2005 class library that is exposed to VB6/COM clients. Everything works as expected except for the fact that Constants (Const) are NOT being exported to the VB6/COM type library; they are not visible. I have tried every trick in the book to force .NET constants to be available to VB6/COM, but to no avail. Enumerators appear correctly, but I need String (Public Const Test As String = "MyString") type constants as opposed to the numeric (Integer) type Enumerator members (Test = 5); I have no choice, I cannot use Enumerators as they only store numeric values. Is there any way to accomplish this. I basically want to avoid the VB6/COM developer from having to guess which constant value to use; or if there were to be a modification, that it would be available immediately. Can anyone please help? Regards, Giovanni Giovanni wrote:
Show quote > Hi, The solution is not to use constants.> > I have built a VB.NET, VS 2005 class library that is exposed to VB6/COM > clients. Everything works as expected except for the fact that Constants > (Const) are NOT being exported to the VB6/COM type library; they are not > visible. I have tried every trick in the book to force .NET constants to be > available to VB6/COM, but to no avail. Enumerators appear correctly, but I > need String (Public Const Test As String = "MyString") type constants as > opposed to the numeric (Integer) type Enumerator members (Test = 5); I have > no choice, I cannot use Enumerators as they only store numeric values. > > Is there any way to accomplish this. I basically want to avoid the > VB6/COM developer from having to guess which constant value to use; or if > there were to be a modification, that it would be available immediately. > > Can anyone please help? > > > Regards, > > Giovanni > Constants doesn't really exist, that is why they are not exposed in the COM+ interface. They are just named values, that when used in the code will be replaced by the actual value. As the constants are replaced during the compilation, that means that if you change a constant in a library, you can't just replace the library dll and expect the changed value of the constant to be used. You have to recompile all code that is using the constant for the change to take effect. Create read-only properties instead of the constants. They will be exposed in the COM+ interface, and all code that uses them will get the value from the library at run time instead of replacing it during compilation. Hi Goran,
Thanks for your help. I'll give it a shot. I was heading towards using readonly properties; I figured it would be the only resort. Thanks again. Regards, Giovanni Show quote "Göran Andersson" wrote: > Giovanni wrote: > > Hi, > > > > I have built a VB.NET, VS 2005 class library that is exposed to VB6/COM > > clients. Everything works as expected except for the fact that Constants > > (Const) are NOT being exported to the VB6/COM type library; they are not > > visible. I have tried every trick in the book to force .NET constants to be > > available to VB6/COM, but to no avail. Enumerators appear correctly, but I > > need String (Public Const Test As String = "MyString") type constants as > > opposed to the numeric (Integer) type Enumerator members (Test = 5); I have > > no choice, I cannot use Enumerators as they only store numeric values. > > > > Is there any way to accomplish this. I basically want to avoid the > > VB6/COM developer from having to guess which constant value to use; or if > > there were to be a modification, that it would be available immediately. > > > > Can anyone please help? > > > > > > Regards, > > > > Giovanni > > > > The solution is not to use constants. > > Constants doesn't really exist, that is why they are not exposed in the > COM+ interface. They are just named values, that when used in the code > will be replaced by the actual value. > > As the constants are replaced during the compilation, that means that if > you change a constant in a library, you can't just replace the library > dll and expect the changed value of the constant to be used. You have to > recompile all code that is using the constant for the change to take effect. > > Create read-only properties instead of the constants. They will be > exposed in the COM+ interface, and all code that uses them will get the > value from the library at run time instead of replacing it during > compilation. > > -- > Göran Andersson > _____ > http://www.guffa.com > |
|||||||||||||||||||||||