Ejemplo n.º 1
0
        private unsafe long GetTypeInfoVersion(UnsafeNativeMethods.ITypeInfo pTypeInfo) {


            IntPtr pTypeAttr = IntPtr.Zero;
            int hr = pTypeInfo.GetTypeAttr(ref pTypeAttr);
            if (!NativeMethods.Succeeded(hr)) {
                return 0;
            }

            System.Runtime.InteropServices.ComTypes.TYPEATTR pTAStruct;
            try {
                try {
                    // just access directly...no marshalling needed!
                    //
                    pTAStruct = *(System.Runtime.InteropServices.ComTypes.TYPEATTR*)pTypeAttr;
                }
                catch {

                    return 0;
                }

                long result = 0;

                // we pull two things out of the struct: the 
                // number of functions and variables, and the version.
                // since they are next to each other, we just pull the memory directly.
                //
                // the cFuncs and cVars are both shorts, so we read them as one block of ints.
                //
                //
                int* pResult = (int*)&result;
                byte* pbStruct = (byte*)&pTAStruct;

                // in the low byte, pull the number of props.
                //
                *pResult = *(int*)(pbStruct + CountMemberOffset);

                // move up to the high word of the long.
                //                
                pResult++;

                // now pull out the version info.
                //
                *pResult = *(int*)(pbStruct + VersionOffset);

                // return that composite long.
                //
                return result;
            }
            finally {
               pTypeInfo.ReleaseTypeAttr(pTypeAttr);
            }
        }