|
That sounds like just what I was looking for. I'll check that out, thanks a lot.
|
|
|
|
|
Hi All
I writing some application in C#.
In my application i have a lot of Const variable , and for this reason i add class with the name "Constant" to my application.
In this class i add this lines
public class Constant
{
public const long A = 0x1;
public const long B = 0x2;
.
.
.
.
}
Now - i want to add to each class in my application this class- i mean that i want for each class to use this Constant variables.
My question : is there some way to do it with out create in each class that use Constant class without use the Constant class constructor ?
I think i can use "nameSpace" but i dont know how to do it without use the Constant class constructor.
Some one can help me?
[in C++ i add the header file to some file (in MFC) that each *.cpp file have it and in this way each *.cpp file know about each #define that i add to the file.]
|
|
|
|
|
Constant values can be used without an instance to the class :
<br />
namespace ConstantsNamespace {<br />
public class Constant<br />
{<br />
public const long A = 0x1; <br />
public const long B = 0x2; <br />
.<br />
.<br />
}<br />
}<br />
<br />
namespace myNamespace {<br />
public class TestClass {<br />
public TestClass() {<br />
Console.WriteLine(ConstantsNamespace.Constant.A);<br />
}<br />
}<br />
}<br />
I hope you understand...because is a rough world out there...
|
|
|
|
|
For that to work, the variables would have to be public static const long A = 0x1; ...etc.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..." - Jörgen Sigvardsson
|
|
|
|
|
A const cannot be marked as static .
Try it for yourself if you do not belive me.
I hope you understand...because is a rough world out there...
|
|
|
|
|
That's right. My bad. Sorry about that.
What he'll want to use then is something like:
public static readonly myVariable = 0x1;
Otherwise he'll have to new up an instance of the Constants class every time he wants to use one of them.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..." - Jörgen Sigvardsson
|
|
|
|
|
This is not correct. Fields declared with the const keyword are implicitely static. Thus you can use them without having an instance.
|
|
|
|
|
Hi,
I got a problem i used ShockWave Flash Object that is available in visual studio 2005, where i make a project by C# and load .swf files in that control and it provides my by all actions that are taken on a flash movie,i.e. when action like click occurs on a thing in the movie i will e notified in c#.
All that was great but when i move the project to another machine i get a surprising thing, the movie is displayed but actions not give me any notification.
note: **the second machine that i tried to work my project on it was have a flash media player setuped on it. And when i downloaded the macromedia flash professional program and installed it the program worked again but i cant download on every client that program so i need a solution.
please any boody help me, i have an un-believable bug.
Regards,
22DoorsDown <me4webby@yahoo.com>
|
|
|
|
|
When I`m running an application, I would like to run another application and receive handler to that process (to send him messages). How to do that in C#?
thank you for any help
|
|
|
|
|
I've got the impression this questing is asked a hundred times a week
Take a look at Process.Start method from the System.Diagnostics namespace.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
System.Diagnostics.Process pr = new System.Diagnostics.Process();
its ok, but how to assign a specific process into that object? Suppose I have a program: a.exe and I would like to launch it
|
|
|
|
|
clickedy
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Indeed, thank you very much
The second question is, how to send a message to that process, having its handler? I mean the system (Windows) message (I need this to cooperate 2 applications, one written in C#, second in Delphi6)
|
|
|
|
|
In a previous project, I had to "hook" up a couple of applications together just like you.
1) After you start the new Process , get the Windows handle to the main window through the Process.MainWindowHandle property.
2) Import the SendMessage native call:
[DllImport("user32.dll")]
static extern IntPtr SendMessage( IntPtr hWnd,
uint Msg,
IntPtr wParam,
IntPtr lParam );
3) Use the Process.MainWindowHandle from step 1 to send messages to the application useing the SendMessage method imported in step 2.
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
And how to receive this msg in second process?
|
|
|
|
|
I do not know how to program in Delphi 6. However, I can help you with the C# implementation. Follow these steps:
- Create a class derived from the
NativeWindow class to handle the messages sent from your Delphi 6 application. - Instantiate the main form.
- When the window has been created for the main form, instantiate an object of your class derived from
NativeWindow and assign the handle of your main form to it using the AssignHandle method. - Process the messages from the Delphi 6 application
- Win the affection of developers and managers everywhere.
I hope that helps.
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I have a problem with step 2nd:
C:\Documents and Settings\ppp\Pulpit\Sudoku\WindowsApplication1\WindowsApplication1\Form1.cs(108): The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
this is what I get about the line
"[DllImport("user32.dll")]"
I tried to add it as a reference (I found appriopriate dll in windows/system32 folder) but it didn`t work as well.
What do you think may be problem?
thank you for help
|
|
|
|
|
Hoping someone can help on this as Google and Google Groups haven't done anything for me! I have 2 ServicedComponents. 1 is a custom collection implementing IEnumerable, the other is a value object. I am replacing existing COM business components, so I don't have the luxury of changing this design. Anyway, I can add the value object to the collection just fine from .NET and COM. I can use a For loop and access the collection via its indexor and it works just fine. But I cannot do a For Each from a COM client; I get the error "Object required". It works great from .NET, and it works from COM if I don't make the value object a serviced component. Here is example code for the collection:
[Guid("1FC8C56E-FE10-4831-B900-892AD2041C64")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ISimpleCollection : IEnumerable, IList
{
void Test();
new int Add(object v);
new IEnumerator GetEnumerator();
}
///
/// Summary description for SimpleCollection.
///
[Guid("CA97A716-4508-4602-A7F4-45F90DBFD93F")]
[ClassInterface(ClassInterfaceType.None)]
public class SimpleCollection : ServicedComponent, ISimpleCollection
{
private ArrayList m_ArrayList = new ArrayList();
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
object[] myObjects = m_ArrayList.ToArray();
return myObjects.GetEnumerator();
}
#endregion
public void Test()
{
}
#region IList Members
public bool IsReadOnly
{
get
{
return m_ArrayList.IsReadOnly;
}
}
public object this[int index]
{
get
{
return m_ArrayList[index];
}
set
{
m_ArrayList[index] = value;
}
}
public void RemoveAt(int index)
{
m_ArrayList.RemoveAt(index);
}
public void Insert(int index, object value)
{
m_ArrayList.Insert(index, value);
}
public void Remove(object value)
{
m_ArrayList.Remove(value);
}
public bool Contains(object value)
{
return m_ArrayList.Contains(value);
}
public void Clear()
{
m_ArrayList.Clear();
}
public int IndexOf(object value)
{
return m_ArrayList.IndexOf(value);
}
public int Add(object value)
{
return m_ArrayList.Add(value);
}
public bool IsFixedSize
{
get
{
return m_ArrayList.IsFixedSize;
}
}
#endregion
#region ICollection Members
public bool IsSynchronized
{
get
{
return m_ArrayList.IsSynchronized;
}
}
public int Count
{
get
{
return m_ArrayList.Count;
}
}
public void CopyTo(Array array, int index)
{
m_ArrayList.CopyTo(array, index);
}
public object SyncRoot
{
get
{
return m_ArrayList.SyncRoot;
}
}
#endregion
}
and the value object:
[Guid("11CAED6B-0E04-4a93-B32B-7100A7B3AD05")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ISimpleObject
{
string SomeValue
{
get;
set;
}
int SomeInt
{
get;
set;
}
}
///
/// Summary description for SimpleObject.
///
[Guid("857E9B62-BCB4-4cb7-B3D3-DD19B2ED074A")]
[ClassInterface(ClassInterfaceType.None)]
public class SimpleObject : ServicedComponent, ISimpleObject
{
private string m_SomeValue = "";
private int m_SomeInt = 0;
#region ISimpleObject Members
public string SomeValue
{
get
{
return m_SomeValue;
}
set
{
m_SomeValue = value;
}
}
public int SomeInt
{
get
{
return m_SomeInt;
}
set
{
m_SomeInt = value;
}
}
#endregion
}
Any help would be greatly appreciated!
|
|
|
|
|
hi there,
I'm new to C# , I have a question abourt performence of c# application.
Could you show me some ideal to improve performence ?
Thank you,
Sincerely,
|
|
|
|
|
Think out the fastest algorithm. Then implement it the fastest way.
C# is very slow, and the compiler can optimize better than you so you can't do anything.
Learn asm and you'll get the best performance, both of your mind and of your computer.
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
C# is very slow
I doubt that.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Try to make a loop that prints all the decimals in pi, or something else.
Then make the same in qbasic (an interpreter!) and you'll see that even a twenty year old interpreter is faster than .Net.
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
I didn't say .NET is on par or even faster than other languages, but stating that C# is "very slow" is absolutely not true. For example MDX applications are about 6 to 10 percent slower than their C++ counterparts, sometimes even less. That's actually pretty good considering all the .NET "overhead".
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Have you ever tried what I descibed?
I still think .net is the absolutly slowest platform I've ever programmed on.
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
Could you post your code (C# and QBASIC)?
Because you must have done something extremly wrong in the C# version to get such a low performance.
|
|
|
|