Newbie Question

S

S Shulman

I added the following declaration withing a namespace but not within a class


[DllImport("user32.dll", EntryPoint="SendMessage", CharSet=CharSet.Auto )]

public static extern int SendCharFmtMsg( IntPtr hWnd, int Msg, int wParam,

ref CHARFORMAT2 cf2 );

And UI get the following compiler error
C:\Componenets\ABC\ABCColor\Class1.cs(11): Expected class, delegate, enum,
interface, or struct


Thank you,
Shmuel Shulman
 
G

Guest

Hi Shmuel,
do you have the type CHARFORMAT2 defined in you code or in a linked DLL,
if not this might be the source of your problem.
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

you have to put it inside a class, in c# you cannot have global methods,
they need to be part of a class.

cheers,
 
S

S Shulman

I had both problems and it is now OK

I was wondering why the compiler gave me such a funny error

Thanks,
Shmuel


Ignacio Machin ( .NET/ C# MVP ) said:
hi,

you have to put it inside a class, in c# you cannot have global methods,
they need to be part of a class.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


S Shulman said:
I added the following declaration withing a namespace but not within a
class


[DllImport("user32.dll", EntryPoint="SendMessage",
CharSet=CharSet.Auto )]

public static extern int SendCharFmtMsg( IntPtr hWnd, int Msg, int
wParam,

ref CHARFORMAT2 cf2 );

And UI get the following compiler error
C:\Componenets\ABC\ABCColor\Class1.cs(11): Expected class, delegate,
enum, interface, or struct


Thank you,
Shmuel Shulman
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

It gave you a correct description of the problem, clear as water :)

It said that at that location only a class, delegate, enum, interface, or
struct can be declared, nothing more

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation




S Shulman said:
I had both problems and it is now OK

I was wondering why the compiler gave me such a funny error

Thanks,
Shmuel


Ignacio Machin ( .NET/ C# MVP ) said:
hi,

you have to put it inside a class, in c# you cannot have global methods,
they need to be part of a class.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


S Shulman said:
I added the following declaration withing a namespace but not within a
class


[DllImport("user32.dll", EntryPoint="SendMessage",
CharSet=CharSet.Auto )]

public static extern int SendCharFmtMsg( IntPtr hWnd, int Msg, int
wParam,

ref CHARFORMAT2 cf2 );

And UI get the following compiler error
C:\Componenets\ABC\ABCColor\Class1.cs(11): Expected class, delegate,
enum, interface, or struct


Thank you,
Shmuel Shulman
 
I

Ignacio Machin \( .NET/ C# MVP \)

no it's not

It may be a problem but the compiler error clearly stated that he tried to
declare a method where only a class, delegate, enum, interface, or struct is
accepted.


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Mark R. Dawson said:
Hi Shmuel,
do you have the type CHARFORMAT2 defined in you code or in a linked DLL,
if not this might be the source of your problem.

S Shulman said:
I added the following declaration withing a namespace but not within a
class


[DllImport("user32.dll", EntryPoint="SendMessage",
CharSet=CharSet.Auto )]

public static extern int SendCharFmtMsg( IntPtr hWnd, int Msg, int
wParam,

ref CHARFORMAT2 cf2 );

And UI get the following compiler error
C:\Componenets\ABC\ABCColor\Class1.cs(11): Expected class, delegate,
enum,
interface, or struct


Thank you,
Shmuel Shulman
 

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