|
Yes, my EFileMove structure is inheriting uint .
When I get chance, i'll try converting the code to use SafeFileHandle .
When I run SetFilePointerEx and sending 0 as the distance to move, and setting the file movement to EFileMove.FileEnd , the resulting long value is always 0. It doesn't seem to adjust the pointer at all.
I'm wondering if I should try passing a LARGE_INTEGER structure through it instead?
|
|
|
|
|
if SetFilePointerEx is returning false, then you should look at the error code.
<br />
if (!SetFilePointerEx(...)) {<br />
throw new Win32Exception(Marshal.GetLastWin32Error());<br />
}<br />
|
|
|
|
|
It's not returning false, but the long output for the 3rd argument (if I change the argument type to ref long ) returns 0 (which documented by MSDN, would return the position of the pointer, thus the pointer hasn't changed).
|
|
|
|
|
The third argument is actually 64 bit unsigned, so strictly speaking long is not the correct cast.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Edit
Nevermind. Seems passing Threading.NativeOverlapped to ReadFile was causing issues with the buffer. And I also changed all IntPtr to SafeFileHandle , and it's working now. Thanks!
Previous
It makes no difference if I convert all the Int64 types long , it still doesn't adjust the pointer and my SetFilePointerEx(this.block, 0, out pos, EFileMove.FileEnd); still assigns 0 to the pos variable (and the buffer is not changed).
modified on Saturday, January 1, 2011 7:41 AM
|
|
|
|
|
Not that it should make any difference, so far as I can tell, but just in case it triggers something in your brain cell.
Is the type of your EFileMove set to uint ?
enum EFileMove : uint
{
FileBegin = 0,
.................
.................
{
The documentation I have read says the dwMoveNethod should be a uint.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
the boundary between managed and unmanaged code does not care about the exact numeric type, all it needs is the right amount of bits. Signed and unsigned are irrelevant at run-time, as it used to be in purely native code.
|
|
|
|
|
On the way in, I agree.
Although I understood that if the unmanaged part filled those bits with what it considered an unsigned value and then on return to the managed code those same bits were treated as or cast to a signed value, there is a possibility of unpredictable results.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
If you use P/Invoke sufficiently correctly (it does not care about the exact integer types, all that matters is the size of the variables), the C# version should behave the same as the C++ version.
And then the MSDN documentation says: "The file pointer returned by this function is not used for overlapped read and write operations. To specify the offset for overlapped operations, use the Offset and OffsetHigh members of the OVERLAPPED structure." Maybe that explains some.
|
|
|
|
|
How do I get access to dynamically created controls on a form in something like this?
form f = new form();
Button pbutton = new Button()..
TextBox pText = new TextBox()...
...
f.controls.add(pButton)
f.controls.add(pText)
....
private void MyHoverHandler(object sender, EventArgs e)
{
}
Thanks
|
|
|
|
|
TextBox pText = new TextBox();
pText.Name = "MyTextBox";
f.Controls.Add(pText1);
private void MyHoverHandler(object sender, EventArgs e)
{
TextBox pText = (TextBox)this.Controls["MyTextBox"];
}
If you can't refer to the form with this , use:
Form f = ((Control)sender).FindForm();
TextBox pText = (TextBox)f.Controls["MyTextBox"];
Greets
Flo
|
|
|
|
|
Thanks for the answer. This method can get tedious if you have lots of dynamic controls though. What if I had 100 buttons and 100 textboxes..etc, Do you have to maintains an array manually, or does the form have all these controls available somehow where you can just do foreach(..)?
Thanks again
|
|
|
|
|
A Form (actually a Control , a Form is a Control) has a Controls collection[^] which keeps track of all the controls placed on it.
So you can do a foreach over that.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
The initial posting shows him adding elements to the Controls collection ...
|
|
|
|
|
I know.
However, they still asked if there were such a collection, in spite of using it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I do not understand exactly what what you want to do. You want to somehow access a specific dynamically created control when you hover over an other dynamically created control?
Then you could use the "Tag" property of the former: set it to the latter, and then access that control.
pButton.Tag = pText;
In the handler use:
Control ctrl = sender as Control;
if (ctrl != null && ctrl.Tag != null)
{
TextBox textBox = sender.Tag as TextBox;
if (textBox != null)
{
textBox.Text = "new text";
}
}
|
|
|
|
|
I am trying to subclassing a checkbox inside a toolstrip. Works OK but the VS interface does not remember the checkboxs after running the app.
Ran the profiler and got this warning...
Warning 11 CA2000 : Microsoft.Reliability : In method 'ToolStripCheckBox.ToolStripCheckBox()', call System.IDisposable.Dispose on object 'new CheckBox()' before all references to it are out of scope.
So I'm not sure where to place the System.IDisposable.Dispose in my checkbox class. Can someone assist me in this.
Below is the code ...
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
[System.ComponentModel.DesignerCategory("code")]
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripCheckBox : ToolStripControlHost
{
public ToolStripCheckBox() : base(new CheckBox())
{
}
public CheckBox CheckBoxControl
{
get { return Control as CheckBox; }
}
public bool Checked
{
get { return CheckBoxControl.Checked; }
set { CheckBoxControl.Checked = value; }
}
public event EventHandler CheckedChanged;
public void OnCheckedChanged(object sender, EventArgs e)
{
if (CheckedChanged != null)
{
CheckedChanged(sender, e);
}
}
protected override void OnSubscribeControlEvents(Control control)
{
base.OnSubscribeControlEvents(control);
(control as CheckBox).CheckedChanged += OnCheckedChanged;
}
protected override void OnUnsubscribeControlEvents(Control control)
{
base.OnUnsubscribeControlEvents(control);
(control as CheckBox).CheckedChanged -= OnCheckedChanged;
}
}
tia
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Implement the Disposable pattern
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for the Info Mark...based on the error text I gathered that this is what I am supposed to do. If I knew how I wouldn't have had to ask...
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Ever heard of GOOGLE
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yea as a matter of fact I have read 17 articles before posting and about 25 since posting. I guess I'm just not as good at understanding it as you are!
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Rafone wrote: I have read 17 articles before posting and about 25 since posting
Absolutely pathetic. In all of your searching you couldn't even find this: Implementing Finalize and Dispose[^]
Hell even here the first five of 140,000 hits show exact code to implement it.
Disposal Pattern .NET[^]
You will never get any where in this field by feigning such ignorance and having others do the work for you.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes found and read both of those you sight. As I said before finding articles to read is not the problem understanding them is....
I guess if you understood then you would have been helping me to understand instead of pointing me in the direction I had already taken.
thanks for your time though...
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Rafone wrote: I guess if you understood then you would have been helping me
The links present you with clear, concise and full implementations of this pattern. Perhaps you should state clearly what part of it you don't understand rather than down voting.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
It appears this is a bug in VS2010
I am seeing a CA200 Warning (call Dispose) on a variable declared within a using statement.
Type: Bug
ID: 521027
Opened: 12/17/2009 2:10:58 PM
Access Restriction: Public
0 Workaround(s)
7 User(s) can reproduce this bug
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|