|
I didnt know I could use c++.dll in C#, im writing it in C~ two reason one my C++ isnt good enough, and the program im writing this plug in for is writen in C#.
Thanks very much will have a looked the links.
|
|
|
|
|
there aint much too c++.
the synthax is pretty simular, but you have to take care of cleaning recources used yourself.
in c# you have the garbage handler, in c++ you don't.
in c++ you would have to make a dispose methode pretty much everywhere and it looks very very simular too c#
that's what makes c# the competitor of java.
cheap develpment software.
cheap ... because it needs less time and less acuracy to create something.
you don't have to take care of freeing up recources that aren't used anymore, so you never really know if you software is actually 100%, because you don't need to think about it.
if it wasn't for the 3rd party dll i use to connect to a virtual world.
i wouldn't be using c# at all.
translating this 3rd party dll into c++, would take me a year or so.
but the downfall of DOTNET is ... you can easy reverse engineer your aplication and resell or hack it.
with a simple click in a tool from the internet, you pretty much get the entire code.
if you read about dotnet, you would have read the each executable actually transports the entire source and recompiles on the user machie.
this is done by the JIT compiler.
dotnet wil never be the tool by excellence for software venders.
dotnet is used by people that didn't like the looks or feel of java, but also aren't competent or too lazy for c++.
i don't live from coding, but this is what i learned in the last years.
if my current project is done, i'm going Nokia Qt.
power @ finger tips
Bad = knowing 2 much
|
|
|
|
|
Natural_Demon wrote: dotnet is used by people that didn't like the looks or feel of java, but also aren't competent or too lazy for c++.
I disagree!
I'm not lazy and consider myself to be competent in many languages, but I use C# almost exclusively.
The vast majority of the software I write is for use with bespoke in-house systems where security of source code is simply not an issue. I use C# because it enables me to quickly develop powerful applications and utilities as required in far less time than would be possible using C++.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
bespoke in-house systems = cheap.
'quickly' develop powerful application = cheap.
you boss or what ever pays less, becaue it takes less, right?
so you do agree with me, be it in other words.
regarding 'lazy' didn't count for all readers.
Bad = knowing 2 much
|
|
|
|
|
bespoke in-house systems != cheap; far from it. The cost of having a team of full time staff developing our systems is much greater than buying off the shelf stuff, and greater than having stuff written for us. It's worth while because:
We can change requirements and make alterations when needed.
The costs are constant - even if high.
We have full control over every single line of code.
Natural_Demon wrote: 'quickly' develop powerful application = cheap.
cheap == cost effective. Also, we add/create apps/utilities because we need them - that means we need them ASAP, not after a delay caused by a choice of language.
Don't get me wrong, C/C++ has it's place but so does C#, and it's positives should never be viewed as derogatory to the language or it's users.
If VB or Mickey Mouse for Windows did the job better for us then that's what we'd use. C# strikes the right balance for us in these situations, in others we do use other languages.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
maybe it's a simple problem for most of you, but I can't find an easy way to quite simple problem, let me describe:
Let's have this code:
<code>public ClassToChange()
{
...
internal List<AnyDataClass> LockAndGetData()
{
Monitor.Enter(cs);
return data;
}
internal Unlock()
{
Monitor.Exit(cs);
}
private object cs = new object();
private List<AnyDataClass> data = new List<AnyDataClass>();
}
public class Editor
{
public Editor(ClassToChange editedObject)
{
this.editedObject = editedObject;
}
public void MyFunctionToChangeData()
{
List<AnyDataClass> data = editedObject.LockAndGetData();
...
editedObject.Unlock();
}
private ClassToChange editedObject;
}
class Program
{
static void Main()
{
Editor ed = new Editor(new ClassToChange());
ed.MyFunctionToChangeData();
}
}</code>
So my aim is to let Editor change the data of ClassToChange in a thread-safe way. But as you can see to call all the List<anydataclass> data = editedObject.LockAndGetData(), then not to forget the editedObject.Unlock() is very boring to write (and not so safe). Do you have any easy solution for this?
Only solution I have, there might be the CS as attribute of ClassToChange and use lock {} in Editor, but I would need an attribute to every data object of ClassToChange, who would check if the cs is locked to make it safe. So that's also not a good way.
Any ideas?
Michal
modified on Tuesday, April 27, 2010 5:16 AM
|
|
|
|
|
You could potentially use Action<T> delegates to do this. Something like this:
public class ClassToChange
{
private object cs = new object();
private List<String> data = new List<String>();
public void LockAndMakeChange(Action<List<String>> changeAction)
{
lock (cs)
{
changeAction(data);
}
}
}
public class Editor
{
private ClassToChange editedObject;
public Editor(ClassToChange editedObject)
{
this.editedObject = editedObject;
}
public void MyFunctionToChangeData()
{
editedObject.LockAndMakeChange((data) =>
{
data.Add("new string");
});
}
}
This would achieve what you are trying to do. It means your editor only has to call LockAndMakeChange and doesn't have to worry about unlocking afterwards because the class handles it after the action has completed, and your lock object remains private (which is good).
However, you need to be careful with this. By allowing external code to run inside an internally private lock you are introducing a great risk of deadlocking. It is having a similar effect to making your locks public (which is bad). If you aren't very careful other code may be able to take advantage of your exposed locking methods to crash or hang your app.
Instead, I would think about having the modification done entirely within the class so no external code runs within the lock. You could have methods like this that just took in the data and did the modification internally:
public void AddNewString(String newString)
{
lock (cs)
{
data.Add(newString);
}
}
public void AddNewString(params String[] newStrings)
{
lock (cs)
{
data.AddRange(newStrings);
}
}
public void AddNewString(IEnumerable<String> newStrings)
{
lock (cs)
{
data.AddRange(newStrings);
}
} Then you would call it like this:
public void MyFunctionToChangeData()
{
editedObject.AddNewString("new");
editedObject.AddNewString("new1", "new2", "new3");
List<String> newStrings = new List<string>();
newStrings.Add("new4");
newStrings.Add("new5");
newStrings.Add("new6");
editedObject.AddNewString(newStrings);
}
This keeps your encapsulation higher and reduces the risk of deadlocking.
Simon
|
|
|
|
|
Thank you Simon, that's definitely interesting solution. But also too much of writing.
I know I should use locks and change data inside the class. And yes, it's possible by simple classes. But in my experience, more complicated classes will get huge like this. E.g. imagine a class, which contains Bezier curve (or e.g . only simple multi-segment line) and you would have to make all the modifications within this class - like rotation, movement, size change ... so I believe sometimes it's better to have different class for every function of some entity. And this is the only problem I have making it good...
I also think this is quite close to MVC pattern. How to implement it in a thread safe way in C# - hm, I don't know...
Not to mention e.g. whole program. To make some central class, which receives all commands from GUI and executes them (meaning just telling some backend what to do) - huge and awful (I ended up with 3500 lines of code for one class in one project ) - I think it's better to let the commands contain function code, but of course the commands need access to data.
Michal
|
|
|
|
|
Hi,
I have following string. And I have to extract "931.3392ms" from the string. This line of string is not delimited by any character. How do I extract it?
8 (26/04/2010 05:58.03) Execute(WQADataRequest, WQA_LOAD_TYPE.Deep) 931.3392ms (1.7/11.4 KB)
|
|
|
|
|
Are they delimited by spaces? Are there always the same number of elements in your string?
If so, you could split[^] it on the space.
I are Troll
|
|
|
|
|
This line of string is not delimited by spaces.Yes,this particular line always contains same number of elements. Is there any efficient method other than split?
|
|
|
|
|
SRKSHOME wrote: This line of string is not delimited by spaces.
You already mentioned that, just checking since there were spaces in the example-string.
SRKSHOME wrote: Yes,this particular line always contains same number of elements.
Split on some other character? Like the "("?
SRKSHOME wrote: Yes,this particular line always contains same number of elements.
But the elements do not always have the same length?
SRKSHOME wrote: Is there any efficient method other than split?
Yup, using regular expressions[^].
I are Troll
|
|
|
|
|
if the string is always fix size you can simply try the Substring method of the String class.
|
|
|
|
|
Try This
string str = "8 (26/04/2010 05:58.03) Execute(WQADataRequest, WQA_LOAD_TYPE.Deep) 931.3392ms (1.7/11.4 KB)";
MessageBox.Show(
(((str.Substring(str.IndexOf(")") + 1)).
Substring((str.Substring(str.IndexOf(")") + 1)).IndexOf(")") + 1)).
Substring(0, ((str.Substring(str.IndexOf(")") + 1)).
Substring((str.Substring(str.IndexOf(")") + 1)).IndexOf(")") + 1)).IndexOf("(")))
);
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
Thanks...This works efficiently.
|
|
|
|
|
Gr8... very smart.
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
|
I can't disagree more, that is horrible code. It is unreadable, it has 7 calls to IndexOf where you only need 3, and 7 to SubString where you also need just 3.
string a=str.Substring(str.IndexOf(")") + 1);
string b=a.Substring(a.IndexOf(")") + 1);
string c=b.Substring(0, b.IndexOf("("));
The Regex alternatives are pretty simple too, here is one; the result excludes the surrounding spaces:
string d=Regex.Match(str, @"\) ([0-9\.]*ms) \(").Groups[1].Value;
|
|
|
|
|
Use a Regular Expression, check out <a href="http://www.ultrapico.com/Expresso.htm">Expresso</a>[<a href="http://www.ultrapico.com/Expresso.htm" target="_blank" title="New Window">^</a>] or my own <a href="http://www.codeproject.com/KB/string/RegexTester_.aspx">RegexTester</a>[<a href="http://www.codeproject.com/KB/string/RegexTester_.aspx" target="_blank" title="New Window">^</a>].
|
|
|
|
|
You may want to consider using my StringParser [^] class.
string mSec = string.Empty;
StringParser sp = new StringParser (s);
if (sp.skipToEndOf (") ") && sp.skipToEndOf (") ")) {
sp.extractTo ("(", out mSec);
}
/ravi
|
|
|
|
|
Hi
My application recieves a stream of images from an IP camera. The images are stored as byte arrays. Does anyone know how to get the BITMAPINFOHEADER from the images?
Thanx
|
|
|
|
|
|
Thanx for the reply
Im using MJPG, I dont think that the images are recieved in BMP format. Isnt there some method I can use to extract the BITMAPINFOHEADER?
Im having trouble writing the images to a avi file because of the format the images are in. Im having to change the image format before writing to video file which is to slow.
Thanx
|
|
|
|
|
Dear Sir,
can you tell me when do i use struct and when i use class
|
|
|
|
|
Use a struct if you have no need for methods or to use inheritance and you only need a structure to store data (remember that a struct is passed by value and an object is passed by reference in C#).
|
|
|
|