Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

regasm exports private unmanaged classes?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anthony Evans - 09 Sep 2004 19:55 GMT
Greetings

I'm using VC++.NET to create a class library.  The class library
contains managed classes that wrap legacy unmanaged classes by the
same name.

I use regasm to register the DLL for COM interop.

If I don't include any managed classes in the library, the context
help in VB6 lists every single unmanaged class in the class library
(even though those classes are not declared with the public keyword.)

If I include managed classes in the class library (in addition to the
aforementioned unmanaged ones), the context help in VB6 lists only the
managed classes.

If the managed classes have the same names as the unmanaged classes,
the VB6 context help shows the class name with the library name and an
underscore prepended (eg: MyLibrary_MyClass instead of MyClass), and
as before, does not show the unmanaged ones (which seems to defeat the
purpose of resolving name collisions in this manner).

When I say "context help", I mean when I type

Dim x As MyLibrary. <-- VB6 lists the available classes after I hit
the period.

When I run regasm in verbose mode, it happily declares that it is
exporting every class in the class library, including the old
unmanaged ones that are, I assume implicitly scoped as "private".

How do I tell regasm (or VC++.NET 2003 or whatever) to only export the
classes marked as public and thus, not to attempt to resolve name
collisions with underscores?

Thanks in advance.

Tony
Phil Wilson - 10 Sep 2004 00:34 GMT
The ComVisible attribute should help (set it false) but I don't know if it
can be applied to unmanaged classes.
Signature

Phil Wilson [MVP Windows Installer]
----

> Greetings
>
[quoted text clipped - 34 lines]
>
> Tony
Anthony Evans - 19 Sep 2004 05:17 GMT
Thank you for your reply, Phil.

Whenever I try to use the ComVisible attribute on unmanaged classes,
the compiler complains:

error C2337: 'ComVisible' : attribute not found; it is neither a
built-in nor a custom attribute that is accessible in the current
namespace

If I move the classes in question in to the current namespace, there
will be naming conflicts between them and the managed classes of the
same name... and I can't rename the unmanaged classes because code
depends on them.

I know I could kludge around the problem by renaming the managed
classes, but this would present other problems that I don't want to go
in to.

Any other suggestions, anyone?

Thanks
Tony

> The ComVisible attribute should help (set it false) but I don't know if it
> can be applied to unmanaged classes.

<snip
Robert Jordan - 19 Sep 2004 11:35 GMT
> Thank you for your reply, Phil.
>
[quoted text clipped - 4 lines]
> built-in nor a custom attribute that is accessible in the current
> namespace

Either

using System.Runtime.InteropServices;

or

[System.Runtime.InteropServices.ComVisible(false)]

bye
REob

> If I move the classes in question in to the current namespace, there
> will be naming conflicts between them and the managed classes of the
[quoted text clipped - 14 lines]
>
> <snip
Anthony Evans - 20 Sep 2004 04:18 GMT
Thank you for your response, Robert.

Your approach yields:

error C3729: 'MyClass': is not managed; a custom attribute
'System::Runtime::InteropServices::ComVisibleAttribute' can only be
applied to a managed type

> > Thank you for your reply, Phil.
> >
[quoted text clipped - 15 lines]
> bye
> REob

<snip
Anthony Evans - 30 Sep 2004 21:50 GMT
I spoke with David King, a Volt contractor at Microsoft Product
Support.

He told me that this was a "known limitation of the compiler."  He
suggested the following work-arounds:

1. Modify the source components to avoid creating the problem in the
first place. This is the most robust, and recommended, solution. For
example, choose sufficiently unique names for public symbols, given
the preceding information. Creating .NET components that work well
when exposed to COM clients usually involves some compromises (e.g.
anticipating the flattening of namespaces).

2. Modify client usage of the resulting library.
   a) The C++ #import statement allows selective renaming of imported
symbols: #import "msrepro.dll" rename ("msrepro_Class1", "Class1")
   b) VB6 (and other) clients have no such option.

3. Forego automated wrapper (interop) generation and write your own
COM-callable wrapper library. VC++ 7.1 supports mixed
managed/unmanaged code that would allow you to directly use a .NET
library from within a ‘traditional' C++ COM library, which would then
expose it's own interface to bridge COM clients to the .NET DLL.

4. Modify the exported type library. The only way to do this is to
decompile the type library to IDL, modify it (e.g. rename symbols),
and recompile. tlbexp.exe, any text editor and midl.exe may be used to
perform each of these actions, respectively.

I'll probably go with #4.  I'll post back here if it doesn't work.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.