문제

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;
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top