G
Guest
Hi,
I have doubts. From p/invoke and most site, they recommend to use this.
Example1:
[DllImport("kernel32.dll")]
static extern bool ReadFile(IntPtr hFile, byte[] lpBuffer,
uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr
lpOverlapped);
But I only want to read 1 byte at a time.
Example2:
[DllImport("kernel32.dll")]
static extern bool ReadFile(IntPtr hFile, ref byte lpBuffer, uint
nNumberOfBytesToRead, ref uint lpNumberOfBytesRead, IntPtr lpOverlapped);
Can i do this instead?
If just say, no choice i have to stick to Example1, when i run that
function, and only read lpBuffer[0], it does not return what i expected.
But if only follow Example2, it will. But the only issue i have is,
Sample snippet:
for(;
{
// some processing
bool test = ReadFile(...)..
}
so basically in this loop, it will read till 8 times of data...
00 11 22 33 44 55 66 77 88 // just say this is what i expect it to give me
but it give me instead
00 11 22 33 44 55 66 00 01 // wrong! Sometimes i get this, and sometimes i
get the above one.
Why?
I try to test on separate machine, or restart my machine. Sometimes i just
get either the one with 88 99 or 00 01!
I have an existing C SDK, and it is running smoothly. That is why i can
compare whether my .NET SDK is working properly or not.
Can anyone provide me any guideslines please?
I have doubts. From p/invoke and most site, they recommend to use this.
Example1:
[DllImport("kernel32.dll")]
static extern bool ReadFile(IntPtr hFile, byte[] lpBuffer,
uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr
lpOverlapped);
But I only want to read 1 byte at a time.
Example2:
[DllImport("kernel32.dll")]
static extern bool ReadFile(IntPtr hFile, ref byte lpBuffer, uint
nNumberOfBytesToRead, ref uint lpNumberOfBytesRead, IntPtr lpOverlapped);
Can i do this instead?
If just say, no choice i have to stick to Example1, when i run that
function, and only read lpBuffer[0], it does not return what i expected.
But if only follow Example2, it will. But the only issue i have is,
Sample snippet:
for(;

{
// some processing
bool test = ReadFile(...)..
}
so basically in this loop, it will read till 8 times of data...
00 11 22 33 44 55 66 77 88 // just say this is what i expect it to give me
but it give me instead
00 11 22 33 44 55 66 00 01 // wrong! Sometimes i get this, and sometimes i
get the above one.
Why?
I try to test on separate machine, or restart my machine. Sometimes i just
get either the one with 88 99 or 00 01!
I have an existing C SDK, and it is running smoothly. That is why i can
compare whether my .NET SDK is working properly or not.
Can anyone provide me any guideslines please?