예제 #1
0
        public CcmErrorCode EnumerateApplications(out IcaApplication[] applications)
        {
            var ptrSize = Marshal.SizeOf(typeof(CcmIcaApplication));
            var ptr     = IntPtr.Zero;

            var result = Environment.Is64BitProcess ?
                         CcmSdk64.CCMEnumerateApplications(out var count, ref ptr) :
                         CcmSdk32.CCMEnumerateApplications(out count, ref ptr);

            applications = new IcaApplication[count];
            for (int i = 0; i < count; i++)
            {
                var nPtr      = IntPtr.Add(ptr, i * ptrSize);
                var appStruct = Marshal.PtrToStructure <CcmIcaApplication>(nPtr);

                var appDto = new IcaApplication()
                {
                    ApplicationID = appStruct.ApplicationID,
                    SessionID     = appStruct.SessionID,
                    FriendlyName  = appStruct.FriendlyName,
                    Title         = appStruct.Title,
                    ClassName     = appStruct.ClassName,
                    IconByteArray = PinvokeHelper.GetIconBytesFromIntPtr(appStruct.hIcon)
                };

                applications[i] = appDto;
            }

            _ = Environment.Is64BitProcess ?
                CcmSdk64.CCMFreeICAApplication(count, ptr) :
                CcmSdk32.CCMFreeICAApplication(count, ptr);

            return((CcmErrorCode)result);
        }