> Hello,
>
[quoted text clipped - 3 lines]
> calls in tmain are all to the same routine, while the one in the class
> constructor is different. Does anybody know what's going on here?
This is a guess, and I'd be interested to hear a more definitive answer.
First I used Reflector to have a look at what's going on:
public static unsafe int modopt(CallConvCdecl) main()
{
VClass class1;
int num4 = <Module>.new(4);
int* numPtr2 = (num4 == 0) ? null : ((int*) num4);
int num3 = <Module>.new(4);
int* numPtr1 = (num3 == 0) ? null : ((int*) num3);
int num2 = <Module>.new(4);
ref int numRef2 = (num2 == 0) ? 0 : num2;
int num1 = <Module>.new(4);
ref int numRef1 = (num1 == 0) ? 0 : num1;
class1 = new VClass();
class1 = new VClass();
return 0;
}
[PreserveSig, MethodImpl(MethodImplOptions.Unmanaged,
MethodCodeType=MethodCodeType.Native), SuppressUnmanagedCodeSecurity]
public static unsafe void* modopt(CallConvCdecl) @new(uint);
[StructLayout(LayoutKind.Sequential)]
internal struct VClass
{
public unsafe int* p;
public VClass();
}
public unsafe VClass()
{
int num2;
int num1 = <Module>.new(4);
if (num1 != 0)
{
num1[0] = 0;
num2 = num1;
}
else
{
num2 = 0;
}
this.p = (int*) num2;
}
I think therefore that because main() and new() have the same calling
convention (cdecl), the call can be made directly. However, when calling
from VClass (which presumably uses something different, stdcall maybe?), a
thunk has to be used to change between the calling conventions.
Stu
> Thanks
>
[quoted text clipped - 20 lines]
> return 0;
> }