Hi
I am trying to solve a problem with COM interop from a C# project. My
C# projet is a Windows Forms project and there is a component that
derives from Forms class. The component also implements an interface
that exposes the ShowDialog method of the Forms class to COM clients
with the return type of DialogResult. The module compiles fine in .NET
1.1, but gives compile errors in .NET 2.0.
In my COM component, I import System.Windows.Forms.tlb and also import
my own .net assembly that has been registered for COM interop (using
regasm.exe).
Here is the pseudo code of my project:
[Guid("516768g2-0024-4d7a-9e51-7ae066t4798b")]
public class MyOwnDlg : System.Windows.Forms.Form, IMyOwnDlg
{
// implementation here
}
[Guid("8428r56c-afab-48d2-921f-17929955fgf6")]
public interface IMyOwnDlg
{
System.Windows.Forms.DialogResult ShowDialog();
}
When I compile my COM client, I get the following warnings and errors:
warning C4926: 'WinForms::DialogResult': symbol is already defined:
attributes ignored
error C3115: 'id': this attribute is not allowed on 'IMyOwnDlg'
predefined C++ attributes (compiler internal)(808) : see
declaration of 'id'
attribute can only be applied to: 'interface member function',
'interface member', 'IDL module'
Can anyone please point me to some documentation about this change or
shed some light on what could be going on and how do I fix this
problem?
Thanks in advance.
Amit - 13 Sep 2006 17:01 GMT
I found what the problem was. I was specifying the embedded_idl
attribute during the #import of the module. I dont understand why it
was causing a problem, but removing it fixed my problem.
Amit - 19 Sep 2006 13:15 GMT
Now I am in a fix...I found out that if I dont import the typelibrary
using the "embedded_idl" attribute, then I cannot use source interfaces
(event interfaces) from the imported typelibrary. I get this error:
error C3706: 'ITestEvents': must be a COM interface to fire COM events
This is annoying and frustrating. If I use embedded_idl attribute, I
get the other compile errors.
Please Help!
Thanks
amitjain
Amit - 20 Sep 2006 12:59 GMT
OK, I fixed the problem. The problem was that when importing
System.Windows.Forms.tlb, I was renaming the namespace from
System_Windows_Forms to WinForms and this was causing a problem for
some reason. After I replaced rename_namespace with no_namespace, my
project compiled without problems.