|
For one or more strings I would:
- get an instance of Encoding for the 1252 code page;
- set its EncoderFallback to a new EncoderFallbackException;
- then use its GetBytes() to do the conversion, possibly resulting in an Exception being thrown.
For an individual character, I might consider:
- just once: building a 256-byte byte array holding all possible byte values;
- just once: convert that to a Unicode string using an Encoding for cp1252;
- then just test the character(s) using string.IndexOf.
|
|
|
|
|
Thanks for this hint.
Only one caveat: the EncoderFallback property is write protected, it must be set in the constructor:
Encoding encoding = Encoding.GetEncoding(1252, new EncoderExceptionFallback(), new DecoderExceptionFallback());
|
|
|
|
|
I would just encode (bytes) to 1252 and then decode that back to UTF (C#). If the output is the same as the input then it is ok.
|
|
|
|
|
Hi all,
I have a problem in creating a Excel RTD Server using C#.
The application is laid out as follows:
A window application which is running .Net Remoting server on a tcp channel (let's call it DataFeedServer).
A dll which can call DataFeedServer to get the data (let's call it DataFeedClient). The communication between those DataFeedServer and DataFeedClient is two-way (using callback functions and delegates).
Then I tried to call the DataFeedClient dll from a test windows application (let's call it TestWinApp).
Then the application flow is:
TestWinApp calls DataFeedClient, DataFeedClient calls DataFeedServer, DataFeedServer fires an event in DataFeedClient and finally DataFeedClient fires an event in TestWinApp. And it's working fine.
Then MS Excel comes in for real world scenario. I put a dll for RTD interface which will be called by MS Excel and which will call to DataFeedClient.
Then the scenario changed to MS Excel RTD calls DataFeedClient, and DataFeedClient calls DataFeedServer. Then DataFeedServer tried to fire an event of DataFeedClient. But fails. No error. Just silently stopped at that stage. So there's no calling from DataFeedClient back to MS Excel. The direction of the data flow is only half of the route always.
I'm not so sure I'm explaining clearly enough and thanks for taking your time this far.
Actually, the very essential information I need to know is if it's possible to use IRtdServer and Two-way .Net Remoting (with callback functions and delegates). Any information source is gratefully appreciated too.
Thanks in advance.
Best regards,
Zaw Min Tun
|
|
|
|
|
How to call java within c#?. It would be helpful if we know the steps to use java code in C#?
|
|
|
|
|
I've never tried it myself, but I have heard good things about it: IKVM.NET[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
If you are talking about directly using Java code from within a C# application, you might want to look at JNBridge.
http://www.jnbridge.com/[^]
I've never used it and I have no idea how much it costs, but it has a good reputation. It seems to do the job pretty well from what I can gather.
If you are talking about reusing functionality but don't need direct integration then it might be easier (and cheaper) to write a wrapper that lets you talk between the two components, e.g. a web service or a call through a TCP socket or something like that. It depends what your requirements are.
|
|
|
|
|
The requirement is here. There are two methods available in java.
Zip(string sourcefolder, string targetloction, string zipfilename);
UnZip(string zipfilename, string targetfolder);
We need call these methods from C#. Is there any ways to achieve whitout using JNBridge
/3rd party?
|
|
|
|
|
You have a number of options:
- use third-party tool like JNBridge or IKVM or similar
- use a web service or other cross-process communication
- write your own wrapper DLL using JNI
I have no idea what your Zip/Unzip methods do, but one option (which I am sure you have considered) is to bite the bullet and rewrite them in C#. If the Java functionality isn't too complicated, this would be my preferred option if it was my project. Don't forget, you will need a JVM up and running in order to call the Java methods. They will not run natively in .NET.
|
|
|
|
|
Thanks for your suggessions. I will try to implement wrapper DLL using JNI.
|
|
|
|
|
Why don't you try some zip libraries for .NET? E.g. ICSharpCode.SharpZipLib.dll.
I'd rather look for .NET alternatives than try to deal with the problems of running java code from C#.
Another alternative would be to write a java "executable" which you can call with System.Diagnostics.Process.Start()
|
|
|
|
|
Trying to avoid 3rd party libs. If no solution available then we may need to use 3rd party libs.
Do you know any sample code that explains about writting wrapper DLL using JNI to call Java?
|
|
|
|
|
Why are you doing this? There is no point in writing a C# program that requires a Java library since you have to cross too many boundaries (managed -> unmanaged -> JVM) to make it work. Write your library in C# and do it the easy way.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
To be fair to him, he is trying to follow the advice given here[^].
|
|
|
|
|
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Three approaches discussed here[^] - all worth considering.
|
|
|
|
|
In java and only in java.
1. Wrap the java code in a java exe framework (so it can be run at the command line with 'java')
2. Add a communication layer (sockets, files or stdio) written in java.
3. Test the above.
In C# and only C#.
1. Use Process to run the above
2. Write code to talk to the communication layer of the above.
Benefits.
A. Java code is all java.
B. C# code is all C#
C. No reliance on third parties.
D. Unit testing can be done without relying on the other language.
|
|
|
|
|
Hello all,
How can i perform multiple mouse clicks at the same time on desktop screen using C# code?????
e.g. when i click on the mouse button I will perform multiple clicks on differents pre-defined x,y positions on the screen
modified 10-Jan-12 3:09am.
|
|
|
|
|
You are going to have to use a User32 API function mouse_event . First off, import System.Runtime.InteropServices into your class, then declare the function import:-
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
You then need to declare constants for the relevant mouse actions :-
private const int MOUSE_LEFTDOWN = 0x02;
private const int MOUSE_LEFTUP = 0x04;
private const int MOUSE_RIGHTDOWN = 0x08;
private const int MOUSE_RIGHTUP = 0x10;
Then you can create a function that clicks the mouse at a specific location on the screen :-
public void ClickMouse(int x, int y)
{
Cursor.Position = new Point(x, y);
mouse_event(MOUSE_LEFTDOWN | MOUSE_LEFTUP, x, y, 0, 0);
}
You should be aware that there could be snags with this, i.e. the speed with which you click could mean mouse clicks getting lost if they are too fast, etc. Also, you will need to be aware of the users screen resolution, else if you hard code specific points to click, they will be off screen if the users resolution is less than yours etc.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
thank you for you perfect answer but really i need to know how exactly can i perform multiple clicks on the same time
regards,
Ahmad
|
|
|
|
|
You have an excellent answer from Wayne (got my +5) here to the question of how to "trigger" a bunch of clicks, but the fact remains that MouseClicks go in an event queue which is sequential.
The mind boggles that the new parallel extensions to .NET might allow "virtual" simultaneous clicks: but I do think we can safely leave out the idea you are using multiple-mice
So I am curious to ask you what your purpose is here ? What does this secondary "cascade" of clicks actually do ?
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
thank you Bill for your interaction, mmmm I know that my question is very strange but i need this to create bugs in games
|
|
|
|
|
Hello all,
I need to run a multi-process app, in which each process keeps 20-40 threads that keep an object state and performs calculations based on the state of the object, ON DEMAND (from the main thread).
Each thread performs a discrete calculation and returns an answer (to the main thread), and then WAITS for the next request
What's the best practice for this kind of app?
Should I keep all objects in the main thread and create new short-life thread that perform only the one action,
OR
Keep the threads alive, and have them use WaitHandle to wait for the next request,
Others suggestions are most welcome?
Tzumer
|
|
|
|
|
Edo Tzumer wrote: Others suggestions are most welcome?
Upgrade the threads to processes; you said multi-process, meaning that you could simplify the architecture to something that runs an external process on demand and catches it output. The external process would then become a small console-app, containing the threading-code. That would mean more isolation and simpler maintenance.
Edo Tzumer wrote: Should I keep all objects in the main thread and create new short-life thread that perform only the one action,
OR
Keep the threads alive, and have them use WaitHandle to wait for the next request,
You'd only keep the threads alive if it were too expensive to recreate them. Short-life threads is what the threadpool is for, albeit you might want to check out the Smart Thread Pool[^]-article.
Bastard Programmer from Hell
|
|
|
|
|
Tnx,
Can't upgrade them to processes though,
the whole constelation is already one process with many threads,
and there are many processes like this one on the same server, doing the same work in parallel, (and many servers doing so in parallel if we already mention the system, but that does not change the question),
apart from that a process sounds like a major overhead and there's the problem of sharing information, since I need to use objects on the main thread, in each of the calculations.
Actually the tip on the thread pool sounds great, it's the approach of having the objects live in the main thread, but perform the alleged calculation in a thread, but INSTEAD of creating and killing them, to use a thread pool,
Gee, that sounds like a great idea!
thanks a bunch mate, I will dig into the concept...
Tzumer
|
|
|
|