When do I need to pin?
- From: nickdu <nicknospamdu@xxxxxxxxxxxxxxxx>
- Date: Wed, 1 Oct 2008 18:07:01 -0700
Just wondering when pinning is required when using PInvoke? In some of the
other posts I read someone mentioned the runtime pins objects for us while
making the interop call and unpins when the call is finished. Is this true?
If so, I'm wondering why the following article:
http://msdn.microsoft.com/en-us/library/2d9wy99d.aspx, has this:
[System.Runtime.InteropServices.DllImport("kernel32", SetLastError = true)]
static extern unsafe bool ReadFile
(
System.IntPtr hFile, // handle to file
void* pBuffer, // data buffer
int NumberOfBytesToRead, // number of bytes to read
int* pNumberOfBytesRead, // number of bytes read
int Overlapped // overlapped buffer
);
public unsafe int Read(byte[] buffer, int index, int count)
{
int n = 0;
fixed (byte* p = buffer)
{
if (!ReadFile(handle, p + index, count, &n, 0))
{
return 0;
}
}
return n;
}
--
Thanks,
Nick
nicknospamdu@xxxxxxxxxxxxxxxx
remove "nospam" change community. to msn.com
.
- Follow-Ups:
- RE: When do I need to pin?
- From: "Jialiang Ge [MSFT]"
- RE: When do I need to pin?
- Prev by Date: Re: issue: calling a C# library function (COMInterop) from an excel macro (VBA)
- Next by Date: RE: When do I need to pin?
- Previous by thread: Re: issue: calling a C# library function (COMInterop) from an excel macro (VBA)
- Next by thread: RE: When do I need to pin?
- Index(es):
Relevant Pages
|
Loading