private static void checkError(ErrorCodeT code)
 {
     if (code != ErrorCodeT.NoError)
     {
         throw new Exception(String.Format("Error code = '{0}'", code));
     }
 }
    public globalmq.marshalling.SimpleBuffer tryGetNextMessage()
    {
        int        size    = 0;
        ErrorCodeT retCode = getNextMessageSize(handle, out size);

        checkError(retCode); // throws in case of retCode != 0

        if (size == 0)
        {
            return(null);
        }

        byte[] arr         = new byte[size];
        int    bytesCopied = 0;

        retCode = getNextMessage(handle, arr, size, out bytesCopied);
        checkError(retCode); // throws in case of retCode != 0

        Debug.Assert(bytesCopied == size);

        globalmq.marshalling.SimpleBuffer sb = new SimpleBuffer();
        sb.setInternalBuffer(arr, size);

        return(sb);
    }
    public static DllTransport getThreadTransport()
    {
        UIntPtr    handle_ = UIntPtr.Zero;
        ErrorCodeT retCode = getThisThreadCommMeans(out handle_);

        checkError(retCode); // throws in case of retCode != 0

        return(new DllTransport(handle_));
    }
 private static void checkError(ErrorCodeT code)
 {
     if (code != ErrorCodeT.NoError)
     {
         string msg = string.Format("Error code = '{}'", code);
         Debug.Print(msg);
         throw new Exception(msg);
     }
 }
    public virtual void postMessage(globalmq.marshalling.BufferT buff)
    {
        int sz = buff.size();

        byte[] arr;
        globalmq.marshalling.SimpleBuffer sb = buff as globalmq.marshalling.SimpleBuffer;
        if (sb == null)
        {
            throw new Exception(String.Format("Unsupported buffer type '{0}'", buff.GetType()));
        }

        arr = sb.getInternalBuffer();

        ErrorCodeT retCode = postMessage(handle, arr, sz);

        checkError(retCode); // throws in case of retCode != 0
    }
    public void getNextMessage(Byte[] buff, out Int32 bytesCopied)
    {
        ErrorCodeT retCode = getNextMessage(handle, buff, buff.Length, out bytesCopied);

        checkError(retCode); // throws in case of retCode != 0
    }
    public void getNextMessageSize(out Int32 sz)
    {
        ErrorCodeT retCode = getNextMessageSize(handle, out sz);

        checkError(retCode); // throws in case of retCode != 0
    }