Пример #1
0
        public static void RegisterAppSchemaHandler(AppSchemaHandler handler)
        {
            AppSchemaHandler_ handler_ = ((url, mimeTypePtr, dataPtr) =>
            {
                string mimeType;
                byte[] data = handler(url, out mimeType);
                if (schemaHandlerData != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(schemaHandlerData);
                    schemaHandlerData = IntPtr.Zero;
                }
                if (data != null)
                {
                    schemaHandlerData = Marshal.AllocHGlobal(data.Length);
                    Marshal.Copy(data, 0, schemaHandlerData, data.Length);
                    Marshal.WriteIntPtr(dataPtr, schemaHandlerData);
                    byte[] mimeTypeBytes = mimeType.Select(c => (byte)c).Take(255).ToArray();
                    Marshal.Copy(mimeTypeBytes, 0, mimeTypePtr, mimeTypeBytes.Length);
                    Marshal.WriteByte(mimeTypePtr, mimeTypeBytes.Length, 0);
                    return(data.Length);
                }
                else
                {
                    return(-1);
                }
            });

            schemaHandler = handler_;
            registerAppSchemaHandler_(handler_);
        }
Пример #2
0
 static extern void registerAppSchemaHandler_(AppSchemaHandler_ handler_);