|
Well, I was originally thinking of trimming the strings to the same length, but that would screw things up because I could get something like 0.5 and then I don't want to trim 0.92323923423 to 0.9. I could go the other way and pad out the 0.5 to 0.500000000, but I don't want to display it like that .
My list control was doing sorting generically by property name. I.e. column1 sorts on "Name", column2 sorts on "Age", etc. So I just added a "custom sort callback" property to the column and
if it has one specified, it calls that instead of StrCmpLogicalW with raw object(s) instead of the ToString()'ed version and the implementer of the callback can decide how to compare them. In this case, I just typecast to doubles and use the <, == and > operators.
Still, the StrCmpLogicalW thing irks me because the whole point of that function is to take numbers into account .
|
|
|
|
|
StrCmpLogicalW() is what Windows Explorer uses to sort file names in the "logical" order, i.e. it gives
a1a, a2a, a3a, ..., a9a, a10a, a11a, ...
so it looks at a string as containing digits and non-digits; in scans left-to-rigth; for the non-digits it compares a character at a time, by char value; for digits, it calculates the integer value and compares that. It does not know about decimal points, thousand separators, minus signs, etc.
As a result 0.842264196854649 is the number zero, a period, and the number 842264196854649, and the latter one is larger than 91145355364217 by about a factor of 9.
You should not use StrCmpLogicalW() here; why don't you just use string.Compare() (OK for positive numbers only!)? and of course, the clean approach would be using numbers, not strings.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Yeah, I have filenames, so thats why my control defaults to using StrCmpLogicalW as the default sorter. As I mentioned in another post, I added support for a custom comparer for each column, so what I'm thinking is that I should default to string.compare() and the user (of the control) can override for the filename columns or other columns they want logical sorting on. That should improve sorting performance since I'm thinking string.compare() is faster then StrCmpLogicalW() .
But great explanation on why it works how it does. I gave up trying to figure that out and just implemented the custom callback so they can sort as doubles or whatever if they wish.
|
|
|
|
|
IMO it isn't hard at all to implement StrCmpLogicalW() or something similar that would understand signed numbers, thousands separators, decimal points, doubles, even engineering notation if that is what you want. Long ago I made an exact replica of StrCmpLogicalW() as I was creating an Explorer clone and wanted identical sort order; only later I figured the StrCmpLogicalW() function was available to all.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Are there asynchronous code designs for a server and a client using TcpListener and TcpClient including asynchronous data read/write?
Чесноков
|
|
|
|
|
If you don't mind using WCF, you can get the async for free (along with several other benefits).
/ravi
|
|
|
|
|
No, I need to use TcpListener and TcpClient in .NET assembly for windows forms.
I'm intrested in correct usage of begin accept, read, write for server and begin read, write for client.
Also correct server shutdown, socket exception handling etc...
Чесноков
|
|
|
|
|
There's always MSDN[^] of course
Bastard Programmer from Hell
|
|
|
|
|
Documentation encourages to use TcpListener and TcpCllient classes.
I've seen those samples with a server getting back data from a client, sending back response and closing it.
I'm intrested in a server handing many clients connected and client connected to many servers architecture.
There should be some ready described solutions to avoid common mistakes.
e.g. in BeginRead callback there is a missing zero byte call back which occurs if client connection is lost
Чесноков
|
|
|
|
|
Wow, this seems to be a good candidate for WCF! The WCF service doesn't need to be hosted in a server app - you can use it much like you'd use TcpListener and TcpClient .
/ravi
|
|
|
|
|
Well I'm developing according to domain-driven design DDD and was going to write a service for server and client.
What is the advanatage of WCF over ordinary .NET sockets apprach?
I need several services running on the same machine each with a different port.
Чесноков
|
|
|
|
|
WCF provides the plumbing for easily:
- building a configuration (port, transport, security) driven client/server system
- implementing both sync and async client APIs
- adding hooks (e.g. custom compression) before data is sent/received
- implementing logging and instrumenting traffic
- implementing handshaking (full-duplex) communication and transacted communication
- embedding the server in any type of host host (GUI app, console app, web app, Windows service)
If you haven't had the opportunity to use it, I recommend giving it a try. I think you'll be pleasantly surprised by its power and ease of use! Here are a couple of links that should get you up and running quickly:
/ravi
|
|
|
|
|
Thanks, but I'm not sure that is suitable for my design.
I'm coding video surveillance application, server runs video capture and sends captured frames to connected clients.
There can be any number of clients connected to a server and a client can be connected to any number of servers.
There are video capture service and video data transfer service (the server).
As the frame is captured video capture service invokes send method from the video data transfer service which sends the frame to all clients connected.
WCF as I understood provides service contract and public methods to call.
In that case I need to add WCF logic to video capture service and declare public method as e.g. GetRecentFrame(). And a client needs to call that method.
I do not want to combine video capture and video data transfer services.
As video capture service is running on despite the fact if someone is connected to transfer it a frame. And network connection may be slow, video capture service may get 10 frames in a time 1 frame is finished with the transfer to the client.
Чесноков
|
|
|
|
|
Ah. I now understand why you prefer to be lower in the network stack.
/ravi
|
|
|
|
|
Chesnokov Yuriy wrote: I've seen those samples with a server getting back data from a client, sending back response and closing it.
I'm intrested in a server handing many clients connected and client connected to many servers architecture.
There is no multiple/multiple architecture, it's always one server/many clients. The fact that your browser can open multiple pages is due to having multiple clients, that each request data from a different server.
Chesnokov Yuriy wrote: There should be some ready described solutions to avoid common mistakes.
The All-in-one samples refer to the same page[^].
Bastard Programmer from Hell
|
|
|
|
|
I don't know if it counts as a design pattern but my sockets library[^] may be of some use to you (either to use it or to look at the code to adapt for your own solution). I don't use asynchronous writing (writing is de facto asynchronous, as it writes to the local buffer immediately, so you only need to use the methods if you want feedback), but I do use asynchronous accept and read and handle the various ways in which it can go wrong unexpectedly.
|
|
|
|
|
Hi All,
I know it is late on a Friday, but I am going to self-destruct if I don't find out this problem.
(.net 4.0)
Does anybody know a diffrence between a console application and a winforms application that would cause a difference between a DLL working correctly on 64bit Windows machine.
on local 32bit machine - both console and winforms work fine
on server 64bit machine - console don't work (error below), winforms works fine
error:
“Unable to cast COM object of type 'XXX' to interface type 'XXX'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DE4DA901-EEF8-11D0-9E5F-008048AADD4E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).”
please somebody know the answer...
Thanks
I may or may not be responsible for my own actions
|
|
|
|
|
Build the project using X86 instead of target any and see if that helps
Project - Properties - Build - Platform Target
I have a few 32 bit only dll's that are a nightmare and that helps.
|
|
|
|
|
Thanks for the reply, I have tried that thou and it did help with an earlier issue. The DLL is 32bit only by the way.
It is also an ActiveX COM DLL if that makes any difference. Their support suggests I try a small console application with another ActiveX COM DLL, I don't suppose you know any I could use? I don't know much about this ActiveX stuff to be honest
I may or may not be responsible for my own actions
|
|
|
|
|
On x64 systems, you need to register 32-bit COM components with C:\WINDOWS\SysWow64\RegSvr32.exe (32-bit version). By default, your path will use the one in C:\WINDOWS\System32 (the 64-bit version). Registering a 32-bit COM component using the 64-bit regsvr32 has a bunch of side effects and doesn't fully work.
|
|
|
|
|
Thanks but I had tried this already. I have now solved the issue and will post separate message with solution
I may or may not be responsible for my own actions
|
|
|
|
|
So I Installed the application that this SDK was for and that fixed the issue. The SDK is meant to work without the original application but I guess they have some set up issue they need to work out.
I am not sure about any specific files that get added/registered during install, but the following programs do get installed with it. These could provide the files that I needed to get around the error.
- Microsoft C++ Redistributable 2005
- Adobe Flash Player ActiveX
I may or may not be responsible for my own actions
|
|
|
|
|
Hallo,
I am reading a book on C# and I came to the following example.
class Employee { }
class ContractEmployee : Employee { }
class CastExample1
{
public static void Main ()
{
Employee e = new ContractEmployee();
}
}
So my question is maybe simple: which properties and methods does the object e has? Those from the base class Employee or of the derived class ContractEmployee? Maybe it is the syntax that confuses me... how should I read this? Let's create an Object which belongs to the Employee class but gets all its properties from the ContractEmployee class? Or maybe it's the opposite that is true? I really don't get it and I would appreciate an explanation. Thanks in advance.
|
|
|
|
|
If you did it like this
class Employee
{
public void Talk()
{
MessageBox.Show("I am an Employee.");
}
}
class ContractEmployee: Employee
{
public void ContractTalk()
{
MessageBox.Show("I am a Contract Employee.");
}
}
and then tried to do this
static void CreateEmployee()
{
Employee e = new ContractEmployee();
e.Talk();
e.ContractTalk();
}
you would see that e only has access to e.Talk(). The compiler throws an error when you try and access e.ContractTalk() because e does not have access to ContractEmployee's methods. I think the example in the book is misleading because you aren't doing anything by decalring an Employee and instantiating a ContractEmployee. It would be different if Employee was an abstract class and it implemented an interface. Then derived classes would be forced to implement the methods defined in the interface, something like this,
interface IEmployee
{
void Talk();
}
abstract class Employee : IEmployee
{
public abstract void Talk();
}
class PermanentEmployee:Employee
{
public override void Talk()
{
MessageBox.Show("I am a Permanent Employee.");
}
}
class ContractEmployee: Employee
{
public override void Talk()
{
MessageBox.Show("I am a Contract Employee.");
}
}
then it would make sense to do something like this
static void CreateEmployee()
{
Employee e = new ContractEmployee();
e.Talk();
e = new PermanentEmployee();
e.Talk();
}
Hope this helps
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Since e is defined as an Employee then it only has access to the properties and methods of the base class. However, you should go back to the book to see what the author is trying to illustrate with this sample, as any comments made here will most likely be out of context.
The best things in life are not things.
|
|
|
|