C# - Dll questions

M

Mr. X.

Hello,

In C# ...
1. I have tried to write to Console : "Hello world" by
Console.WriteLine("Hello world"), but I cannot see the console screen.
2. How can I show a MessageBox in a class Library (dll) instead of console.
Need some samples, please.

Thanks :)
 
B

bradbury9

El miércoles, 23 de mayo de 2012 15:41:48 UTC+2, Mr. X. escribió:
Hello,

In C# ...
1. I have tried to write to Console : "Hello world" by
Console.WriteLine("Hello world"), but I cannot see the console screen.
2. How can I show a MessageBox in a class Library (dll) instead of console.
Need some samples, please.

Thanks :)

To call MessageBox.Show function in a class library you must add a reference to System.Windows.Forms

It would be wise to provide a sample code of the non working Console.WriteLine, so we can look at it and point out the error.
 
M

Mr. X.

Well, that's what I have done.
Still on the class library - MessageBox.Show("x"); isn't compiled.
I got the message:
Error 1 The name 'MessageBox' does not exist in the current context

I use C# VS 2008.

Thanks :)

"bradbury9" wrote in message

El miércoles, 23 de mayo de 2012 15:41:48 UTC+2, Mr. X. escribió:
Hello,

In C# ...
1. I have tried to write to Console : "Hello world" by
Console.WriteLine("Hello world"), but I cannot see the console screen.
2. How can I show a MessageBox in a class Library (dll) instead of
console.
Need some samples, please.

Thanks :)

To call MessageBox.Show function in a class library you must add a reference
to System.Windows.Forms

It would be wise to provide a sample code of the non working
Console.WriteLine, so we can look at it and point out the error.
 
M

Mr. X.

First - it just for debug ...
(It's dll : Class library).
I need somehow to trace the dll (also by messages).

Thanks :)

"Mr. X." wrote in message
Well, that's what I have done.
Still on the class library - MessageBox.Show("x"); isn't compiled.
I got the message:
Error 1 The name 'MessageBox' does not exist in the current context

I use C# VS 2008.

Thanks :)

"bradbury9" wrote in message

El miércoles, 23 de mayo de 2012 15:41:48 UTC+2, Mr. X. escribió:
Hello,

In C# ...
1. I have tried to write to Console : "Hello world" by
Console.WriteLine("Hello world"), but I cannot see the console screen.
2. How can I show a MessageBox in a class Library (dll) instead of
console.
Need some samples, please.

Thanks :)

To call MessageBox.Show function in a class library you must add a reference
to System.Windows.Forms

It would be wise to provide a sample code of the non working
Console.WriteLine, so we can look at it and point out the error.
 
M

Mr. X.

The application is class library,
so I put on code :
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
static extern int MsgBox(int hWnd,
string msg,
string caption,
int type);

and use MsgBox fine.

Thanks, anyway :)


"Peter Duniho" wrote in message

Well, that's what I have done.
Still on the class library - MessageBox.Show("x"); isn't compiled.
I got the message:
Error 1 The name 'MessageBox' does not exist in the current context

To use any member of any type, you must:

-- reference the assembly that declares the type, and
-- use the correct name in your code when using the type

If a type exists within a namespace, as most do (including MessageBox), you
must either provide the fully-qualified name (i.e. the full name, including
the namespace) or you must add an appropriate "using" directive to your .cs
file for the namespace in which the type is found).

Given the error message, I suspect you have not added the necessary "using"
directive. You either need to do that, or use the fully-qualified name of
the type (which is "System.Windows.Forms.MessageBox").

Pete
 
M

Mr. X.

System.Windows.Form is not acceptable (it isn't compiled - The computer
doesn't know this - Framework 3.5).

"Peter Duniho" wrote in message

The application is class library,
so I put on code :
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
static extern int MsgBox(int hWnd,
string msg,
string caption,
int type);

and use MsgBox fine.

That's a stupid way to display a message box from managed code.
Thanks, anyway :)

You're welcome.
 
M

Mr. X.

For http://social.msdn.microsoft.com/Search/en-US?query=messagebox&ac=8
(In the same site, and many samples around the internet -
http://social.msdn.microsoft.com/Search/en-US?query=messagebox&ac=8
the namespace is System.Windows.Forms (the only "s" for different) - Not
working neighther).

"Peter Duniho" wrote in message

System.Windows.Form is not acceptable (it isn't compiled - The computer
doesn't know this - Framework 3.5).

Since "System.Windows.Form" is not what any of us wrote, I'm not all that
worried about it.

You should become familiar with http://msdn.microsoft.com/ and especially
http://msdn.microsoft.com/library

There is a wealth of useful information and documentation there, including
detailed reference of the C# language and the .NET Framework libraries.

Pete
 
B

bradbury9

El jueves, 24 de mayo de 2012 16:23:33 UTC+2, Mr. X. escribió:
The application is class library,
so I put on code :
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
static extern int MsgBox(int hWnd,
string msg,
string caption,
int type);

and use MsgBox fine.

Thanks, anyway :)

- Do no reinvent the wheel, use .NET API so you have less code to debug.

- You can call .NET API MessageBox.Show since easily http://msdn.microsoft.com/es-es/library/system.windows.forms.messagebox.show(v=vs.80).aspx

- If you port your code to other OS (other versions o windows, smart devices, linux) you won't need to change your code to make it work again.

- yeah, it is not compiled but... Aren't the pros better than the cons?
 
M

Mr. X.

Just needed to add reference to System.Windows.Forms.

Still, I don't know why the command console doesn't return an output to
basic console window (or how can I show the console window - The output type
is class library).

Thanks, anyway :)

"Peter Duniho" wrote in message

For http://social.msdn.microsoft.com/Search/en-US?query=messagebox&ac=8
(In the same site, and many samples around the internet -
http://social.msdn.microsoft.com/Search/en-US?query=messagebox&ac=8
the namespace is System.Windows.Forms (the only "s" for different) - Not
working neighther).

"Not working neighther" is not a useful problem description (never mind
good grammar).

If you want help, you need to get into the habit of asking good questions.
 

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