coredll.dll ReadFile

  • Thread starter Thread starter Empi
  • Start date Start date
E

Empi

Hi,

is [DllImport("coredll.dll", EntryPoint="ReadFile")] managed or not ?
If not, how come I find no sample that relate to the byte[] array
with marshal unmanaged to avoid memory buffer mismatch (none sequential
memory area) ?


Thanks.
 
I don't understand the question. It's clearly C#, which by definition is
managed code. Nearly all samples for it I would expect to use a byte[]
parameter for the lpBuffer parameter, but I don't know what you mean by
"marshal unmanaged" or "avoid memory mismatch". Do you mean avoiding a
pointer invalidation due to a GC compaction? ReadFile is synchronous, so
once your thread goes into the call, compaction can't occur until you return
from it, so there's nothing inherently unsafe about the operation and
pinning the inbound array isn't necessary (though pre-allocation is).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
Thanks.

I didn't know if coredll.dll has it all managed or further depends on
unmanaged api's.


I don't understand the question. It's clearly C#, which by definition is
managed code. Nearly all samples for it I would expect to use a byte[]
parameter for the lpBuffer parameter, but I don't know what you mean by
"marshal unmanaged" or "avoid memory mismatch". Do you mean avoiding a
pointer invalidation due to a GC compaction? ReadFile is synchronous, so
once your thread goes into the call, compaction can't occur until you
return from it, so there's nothing inherently unsafe about the operation
and pinning the inbound array isn't necessary (though pre-allocation is).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com




Empi said:
Hi,

is [DllImport("coredll.dll", EntryPoint="ReadFile")] managed or not ?
If not, how come I find no sample that relate to the byte[] array
with marshal unmanaged to avoid memory buffer mismatch (none sequential
memory area) ?


Thanks.
 
Coredll itself, the DLL, is native code, not managed. You're platform
invoking, P/Invoking, that call, which is the same call that a native C
program running on the device would access if it were reading from a file.

Paul T.

Empi said:
Thanks.

I didn't know if coredll.dll has it all managed or further depends on
unmanaged api's.


I don't understand the question. It's clearly C#, which by definition is
managed code. Nearly all samples for it I would expect to use a byte[]
parameter for the lpBuffer parameter, but I don't know what you mean by
"marshal unmanaged" or "avoid memory mismatch". Do you mean avoiding a
pointer invalidation due to a GC compaction? ReadFile is synchronous, so
once your thread goes into the call, compaction can't occur until you
return from it, so there's nothing inherently unsafe about the operation
and pinning the inbound array isn't necessary (though pre-allocation is).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com




Empi said:
Hi,

is [DllImport("coredll.dll", EntryPoint="ReadFile")] managed or not ?
If not, how come I find no sample that relate to the byte[] array
with marshal unmanaged to avoid memory buffer mismatch (none sequential
memory area) ?


Thanks.
 
Back
Top