converting c# to COM

G

Guest

I have to create a COM dll from c# to use within old code. Every time I build
I get a new guid. I have tried to use the [Guid(...)] phrase before a class
or interface, but the compiler won't build due to the following messages:

Syntax error, ']' expected (shown after "[Guid" and before "("
A namespace does not directly contain members such as fields or methods
Type or namespace definition, or end-of-file expected


My code looks like:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace EvalAndReview
{
/// <summary>
/// Summary description for SpectCharts.
/// </summary>
///
// interface
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid{"1D99B653-4AD4-41c6-9D0F-46C366FB43A6"}]
public interface IDataReviewCharts
{
void ClearChart (int chart);
void SetRawSpectrumPointlist (int curve, int size);
void SetBGSubSpectrumPointlist (int curve, int size);
void SetLibSpectrumPointlist (int curve, int size);
void LoadRawSpectrumPoint (double x, double y);
void LoadBGSubSpectrumPoint (double x, double y);
void LoadLibSpectrumPoint (double x, double y);
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid{"1D99B653-4AD4-41c6-9D0F-46C366FB43A6"}]
public class DataReviewCharts : System.Windows.Forms.Form
{
...
}

Any help in getting this to build will be greatly appreciated.


Thanks
 
J

Jon Shemitz

woodworker said:
[Guid{"1D99B653-4AD4-41c6-9D0F-46C366FB43A6"}]

Try

[Guid("1D99B653-4AD4-41c6-9D0F-46C366FB43A6")]

The [] attribute syntax is a sort of shorthand for

new GuidAttribute("1D99B653-4AD4-41c6-9D0F-46C366FB43A6");
 
N

Nicholas Paldino [.NET/C# MVP]

Jon,

Not to bust chops, but it's not shorthand for "new <attribute type>",
just for the name of the type. You can't do this, for example:

new GuidAttribute("1D99B653-4AD4-41c6-9D0F-46C366FB43A6");
public class MyClass
{
...
}

It won't compile.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Jon Shemitz said:
woodworker said:
[Guid{"1D99B653-4AD4-41c6-9D0F-46C366FB43A6"}]

Try

[Guid("1D99B653-4AD4-41c6-9D0F-46C366FB43A6")]

The [] attribute syntax is a sort of shorthand for

new GuidAttribute("1D99B653-4AD4-41c6-9D0F-46C366FB43A6");
 
J

Jon Shemitz

Nicholas Paldino said:
The [] attribute syntax is a sort of shorthand for

new GuidAttribute("1D99B653-4AD4-41c6-9D0F-46C366FB43A6");
Not to bust chops, but it's not shorthand for "new <attribute type>",
just for the name of the type. You can't do this, for example:

new GuidAttribute("1D99B653-4AD4-41c6-9D0F-46C366FB43A6");
public class MyClass

I know, that's why I said "sort of" - I was just trying to make it a
little clearer why the [Guid{"1D99B653-4AD4-41c6-9D0F-46C366FB43A6"}]
syntax didn't work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top