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 / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

regasm exports unmanaged classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anthony Evans - 09 Sep 2004 08:59 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 the name collision in this manner).

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

Dim x As MyLibrary. <-- right here, VB6 lists the available classes

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
Ronald Laeremans [MSFT] - 19 Sep 2004 20:52 GMT
Added a more directly appropriate newsgroups and set follow-ups to that
newsgroup.

Ronald Laeremans
Visual C++ team

> Greetings
>
[quoted text clipped - 33 lines]
>
> Tony
Anthony Evans - 20 Sep 2004 04:20 GMT
Hello Ronald

Thank you for your efforts, however I actually posted to languages.vc
first.  No one has responded to my original thread there.

Tony

> Added a more directly appropriate newsgroups and set follow-ups to that
> newsgroup.
[quoted text clipped - 7 lines]
> > contains managed classes that wrap legacy unmanaged classes by the
> > same name.

<snip
Ronald Laeremans [MSFT] - 30 Sep 2004 20:25 GMT
I redirected this to the interop newsgroup. Which is where the experts on
this hang out., including the team that wrote regasm.

Ronald

> Hello Ronald
>
[quoted text clipped - 16 lines]
>
> <snip
Anthony Evans - 30 Sep 2004 21:51 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.
Anthony Evans - 30 Sep 2004 21:52 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.