|
Sounds like a candidate for T4 if you're using Visual Studio.
|
|
|
|
|
Nope, sorry - don't agree.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I have array list contains bytes , I want to check if the first byte start with 99 and end with 0d this means i have received a complete message but message length may be either 6 or 30 so if i received message start with 99 and it's terminal is 0d with message length 6 I will do operation and if length of message is 30 I will do another operation.
How I can check like this.
|
|
|
|
|
You have an ArrayList of byte? ArrayList has a Count property ( from documentation: Gets the number of elements actually contained in the ArrayList.)
Whas that it?
|
|
|
|
|
You really shouldn't have to ask such a simple question. When you read a 99 put it and any following bytes into the List (don't use ArrayList) and when you find a 0d, check the Count. Take the appropriate action then clear the List.
|
|
|
|
|
This question has already been answered here[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hello Experts,
I would like to ask some help if how can I know the number of pc connected in my network.
Any link of suggestion/comments for me to read if what will I use is kindly appreciated.
Thanks,
DAN
|
|
|
|
|
Here[^] is a solution for you
|
|
|
|
|
Hello,
Thanks for the nice link it was very useful.
Still confusing how to understand the code but having a guide
on what to do is a bit more easier
Thanks,
DAN
|
|
|
|
|
You may use the Comments and Discussions section below the article and add a new message to the article writer and ask what you more want to know.
|
|
|
|
|
How to generate script of a database at run time in c#.
|
|
|
|
|
|
|
See here[^]
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Wrong again! - don't worry, I won't bother going back through any more of your so called answers
return 5;
|
|
|
|
|
Hey there,
I'm working on an NTFS Master File Table reader as part of a project for University. I've already got a Console API working in C++ which reads the current $MFT file/table, and i've begun work on porting the code over to C# (as per my requirements), however my version of SetFilePointerEx doesn't seem to move the file buffer pointer.
My C++ code:
BOOL __stdcall SetFileBlockLocation(HANDLE address, LARGE_INTEGER position)
{
return SetFilePointerEx(address, position, NULL, FILE_BEGIN);
}
My C# code:
public bool AssignPointerPosition(Int64 position, EFileMove movement)
{
if (this.IsBufferReady == false)
return false;
if (Win32API.SetFilePointerEx(this.block, (long)position, IntPtr.Zero, movement) == false)
{
this.errorcode = Marshal.GetLastWin32Error();
this.errorpos = MFTHaltPosition.MoveFile;
return false;
}
return true;
}
Where EFileMove is set to EFileMove.FileBegin (aka. 0)
When I run another ReadFile , it continues to read out the same block of data into the buffer (the first four bytes should be FILE , but instead reads the beginning of the NTFS block).
Does anyone have an idea why it wouldn't move the pointer forward (position is a value far above 0), and is there a solution?
Thank you,
Chris
|
|
|
|
|
What does your import/p-invoke look like for SetFilePointerEx? What is this.block defined as?
|
|
|
|
|
My SetFilePointerEx import looks like this:
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetFilePointerEx(IntPtr fHandle, long lDistance, IntPtr lpNewPointer, EFileMove dwMove);
And the block attribute is an IntPtr :
private IntPtr block;
Which stores the file pointer created by CreateFile , and is used to read the data.
|
|
|
|
|
Is SetFilePointerEx returning 0? If so, what is GetLastError reporting?
I would recommend using SafeFileHandle instead of IntPtr for the file handle.
I assume you are doing a verbatum translation of your C++ code to C#, so that you know the actual sequence of calls you are performing are valid.
|
|
|
|
|
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.”
|
|
|
|