G
Guest
Can somone tell me why one senario works but not the other?
namespace mynamespaceA
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct structA
{
public int a1;
}
public unsafe class classA
{
public unsafe void FunctionA(void* ptrA)
{
structA* castPtrA = (structA*)ptrA;
// this will fail!!!!!!!!!!!! WHY???????????????
}
}
}
namespace mynamespaceB
{
public unsafe class classB
{
public void FunctionB(void* ptrB)
{
structB* castPtrB = (structB*)ptrB;
// this will work l!!!!!!!!!!!!
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct structB
{
public int b1;
}
}
}
Q2: why wont the following work:
namespace mynamespaceA
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct structA
{
public int a1;
public void FunctionA(void* ptrA)
{
structA* castPtrA = (structA*)ptrA;
// this will fail!!!!!!!!!!!! WHY???????????????
}
}
}
Yes I know I like unsafe too much
namespace mynamespaceA
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct structA
{
public int a1;
}
public unsafe class classA
{
public unsafe void FunctionA(void* ptrA)
{
structA* castPtrA = (structA*)ptrA;
// this will fail!!!!!!!!!!!! WHY???????????????
}
}
}
namespace mynamespaceB
{
public unsafe class classB
{
public void FunctionB(void* ptrB)
{
structB* castPtrB = (structB*)ptrB;
// this will work l!!!!!!!!!!!!
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct structB
{
public int b1;
}
}
}
Q2: why wont the following work:
namespace mynamespaceA
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct structA
{
public int a1;
public void FunctionA(void* ptrA)
{
structA* castPtrA = (structA*)ptrA;
// this will fail!!!!!!!!!!!! WHY???????????????
}
}
}
Yes I know I like unsafe too much
