> For the complete documentation index, see [llms.txt](https://pinvokeisalive.gitbook.io/pinvoke/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pinvokeisalive.gitbook.io/pinvoke/desktopfunctions/ole32/createilockbytesonhglobal.md).

# CreateILockBytesOnHGlobal

### C# Signature:

```cs
/// <summary>
    /// The CreateILockBytesOnHGlobal function creates a byte array object, 
    /// using global memory as the physical device, which is intended to be the 
    /// compound file foundation. This object supports a COM implementation of the 
    /// ILockBytes interface.
    /// </summary>
    /// 
    /// <param name="hGlobal">The memory handle allocated by the GlobalAlloc function. 
    /// The handle must be allocated as moveable and nondiscardable. If the handle is 
    /// shared between processes, it must also be allocated as shared. New handles should 
    /// be allocated with a size of zero. If hGlobal is NULL, CreateILockBytesOnHGlobal 
    /// internally allocates a new shared memory block of size zero.</param>
    /// 
    /// <param name="fDeleteOnRelease">A flag that specifies whether the underlying handle 
    /// for this byte array object should be automatically freed when the object is released. 
    /// If set to FALSE, the caller must free the hGlobal after the final release. If set 
    /// to TRUE, the final release will automatically free the hGlobal parameter.</param>
    /// 
    /// <param name="ppLkbyt">The address of ILockBytes pointer variable that receives the 
    /// interface pointer to the new byte array object.</param>
    /// 
    /// <returns>This function supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following:
    /// S_OK: The byte array object was created successfully.</returns>
    [DllImport ("ole32.dll")]
    public extern static int CreateILockBytesOnHGlobal(IntPtr hGlobal, [MarshalAs(UnmanagedType.Bool)] bool fDeleteOnRelease, out ILockBytes ppLkbyt);
```

### C# Signature:

```cs
[DllImport("ole32.dll",
    EntryPoint="CreateILockBytesOnHGlobal",
    ExactSpelling=true, PreserveSig=true, CharSet=CharSet.Ansi,
    CallingConvention=CallingConvention.StdCall)]
static extern int CreateILockBytesOnHGlobal(IntPtr /* HGLOBAL */ hGlobal, bool fDeleteOnRelease, [MarshalAs(UnmanagedType.Interface)]out object /* ILockBytes** */ ppLkbyt);
```

### VB.NET Signature:

```cs
<DllImport("ole32.dll")> _
    Public Shared Function CreateILockBytesOnHGlobal(ByVal hGlobal As IntPtr, _
                              ByVal fDeleteOnRelease As Boolean, _
                              <Out()> ByRef ppLkbyt As IlockBytes) _
                              As Integer
    End Function
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://pinvokeisalive.gitbook.io/pinvoke/desktopfunctions/ole32/createilockbytesonhglobal.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
