private VibrateController()
        {
            if (InTheHand.WindowsCE.Forms.SystemSettingsInTheHand.Platform != WinCEPlatform.Smartphone)
            {
                // get count
                int    count = -1;
                IntPtr p     = Marshal.AllocHGlobal(4);
                try
                {
                    bool success = NativeMethods.NLedGetDeviceInfo(0, p);
                    count = Marshal.ReadInt32(p);
                }
                finally
                {
                    Marshal.FreeHGlobal(p);
                }

                // loop through leds
                for (int i = 0; i < count; i++)
                {
                    System.Diagnostics.Debug.WriteLine(i.ToString());

                    // set ledIndex if vibrate
                    IntPtr ps = MarshalInTheHand.AllocHGlobal(Marshal.SizeOf(typeof(NativeMethods.NLED_SUPPORTS_INFO)));
                    try
                    {
                        Marshal.WriteInt32(ps, i);
                        bool success = NativeMethods.NLedGetDeviceInfo(1, ps);
                        if (success)
                        {
                            NativeMethods.NLED_SUPPORTS_INFO lsi = (NativeMethods.NLED_SUPPORTS_INFO)Marshal.PtrToStructure(ps, typeof(NativeMethods.NLED_SUPPORTS_INFO));

                            if (lsi.lCycleAdjust == -1)
                            {
                                ledIndex = i;
                                return;
                            }
                        }
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(ps);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private FileVersionInfo(string fileName)
        {
            //get the filename sans path
            this.filename = System.IO.Path.GetFileName(fileName);

            int    handle;
            ushort language;
            ushort codepage;
            int    len = 0;

            //get size of version info
            len = NativeMethods.GetInfoSize(fileName, out handle);

            if (len > 0)
            {
                //allocate buffer
                IntPtr buffer = MarshalInTheHand.AllocHGlobal(len);

                try
                {
                    //get version information
                    if (NativeMethods.GetInfo(fileName, handle, len, buffer))
                    {
                        IntPtr fixedbuffer = IntPtr.Zero;
                        int    fixedlen;
                        //get language independent version info
                        //this is a pointer within the main buffer so don't free it
                        if (NativeMethods.QueryValue(buffer, "\\", out fixedbuffer, out fixedlen))
                        {
                            fixedFileInfo = (VS_FIXEDFILEINFO)Marshal.PtrToStructure(fixedbuffer, typeof(VS_FIXEDFILEINFO));
                        }
                        else
                        {
                            throw InTheHand.ComponentModel.Win32ExceptionInTheHand.Create();
                        }
                        IntPtr langBuffer = IntPtr.Zero;
                        int    langLen;
                        if (NativeMethods.QueryValue(buffer, "\\VarFileInfo\\Translation", out langBuffer, out langLen))
                        {
                            if (langLen > 0)
                            {
                                language = (ushort)Marshal.PtrToStructure(langBuffer, typeof(ushort));
                                codepage = (ushort)Marshal.PtrToStructure(IntPtrInTheHand.Add(langBuffer, 2), typeof(ushort));

                                IntPtr stringPtr;
                                int    stringLen;

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "Comments"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        comments = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "CompanyName"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        companyName = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "FileDescription"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        fileDescription = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "FileVersion"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        fileVersion = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "InternalName"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        internalName = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                    else
                                    {
                                        internalName = System.IO.Path.GetFileNameWithoutExtension(fileName);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "LegalCopyright"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        legalCopyright = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "LegalTrademarks"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        legalTrademarks = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "OriginalFilename"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        originalFilename = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "ProductName"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        productName = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "ProductVersion"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        productVersion = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "ProductName"), out stringPtr, out stringLen))
                                {
                                    if (stringLen > 0)
                                    {
                                        productName = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                    }
                                }

                                if (IsPrivateBuild)
                                {
                                    if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "PrivateBuild"), out stringPtr, out stringLen))
                                    {
                                        if (stringLen > 0)
                                        {
                                            privateBuild = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                        }
                                    }
                                }

                                if (IsSpecialBuild)
                                {
                                    if (NativeMethods.QueryValue(buffer, string.Format(valueNameMask, language, codepage, "SpecialBuild"), out stringPtr, out stringLen))
                                    {
                                        if (stringLen > 0)
                                        {
                                            specialBuild = Marshal.PtrToStringUni(stringPtr, stringLen - 1);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        throw InTheHand.ComponentModel.Win32ExceptionInTheHand.Create();
                    }
                }
                finally
                {
                    if (buffer != IntPtr.Zero)
                    {
                        //free native buffer
                        Marshal.FreeHGlobal(buffer);
                    }
                }
            }
        }