From: Alan Sloan on
I need to create a .net class library (dll) that contains nothing but a
bunch of constants. It doesn't matter if it's VB.NET or C#, but it must be
exposed to COM so that a legacy VB6 project can reference it and use the
constants contained within the dll.

Let's see if I can explain this clearly. I have created a C# dll which
contains several classes and within those classes are the constants. Such
as:

using System; namespace MyConstantLib {
public sealed class ItemConstants : CommonConstants
{
public static readonly Int32 CLASS_ITEM_BASE_CLASS = 901;
public static readonly Int32 CLASS_DOCUMENTS_CLASS = 9000;
public static readonly Int32 CLASS_DOCUMENT = 9141;
.....
}

The VB app can "See" and reference the DLL, and It will Intellisense all the
way to the class in the dll. For example, I can do this in VB

Dim dllRef as MyConstLib.ItemConstants

But I cannot get to the individual constants in the "object" (i.e.
CLASS_ITEM_BASE_CLASS const). What am I missing?

Even better yet would be that once my dll is referenced in VB these
constants would show up at the first level of the Intellisense list (right
there when you press ctrl+space) without needing to Dim an object to get to
them.

Any help would be greatly appreciated.

Thanks in advance,
Alan


From: Scott M. on

"Alan Sloan" <NoSpam(a)comcast.net> wrote in message
news:%23zyY8U0rKHA.1796(a)TK2MSFTNGP02.phx.gbl...
>I need to create a .net class library (dll) that contains nothing but a
>bunch of constants. It doesn't matter if it's VB.NET or C#, but it must be
>exposed to COM so that a legacy VB6 project can reference it and use the
>constants contained within the dll.
>
> Let's see if I can explain this clearly. I have created a C# dll which
> contains several classes and within those classes are the constants. Such
> as:
>
> using System; namespace MyConstantLib {
> public sealed class ItemConstants : CommonConstants
> {
> public static readonly Int32 CLASS_ITEM_BASE_CLASS = 901;
> public static readonly Int32 CLASS_DOCUMENTS_CLASS = 9000;
> public static readonly Int32 CLASS_DOCUMENT = 9141;
> .....
> }
>
> The VB app can "See" and reference the DLL, and It will Intellisense all
> the way to the class in the dll. For example, I can do this in VB
>
> Dim dllRef as MyConstLib.ItemConstants
>
> But I cannot get to the individual constants in the "object" (i.e.
> CLASS_ITEM_BASE_CLASS const). What am I missing?
>
> Even better yet would be that once my dll is referenced in VB these
> constants would show up at the first level of the Intellisense list (right
> there when you press ctrl+space) without needing to Dim an object to get
> to them.
>
> Any help would be greatly appreciated.
>
> Thanks in advance,
> Alan

If you make sure that your VB project, not only references the C# .dll, but
also includes:

Imports MyConstLib.ItemConstants

then it will work (it did for me). You will be able to access your
constants with no qualification as you desire.

-Scott


From: Patrice on
> The VB app can "See" and reference the DLL, and It will Intellisense all
> the way to the class in the dll. For example, I can do this in VB
>
> Dim dllRef as MyConstLib.ItemConstants
>
> But I cannot get to the individual constants in the "object" (i.e.
> CLASS_ITEM_BASE_CLASS const). What am I missing?
>
> Even better yet would be that once my dll is referenced in VB these
> constants would show up at the first level of the Intellisense list (right
> there when you press ctrl+space) without needing to Dim an object to get
> to them.

Hi,

Not sure why you inherit from a CommonConstants class but I would just use
Enums. It should solve both problems and seems more natural for the usage
you seems to have..

If for some reason you want to keep using static, I would try to explicitely
define the class as being static (or perhaps is this just that is not
supported on the COM/VB6 side)...

--
Patrice




From: Alan Sloan on
Thanks Scott, however this dll will be referenced by a VB6 app, which has no
Import like VB.NET

"Scott M." <s-mar(a)nospam.nospam> wrote in message
news:egtReo1rKHA.4752(a)TK2MSFTNGP04.phx.gbl...
>
> "Alan Sloan" <NoSpam(a)comcast.net> wrote in message
> news:%23zyY8U0rKHA.1796(a)TK2MSFTNGP02.phx.gbl...
>>I need to create a .net class library (dll) that contains nothing but a
>>bunch of constants. It doesn't matter if it's VB.NET or C#, but it must
>>be exposed to COM so that a legacy VB6 project can reference it and use
>>the constants contained within the dll.
>>
>> Let's see if I can explain this clearly. I have created a C# dll which
>> contains several classes and within those classes are the constants.
>> Such as:
>>
>> using System; namespace MyConstantLib {
>> public sealed class ItemConstants : CommonConstants
>> {
>> public static readonly Int32 CLASS_ITEM_BASE_CLASS = 901;
>> public static readonly Int32 CLASS_DOCUMENTS_CLASS = 9000;
>> public static readonly Int32 CLASS_DOCUMENT = 9141;
>> .....
>> }
>>
>> The VB app can "See" and reference the DLL, and It will Intellisense all
>> the way to the class in the dll. For example, I can do this in VB
>>
>> Dim dllRef as MyConstLib.ItemConstants
>>
>> But I cannot get to the individual constants in the "object" (i.e.
>> CLASS_ITEM_BASE_CLASS const). What am I missing?
>>
>> Even better yet would be that once my dll is referenced in VB these
>> constants would show up at the first level of the Intellisense list
>> (right there when you press ctrl+space) without needing to Dim an object
>> to get to them.
>>
>> Any help would be greatly appreciated.
>>
>> Thanks in advance,
>> Alan
>
> If you make sure that your VB project, not only references the C# .dll,
> but also includes:
>
> Imports MyConstLib.ItemConstants
>
> then it will work (it did for me). You will be able to access your
> constants with no qualification as you desire.
>
> -Scott
>


From: Patrice on
> Patrice, using enums worked great, except that some of the constants that
> I need to expose to COM are strings and enums can't "do" strings. Any
> ideas on how to accomplish the same result with strings?

Never tried, but my first try would be to expose them as constants (using
the "const" keyword)...

--
Patrice