
Signature
Phil Wilson [MVP Windows Installer]
----
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.