G
Guest
I could not get the following code to compile:
public ref class wrapper
{
void Read(int^ mpLen)
{
pin_ptr<int> pLen = mpLen;
unmanaged* punman = new unmanaged();
punman->Read(pLen);
return;
}
}
The error was in the conversion from a managed pointer, mpLen, to
pin_ptr<int>.
When I changed the code by wrapping the int in a managed class, it worked:
public ref class BytesRead
{
public:
int Len;
};
public ref class wrapper
{
void Read(BytesRead^ mpBR)
{
pin_ptr<int> pLen = &mpBR->Len;
unmanaged* punman = new unmanaged();
punman->Read(pLen);
return;
}
}
I interpret that difference as pin_ptr being happy with an interior pointer
but not a whole pointer. But surely there is a way to pin the whole pointer
to a managed class. What did I do wrong?
Thanks in advance,
Ray
public ref class wrapper
{
void Read(int^ mpLen)
{
pin_ptr<int> pLen = mpLen;
unmanaged* punman = new unmanaged();
punman->Read(pLen);
return;
}
}
The error was in the conversion from a managed pointer, mpLen, to
pin_ptr<int>.
When I changed the code by wrapping the int in a managed class, it worked:
public ref class BytesRead
{
public:
int Len;
};
public ref class wrapper
{
void Read(BytesRead^ mpBR)
{
pin_ptr<int> pLen = &mpBR->Len;
unmanaged* punman = new unmanaged();
punman->Read(pLen);
return;
}
}
I interpret that difference as pin_ptr being happy with an interior pointer
but not a whole pointer. But surely there is a way to pin the whole pointer
to a managed class. What did I do wrong?
Thanks in advance,
Ray