コード例 #1
0
        /// <summary>
        /// Formats the message from the given DLL, having the system allocate the message buffer.
        /// </summary>
        /// <param name="flags">The formatting message flags. This must include <see cref="FORMAT_MESSAGE_ALLOCATE_BUFFER"/>, <see cref="FORMAT_MESSAGE_FROM_HMODULE"/>, and <see cref="FORMAT_MESSAGE_IGNORE_INSERTS"/>.</param>
        /// <param name="dll">The DLL to search for the message definition. May not be <c>null</c>.</param>
        /// <param name="code">The code identifying the message to look up.</param>
        /// <param name="localMemory">On return, contains a handle to a local memory buffer allocated by the system.</param>
        /// <param name="minimumBufferSize">Minimum size of the buffer local memory buffer to allocate.</param>
        /// <returns>The number of valid characters in the local memory buffer.</returns>
        private static uint FormatMessageFromModuleAllocatingBuffer(uint flags, SafeModuleHandle dll, uint code, out SafeLocalMemoryHandle localMemory, uint minimumBufferSize)
        {
            Contract.Requires(dll != null);
            Contract.Ensures(Contract.ValueAtReturn <SafeLocalMemoryHandle>(out localMemory) != null);
            Contract.Ensures(Contract.Result <uint>() != 0);

            uint ret = DoFormatMessageFromModuleAllocatingBuffer(flags, dll, code, 0, out localMemory, minimumBufferSize, IntPtr.Zero);

            if (ret == 0)
            {
                throw Interop.GetLastWin32Exception();
            }

            Contract.Assume(localMemory != null);
            return(ret);
        }
コード例 #2
0
 private static extern uint DoFormatMessageFromModuleAllocatingBuffer(uint flags, SafeModuleHandle lpSource, uint dwMessageId, uint dwLanguageId, out SafeLocalMemoryHandle lpBuffer, uint nSize, IntPtr arguments);
コード例 #3
0
        /// <summary>
        /// Formats the message from the given DLL, having the system allocate the message buffer.
        /// </summary>
        /// <param name="flags">The formatting message flags. This must include <see cref="FORMAT_MESSAGE_ALLOCATE_BUFFER"/>, <see cref="FORMAT_MESSAGE_FROM_HMODULE"/>, and <see cref="FORMAT_MESSAGE_IGNORE_INSERTS"/>.</param>
        /// <param name="dll">The DLL to search for the message definition.</param>
        /// <param name="code">The code identifying the message to look up.</param>
        /// <param name="localMemory">On return, contains a handle to a local memory buffer allocated by the system.</param>
        /// <param name="minimumBufferSize">Minimum size of the buffer local memory buffer to allocate.</param>
        /// <returns>The number of valid characters in the local memory buffer.</returns>
        private static uint FormatMessageFromModuleAllocatingBuffer(uint flags, SafeModuleHandle dll, uint code, out SafeLocalMemoryHandle localMemory, uint minimumBufferSize)
        {
            uint ret = DoFormatMessageFromModuleAllocatingBuffer(flags, dll, code, 0, out localMemory, minimumBufferSize, IntPtr.Zero);

            if (ret == 0)
            {
                throw Interop.GetLastWin32Exception();
            }

            return(ret);
        }