|
You can't make it do it automatically. With MFC, you could use PostMessage, which would then cause the message to be sent when the current method had ended, but I don't believe C# supports anything like that, nor am I sure what would happen if you p/invoked PostMessage.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
You can't do that. But why would you want to do it anyway? It's against OO principles, and the solution you pointed out is perfectly valid. Everything else would make things much more complicated, obfuscated, and error-prone...
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
i wanna get Struct's address.
now i use DLL(made by API), so i have to use Pointer~
ofcourse i already use "unsafe" keyword~
i can get other variable's address..
but...struct's address... i can't...
please help me~~
for example~~
public struct first
{
.......
} //make struct
first fir = new first();
unsafe public void test_1 (first* a)
{
.......................
}
unsafe public void test_2 ()
{
test_1(&fir); <-------------------- This part has problem~
}
|
|
|
|
|
Hi,
you don't need unsafe to use P/Invoke.
What you should do is use the GCHandle class to pin objects (so the GC won't move them around),
then obtain their address, pass that as an IntPtr, and afterwards free the handle.
You don't need to do this for strings though: a read-only string can be passed as is, and your C code will get a valid char*. For a writable string, use a StringBuilder instead.
Make sure you describe the structs correctly; be careful with the size of simple types,
long in C# is 64-bit, in most C environments it is 32-bit; and char in C# is 16-bit, in C it is 8-bit. Also be careful with alignment, the byte stuffing rules could be different on both sides.
|
|
|
|
|
|
hi every body
how can i write a program in C# and run it in another pc that, THAT PC hasn't installed .net ?
i don't want to install .net in that pc, I mean how can I embed it in my program?
if evry one knows this....
saeed_saeed7007@yahoo.com
or
7007.saeed@gmail.com
|
|
|
|
|
As far as I know, you have to have the .net framework installed if you're program utilizes the .net framework or Mono[^]
|
|
|
|
|
|
|
I am using Visual Studio and I am trying to update my datagrid using the info from text boxes rather than using the binding navigator to directly input the information. I was hoping that I can fill in the fields with the info and click a button to update my datagrid. Is this possible? If so how?

|
|
|
|
|
The easier way is using a dataset n update it.
Good Luck.![Rose | [Rose]](https://www.codeproject.com/script/Forums/Images/rose.gif)
|
|
|
|
|
I am trying to figure out how to throttle the bandwidth used by my socket. I am having trouble figuring out how to break up the send buffer into smaller pieces and still let the receiving socket know that all the pieces are part of a single send.
|
|
|
|
|
One possible solution:
take your buffer and partition it into pieces. wrap each piece with some info so that the receiver can reassemble them into the correct order; minimally you'll need a Sequence ID, message number and stop flag. Then instead of sending all of your data in bulk at once send each packet at whatever rate you want so the receiver will receive them at your desired frequency.
The packet sequence should look something like this:
SEQ ID: 1
NUM: 1
COMPLETE: FALSE
BODY: < small part of the message >
SEQ ID: 1
NUM: 2
COMPLETE: FALSE
BODY: < another small part of the message >
...
SEQ ID: 1
NUM: n
COMPLETE: TRUE
BODY: < the last small part of the message >
the sender is responsible for making sure Seq IDs are unique, the data is partitioned/packaged properly and all packets are sent.
it's the job of the receiver to buffer the individual packets for each Sequence ID, wait until it receives the last packet number in the sequence and then reassemble the entire message. It should be able to handle cases like dropping packets (receiving packets 1 and 3 of a message but not 2) and receiving message packets out of order, but the specifics of what to do in those cases depend on your application.
For the next bulk send you want to perform increment the Sequence ID and repeat.
|
|
|
|
|
I'm trying to write a program, that displays some auxiliary information on top of a 3rd party
application. For now, I'm just trying to draw a transparent window, that lets keypresses and mouse events through to the 3rd party application, and draws a red border around its client area.
..but instead of doing that, what happens is that only small part of the upper left corner of my auxiliary screen gets drawn, while rest of the area stays black. The reason for this seems to be that the ClipRectangle in the Paint doesn't cover the whole area of my auxiliary window.
I've tried to invalidate the whole area by explicitly giving the window size, etc, but nothing seems to help. Please, can anyone see what is wrong and help me fix this? Thanks!
I've attached the code. Just replace the hwnd in the Main with a hwnd of an existing window to try it out.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Overlay {
public class OverlayForm : Form {
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetClientRect(HandleRef hwnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(HandleRef childWwnd, HandleRef newParentHwnd);
private IntPtr parentHwnd;
public OverlayForm(IntPtr parentHwnd) {
this.parentHwnd = parentHwnd;
this.Paint += new PaintEventHandler(OverlayForm_Paint);
this.SuspendLayout();
this.BackColor = System.Drawing.Color.Lime;
this.FormBorderStyle = FormBorderStyle.None;
this.TransparencyKey = Color.Lime;
this.StartPosition = FormStartPosition.Manual;
SetParent(new HandleRef(null, this.Handle), new HandleRef(null, parentHwnd));
adjustSize();
this.ResumeLayout(false);
this.PerformLayout();
Thread adjustThread = new Thread(adjustSizeContinuous);
adjustThread.Start();
}
private void adjustSizeContinuous() {
while(true) {
this.SuspendLayout();
adjustSize();
this.ResumeLayout(false);
this.PerformLayout();
Thread.Sleep(500);
}
}
private void adjustSize() {
RECT windowRect = new RECT();
RECT clientRect = new RECT();
GetWindowRect(new HandleRef(null, parentHwnd), out windowRect);
GetClientRect(new HandleRef(null, parentHwnd), out clientRect);
this.Location = new Point(windowRect.left, windowRect.top);
this.Size = new Size(clientRect.right, clientRect.bottom);
Refresh();
}
private void OverlayForm_Paint(object sender, PaintEventArgs e) {
Console.WriteLine(" cr = " + e.ClipRectangle);
Graphics g = e.Graphics;
g.Clear(Color.Lime);
Pen pen = new Pen(Color.Red, 10);
g.DrawRectangle(pen, 0, 0, ClientSize.Width, ClientSize.Height);
g.Dispose();
}
public static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
IntPtr hwnd = new IntPtr(0x00D3024A);
Application.Run(new OverlayForm(hwnd));
}
}
}
|
|
|
|
|
Hi,
I want to measure reaction times by playing a sound for the user, and the timing how long it takes for him to press space.... I just cant get it accurate enough. There is to much latency in the sound system, and the many message queues to make this work. I want it to be accurate within <10ms.
Can this even be done in Windows using .NET ??
/Jakob
ASCII tables, HTML entities, types, string formats and more info for the nerdy coder at: www.codecharts.com
|
|
|
|
|
Have you tried using the Stopwach[^] class? It uses a high resolution timer, if available on the system.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
That is the exact class i am using for the timing. It is highly accurate and that class is definetely not the problem.
I know from a very accurate soundbased reaction time measuring device, that my reaction times are about twice as fast, and more consistent than the ones i measure using a SoundPlayer, StopWatch and a KeyDown event. I have the feeling that this is because of small delays everywhere in the system (Windows is not a RTOS), but i have no idea what to do about them.
ASCII tables, HTML entities, types, string formats and more info for the nerdy coder at: www.codecharts.com
|
|
|
|
|
I'm trying to add images dynamically to an open xml spreadsheet.
I can add images to the package easily with
ImagePart imagePart = picturesWorksheet.WorksheetPart.AddImagePart(ImagePartType.Jpeg, imageId);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(imagePart.GetStream());
writer.Write(System.Convert.FromBase64String(base64Image));
But I can't seem to get them to appear on the worksheet, no matter what I've tried doing with the WorksheetDrawing object it just won't work!
If anyone has some sample code that would be great, as I've been scouring websites for hours with no success.
|
|
|
|
|
Hello All,
Is that possible to acquire a thread by specifying thread ID. Eg. I want to use thread ID 15 (or some number) only for my process, is this possible?
Thanks
|
|
|
|
|
No. You can't steal a thread from another process. If you did, how would you know what to do with it ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
My plan is to get hold of thread waiting for Async IO to complete and make it sleep. so that process will choose different thread to process call back.
E.g. Thread 15 is waiting for IO to complete. I want to make thread 15 to sleep. So, when call back comes after IO completion, that should get processed on different thread than 15. Am Trying to reproduce thread switching scenario.
I guess its difficult to reproduce.
Thanks.
|
|
|
|
|
Member 2324483 wrote: My plan is to get hold of thread waiting for Async IO to complete and make it sleep
The main advantage of async operation is non-blocking fashioned execution. It uses less resources and won't keep any threads in blocking.
Member 2324483 wrote: Thread 15 is waiting for IO to complete. I want to make thread 15 to sleep. So, when call back comes after IO completion, that should get processed on different thread than 15
You said Thread15 is doing IO operation. So if you put it in sleep, how come that operation will end? Also there is no way to put a thread in sleep from another thread. Please explain why you need this.
|
|
|
|
|
Hello gentlemen,
I would like to write a service and an form appl.I need to obtain data from service to my form application(some information). Is it possible? If yes, could you give me a hint?
Thank you very much.
|
|
|
|
|
daavena wrote: Is it possible?
Yes.
daavena wrote: If yes, could you give me a hint?
It can be done via Inter-Process communication. Possible solutions are:
Pipes and .Net Remoting/WCF
|
|
|
|
|
Thank you. I will check it.
|
|
|
|