Domanda

I have picked up this piece of code but as I understand it is unsafe code to use and may not be possible in WP7. Does anyone have an idea about how I can make this code safe to use, maybe with try/catch?

GCHandle gch = GCHandle.Alloc(waveInBytes,GCHandleType.Pinned);
int pPtr;

unsafe
{
    pPtr = (int)gch.AddrOfPinnedObject().ToPointer();
    pPtr += 4;
}
È stato utile?

Soluzione

Pointers in general are unsafe. IntPtr.ToPointer() returns a void* type, which is what's causing the error. try/catch doesn't help.

Depending on the larger context of what you're trying to do, it may work to just change the ToPointer() call to be ToInt32(). Realistically you're likely going to have more problems than just this compiler error with trying to convert this kind of code to WP7.

Hope that helps, anyways.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top