import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'


The **GW2RegisterOutputMemory** function registers the memory location to place the managed file produced by Glasswall to a session. Using this function **activates the Manage & Protect Process Mode** for the session.

<Tabs>

<TabItem value="C++" label="C++" default>

**Synopsis**

For session **session**, the **GW2RegisterOutputMemory** function registers where the managed content is to be placed, and where to place the size in bytes of the managed content. A pointer to the managed file content will be placed in the object pointed to by **outputBuffer** and the size in bytes of the managed data will be placed in the **size_t** object pointed to by **outputLength**. The managed file content will be deleted when the session is closed using **GW2CloseSession**. Using this function activates the Manage and Protect Process Mode for the session.

```cpp
#include "glasswall.core2.api.h"
int GW2RegisterOutputMemory(Session session, char **outputBuffer, size_t *outputLength);
```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

**Example**

```cpp

#include "glasswall.core2.api.h"

HANDLE session = GW2OpenSession();
char *managed_content = NULL;
size_t size = 0;

if (!session)
    /* deal with error */
else
{
    if (GW2RegisterOutputMemory(session, &managed_content, &size) < 0)
        /* deal with error */
    else
        /* continue processing */
        ...
}

/* later */
if (GW2CloseSession(session) < 0)
    /* error closing session */
else
    /* managed file content has been deleted */

```

</TabItem>

<TabItem value="C#" label="C#">

**Synopsis**

```csharp
public int RegisterOutputMemory(
    int session,
    out IntPtr outputBufferPtr,
    ref UIntPtr outputBufferLengthPtr)

```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

<TabItem value="Java" label="Java">

**Synopsis**

```java
import com.glasswall.core2javabridge.*;

public int GW2RegisterOutputMemory(int session) throws GlasswallException
```

**Description**

The **GW2RegisterOutputMemory** function registers a memory buffer to be used as the output for the output file for the session specified by `session`. 

You will need to call **GetOutputBuffer** after having called **GW2RunSession** in order to retrieve the output file.

**Returns**

The **GW2RegisterOutputMemory** function returns a **GW2_RetStatus** enumeration converted to `int`. The value will be negative if an error occurred. `0` indicates success. Refer to the API Overview/Return types for details. 

A **GlasswallException** exception will be thrown if `session` is invalid.

**Synopsis - Retrieve Data**

```java
import com.glasswall.core2javabridge.*;

public byte[] GetOutputBuffer(int session) throws GlasswallException
```

**Description**

The GetOutputBuffer function retrieves the output buffer associated with the session specified by `session`.

**Returns**

The **GetOutputBuffer** function returns a `byte[]` containing the output file. This will be null if **GW2RegisterOutputMemory** and **GW2RunSession** have not been called, or if the file is non-conforming.

A **GlasswallException** exception will be thrown if `session` is invalid.

</TabItem>

<TabItem value="Python" label="Python">

**Synopsis**

Register an output file for the given session. If output_file is None the file will be returned as 'buffer' and
'buffer_length' attributes.

```py
def register_output(self, session, output_file: Optional[str] = None):
    """ Register an output file for the given session. If output_file is None the file will be returned as 'buffer' and 'buffer_length' attributes.

    Args:
        session (int): The session integer.
        output_file (Optional[str]): If specified, during run session the file will be written to output_file, otherwise the file will be written to the glasswall.GwReturnObj 'buffer' and 'buffer_length' attributes.

    Returns:
        gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attribute 'status' indicating the result of the function call. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.
    """
```

**Returns**

gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attribute 'status' indicating the result of the function call. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.

The status attribute is an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

<TabItem value="JavaScript" label="JavaScript">

**Synopsis**

This function registers where the managed content is to be placed, and where to place the size variable of the content.

```jsx

/**
 * @param {number} session The ID of the session.
 * @param {string} outputBuffer The specified output path. Must be different to the specified input file path.
 * @param {string} outputLength The size of the file buffer
 */

GW2RegisterOutputMemory(
    session,
    outputBuffer,
    outputLength)

```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

</Tabs>