|
Hi , guys!
I want to write a c# program to send windows message to other process.
For example,send a mouse click to IE.
Is this possible ? How?
Thanks!!!
|
|
|
|
|
Hi,
you will need P/Invoke to call some good old Win32 functions such as
SendMessage or PostMessage.
Lookt them up on CodeProject, Google or MSDN.
Also have a look at www.pinvoke.net
If pointers are required, they must be valid in the other process;
in that case you will also need VirtualAllocEx, VirtualFreeEx, WriteProcessMemory,
ReadProcessMemory.
|
|
|
|
|
I am getting System.OutOfMemoryExeception when executing this code:
...
StringBuilder afterSequence = new StringBuilder();
StringBuilder sequence = new StringBuilder();
StreamReader reader = new StreamReader(filePath);
string line;
bool sequenceReady = false;
while((line = reader.ReadLine()) != null && !line.StartsWith("CO"))
{
if(line.StartsWith("BQ"))
sequenceReady = true;
if(!sequenceReady)
sequence.Append(line + "\n");
else
afterSequence.Append(line + "\n");
}
...
I am reading 150MB file
Any ideas? And how can I read the file, because I need to send the whole file?
|
|
|
|
|
Hello,
Is the Exception accuring on the first time you are reading the file, or are you entering this code more often?
Just for info:
You should use the "new StreamReader" in a using block.
using(StreamReader reader = new StreamReader(filePath))
{
...
...
}//This makes sure that the Close() and/or the Dispose() method is called of the instance. (Can also have the effect of your Exception)
Using a StringBuilder is correct, so why doing this:
sequence.Append(line + "\n");
Instead of:
sequence.Append(line);
sequence.Append("\n"); //By the way, look at "Enviroment.NewLine"
Hope it helps!
All the best,
Martin
|
|
|
|
|
Hi,
seems like you are splitting a file into two parts, based on a line starting
with BQ. Now why would you use StringBuilder objects to do that ?
A StringBuilder is very efficient at collecting and possibly modifying text
content, particularly if it has sufficient capacity (otherwise internally a
new array has to be created and all data copied, everytime the capacity is
insufficient).
Depending on what you want to do with the two parts afterwards, I would
choose one of the following:
- create two files on disk; this avoids needing to have all data in memory at once;
- create two ArrayLists or List<string> in memory; this avoids the concatenation
of all text lines.
Even if you need each part as a StringBuilder, an ArrayList/List approach
allows you to determine the amount of data and create the StringBuilder object
with the right capacity, hence copying the data only once.
|
|
|
|
|
I have develop a Windows library ,i want to know how to make it into dll and how can i use this dll in other application in >net environment.
Plzz reply soon
|
|
|
|
|
See Here[^]
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Your project type is Class library, right? When you compile it, you should be getting a .DLL file. Add it as a reference in your new project and you can use the types in your DLL.
Please read Chris Maunder's How to get an answer to your question above.
Cheers,
Vıkram.
Déjà moo - The feeling that you've seen this bull before.
Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
Hi
I have a XML file as like below with large bumber nodes, what is the best way to parse it in terms of time...
<SCRIPT>
<ROW name='I' D='110' L='3'/>
<ROW name='D' D='111001' L='6'/>
<ROW name='I' D='11' L='2'/>
<ROW name='D' D='1' L='1'/>
etc.............
..............
...............
</SCRIPT>
|
|
|
|
|
sivaprakashshanmugam wrote: terms of time...
Developer's time, or running time?
Fro the first, System.Xml.XmlDocument. For the latter, System.Xml.XmlReader should suffice. Google or MSDN have plenty of examples how to use those.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Hi
VS2005 pro, dotnet 2.0
I want to have the complete field highlighted when the fielld gets focus.In this case the field is a masked edit box.
I call selectall() and have tried the other deriviations when the controls enter event is fired but the text is not selected. The same mechanism works well with standard text boxes.
Am I missing something or is this the default behaviour for a masked edit box.
tcss
-- modified at 6:05 Thursday 10th May, 2007
|
|
|
|
|
To clarrify a little bit more of what I have found.
If I remove the mask from the field then it allows all text to be selected
using select all. I may need to call selectAll in a an event other the onClick or on enter. Any ideas here. This is a customer request so I can not just let it slide but it currently appears impossible. The mask is ##0 to force numeric input and have a value of at least zero.
Anyone else been bitten by this.
|
|
|
|
|
hi i am currently using c#.net to do remoting
i am basically trying to make a project whereby when the client changes the values of the remotable object a function in the main class would execute.
my remotable class is in a class library
i am currently trying to make one of the remotable class object call one of the main class's function
so far all my attempts fail:
i tryed using delegate <==cant as the classes not same file the remotable class dont regconize some of the classes
event handler <== cant as some error keep coming up asking me to serialize the class and when i serialise the class another error pop's up saying that the security is not there to deserialise.
PLEASE HELP ME I AM DESPO
codes i have so far:<br />
static void Main(string[] args)<br />
{<br />
HttpChannel channel = new HttpChannel(8080);<br />
ChannelServices.RegisterChannel(channel, false);<br />
<br />
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(MyRemoteType),<br />
"MyRemoteObject",<br />
WellKnownObjectMode.Singleton);<br />
<br />
MyRemoteType MyRemoteClass = (MyRemoteType)Activator.GetObject(<br />
typeof(MyRemoteType),<br />
"http://localhost:8080/MyRemoteObject");<br />
MyRemoteClass.setsvalue("hihi");<br />
Console.WriteLine(MyRemoteClass.returnstring());<br />
<br />
<br />
<br />
Console.WriteLine("Press enter to stop this process.");<br />
Console.ReadLine();
|
|
|
|
|
my project have some function,but after one function,i must close the program and debug it again then can run the other function.my teacher ask me to add a button, then user finished one function,click this button,the program like refresh then can use the other one.
my question is how to restart the program?hope u can understand what i mean.
thank you.
|
|
|
|
|
Hello,
I would assume that you have to build a second update project wich is started (Process.Start) by your main programm (button click).
After you started the update programm you can Exit the main programm.
Your update program does whatever it should do and restarts the main program again.
Be aware that you have to set the "WorkingDirectory" of your Updateprogramm process explicite, because default would be the mainprogram directory, and then you have problems if you have to delet, move, ... files from the main program.
All the best,
Martin
|
|
|
|
|
Martin ,thanks a lot for u r reply...but i still a little confused about this function...sorry
|
|
|
|
|
So tell us what confusses you!
|
|
|
|
|
System.Windows.Forms.Application.Restart();
|
|
|
|
|
Hey guys thanks for helping, I have the following:
* a main form, mainForm (the main application)
* i have a class, myClass
* i have an auxiliary form, auxForm which displays info about a certain process (method in myClass), say downloadData().
When I make a call to downloadData() the first time, auxForm is created and showed as follows:
<br />
class myClass{<br />
AuxForm myAuxForm;<br />
<br />
downloadData()<br />
{<br />
myAuxForm = new AuxForm (this);
myAuxForm .Show();<br />
doDataLoad();<br />
}<br />
<br />
.<br />
.<br />
.<br />
}<br />
This works fine.
However, once the form has been closed, and I make another call to the above method,
I get an error:
<br />
System.ObjectDisposedException was unhandled<br />
Message="Cannot access a disposed object.\r\nObject name: 'TextBox'."<br />
Source="System.Windows.Forms"<br />
ObjectName="TextBox"<br />
Given that its a textbox on the (closed) form causing the problem, it seems that the object myAuxForm, even though closed/disposed, is not reset to null.
(I have tried doing a if(myAuxForm == null) test before instantiating it again, but with no success).
If anyone has advice on how to get around this problem, it would be much appreciated!
For reference, here is the myAuxForm's code (actually called PriceUpdateForm):
<br />
partial class PriceUpdateForm : Form<br />
{<br />
delegate void OutputDisplayCallback(string s, TextBox txtbxOutputTmp);<br />
StockListManager m_slm;<br />
<br />
public PriceUpdateForm(StockListManager slm)<br />
{<br />
InitializeComponent();<br />
m_slm = slm;<br />
m_slm.m_DisplayOutputEvt += new StockListManager.m_DisplayOutEH(DisplayOutputFromThread);
}<br />
<br />
void DisplayOutputFromThread(string s)<br />
{<br />
DisplayOutput(s, txtbxOutput);<br />
}<br />
<br />
<br />
private void DisplayOutput(string s, TextBox txtbxOutputTmp)<br />
{<br />
<br />
if (txtbxOutputTmp.InvokeRequired)
{<br />
OutputDisplayCallback d = new OutputDisplayCallback(DisplayOutput);<br />
this.Invoke(d, new object[] { s, txtbxOutputTmp });<br />
}<br />
else<br />
{<br />
txtbxOutputTmp.AppendText(s + "\n");<br />
if ((s == "Price data update complete.") && (chbxCloseWhenDone.Checked))<br />
this.Hide();<br />
} <br />
}<br />
<br />
<br />
}<br />
In effect, it comes down to "How to make a call to the same form twice?" I think
Many thanks,
Gerry
C# newbie
|
|
|
|
|
Hi,
Actually Problem is occuring due to your custom event.The work around of this problem is
void DisplayOutputFromThread(string s)<br />
{<br />
if(!this.IsDisposed)<br />
{<br />
DisplayOutput(s, txtbxOutput);<br />
}<br />
}
|
|
|
|
|
Wow thanks sam!
Not sure why the object is still in existence (as its been closed) tho?
Thanks again,
Gerry
|
|
|
|
|
Hello,
The question is if you don't whant to hold the Form in memory and make and only hide it.
If jes, you should add a static "GetInstance" method in your auxForm, which creates an instance at first call and returns it, after that instance != null you return that instanc without creating it new.
The problem of your not accurate disposed class, should not be resolved with an workaround, as this will cause memory leeks and very soon Out of memory exceptions if you go on like this!
As Form is IDisposable and Dipsoe will be called at Close, you should override the Dispose method and unregister the eventhandler you added (-=.....).
Hope it helps!
All the best,
Martin
|
|
|
|
|
Thanks Martin thats some great advice!
|
|
|
|
|
|
i have a gif file with me,and want to place that in the from .
i tried with picture box but its doen't animating.
do we have any other controls or techniques to achieve this?
My small attempt...
|
|
|
|