Why I can not compile this interface?

G

Guest

//This is my interface
namespace MyGroupPolicyObject
{
[ComImport, Guid("EA502723-A23D-11d1-A7D3-0000F87571E3"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGroupPolicyObject
{
void GetDisplayName(
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName,
int cchMaxLength);
}
}


//this is my other class

using MyGroupPolicyObject;

namespace DomainGroupPolicy
{
public string m_gpName;
public class CommandLineProcess : IGroupPolicyObject
{
MyGroupPolicyObject gpo = new MyGroupPolicyObject();
m_gpName = gpo.GetDisplayName(strname, sizeof(strname));
}
}
 
J

Joanna Carter [TeamB]

"ttan" <[email protected]> a écrit dans le message de (e-mail address removed)...

| //This is my interface
| namespace MyGroupPolicyObject
| {
| [ComImport, Guid("EA502723-A23D-11d1-A7D3-0000F87571E3"),
| InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
| public interface IGroupPolicyObject
| {
| void GetDisplayName(
| [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName,
| int cchMaxLength);
| }
| }

The interface compiles fine, the rest is uncompilable code.

| //this is my other class
|
| using MyGroupPolicyObject;
|
| namespace DomainGroupPolicy
| {
| public string m_gpName;

this string is not a member of a class

| public class CommandLineProcess : IGroupPolicyObject
| {

The class does not implement the interface

| MyGroupPolicyObject gpo = new MyGroupPolicyObject();
| m_gpName = gpo.GetDisplayName(strname, sizeof(strname));

This code belones in a method, it cannot be declared without.

| }
| }

Joanna
 
B

Ben Voigt

Joanna Carter said:
"ttan" <[email protected]> a écrit dans le message de (e-mail address removed)...

| //This is my interface
| namespace MyGroupPolicyObject
| {
| [ComImport, Guid("EA502723-A23D-11d1-A7D3-0000F87571E3"),
| InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
| public interface IGroupPolicyObject
| {
| void GetDisplayName(
| [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName,
| int cchMaxLength);
| }
| }

The interface compiles fine, the rest is uncompilable code.

| //this is my other class
|
| using MyGroupPolicyObject;
|
| namespace DomainGroupPolicy
| {
| public string m_gpName;

this string is not a member of a class

| public class CommandLineProcess : IGroupPolicyObject
| {

The class does not implement the interface

| MyGroupPolicyObject gpo = new MyGroupPolicyObject();

and finally, MyGroupPolicyObject is a namespace, not a class, so you can't
use "new".
 

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