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


The **GW2RegisterLicenceMemory** registers the licence file held in memory to a session.

If neither **GW2RegisterLicenceFile** or **GW2RegisterLicenceMemory** is registered with a session, the Editor will attempt to search for the licence in the default location. This is a file called gwkey.lic located in the same folder as the Editor library. If that cannot be found then the library will be considered unlicenced and some processes may fail with licence expiry issues.

<Tabs>

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

**Synopsis**

For session **session**, the **GW2RegisterLicenceMemory** function registers the licence to be used by Glasswall when processing files. **licenceContents** is a pointer to the licence data, **licenceLength** specifies the size in bytes of the licence data.

```cpp

    #include "glasswall.core2.api.h"
    int GW2RegisterLicenceMemory(Session session, 
                                 const char *licenceContents, 
                                 size_t licenceLength);
```

**Returns**

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

**Example**

```cpp

    #include "glasswall.core2.api.h"

    Session session = GW2OpenSession();
    char *licence = NULL;
    size_t size = 0;
    if (!session)
        /* deal with error */
    else
    {
        /* ... load 'licence' with a pointer to the licence content ... */
        if (GW2RegisterLicenceMemory(session, licence, size) < 0)
            /* deal with error */
        else
            /* continue processing */
    }

    . . .

    /* later */
    if (GW2CloseSession(session) < 0)
        /* error closing session */

```

</TabItem>

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

**Synopsis**

For session **session**, the **RegisterLicenceMemory** method registers the licence to be used by Glasswall when processing files.


```csharp
        /// <summary>
        /// Provide a licence to use for the session.
        /// </summary>
        /// <param name="session">Current open Glasswall session</param>
        /// <param name="licence">Byte content of the licence</param>
        public int RegisterLicenceMemory(int session, byte[] licence)
```

**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 GW2RegisterLicenceMemory(int session, byte[] licenceBuffer) throws GlasswallException, NullPointerException

public int GW2RegisterLicenceMemory(int session, byte[] licenceBuffer, int licenceLength) throws GlasswallException, NullPointerException
```

**Note**

The `length` of the `licenceBuffer` may optionally be specified.

**Returns**

The **GW2RegisterLicenceMemory** 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.

A **NullPointerException** exception will be thrown if `licenceBuffer` buffer is null or empty.

</TabItem>

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

Licence registration for each session is handled automatically in the Python wrapper, and it is not necessary for users to call `GW2RegisterLicenceFile` or `GW2RegisterLicenceMemory` manually.

By default, the `Editor` class expects a valid licence file to be located in the same directory as the `library_path`. You can also specify a different path to a `gwkey.lic` licence file using the `licence` argument.

```py
import glasswall


# Load the Glasswall Editor library with a specified licence file
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0", licence=r"C:\gwpw\licence\gwkey.lic")
```

Alternatively, you can pass the licence data in-memory as a bytes, bytearray, or io.BytesIO object.

```py
import glasswall


# Alternatively, load the licence from in-memory bytes or bytearray
with open(r"C:\gwpw\licence\gwkey.lic", "rb") as f:
    licence_data = f.read()

editor = glasswall.Editor(
    r"C:\gwpw\libraries\10.0", 
    licence=licence_data  # In-memory licence data
)
```

</TabItem>

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

**Synopsis**

For session **session**, the **GW2RegisterLicenceMemory** function registers the licence to be used by Glasswall when processing files. **licenceContents** is a pointer to the licence data, **licenceLength** specifies the size in bytes of the licence data.

```jsx

    /**
     * Provides the contents of the licence file that will be used for this session.
     * @param {number} session The ID of the session.
     * @param {string} licenceContents A pointer to the licence data buffer.
     * @param {number} licenceLength Length of the data in the licence buffer.
     * @returns {number} Status of the operation; 0 for success, non-zero for failure.
     */
    GW2RegisterLicenceMemory(session, licenceContents, licenceLength)
```

**Returns**

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

</TabItem>

</Tabs>