From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- ComLightLib/streams.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ComLightLib/streams.h (limited to 'ComLightLib/streams.h') diff --git a/ComLightLib/streams.h b/ComLightLib/streams.h new file mode 100644 index 0000000..87680e1 --- /dev/null +++ b/ComLightLib/streams.h @@ -0,0 +1,61 @@ +#pragma once +#include +#include "comLightCommon.h" + +// COM interfaces to marshal streams across the interop. +namespace ComLight +{ + enum struct eSeekOrigin : uint8_t + { + Begin = 0, + Current = 1, + End = 2 + }; + + namespace details + { + template + inline size_t sizeofVector( const std::vector& vec ) + { + return sizeof( E ) * vec.size(); + } + } + + // COM interface for readonly stream. You'll get these interfaces what you use [ReadStream] attribute in C#. + struct DECLSPEC_NOVTABLE iReadStream : public IUnknown + { + DEFINE_INTERFACE_ID( "006af6db-734e-4595-8c94-19304b2389ac" ); + + virtual HRESULT COMLIGHTCALL read( void* lpBuffer, int nNumberOfBytesToRead, int &lpNumberOfBytesRead ) = 0; + virtual HRESULT COMLIGHTCALL seek( int64_t offset, eSeekOrigin origin ) = 0; + virtual HRESULT COMLIGHTCALL getPosition( int64_t& position ) = 0; + virtual HRESULT COMLIGHTCALL getLength( int64_t& length ) = 0; + + template + inline HRESULT read( std::vector& vec ) + { + const int cb = (int)details::sizeofVector( vec ); + int cbRead = 0; + CHECK( read( vec.data(), cb, cbRead ) ); + if( cbRead >= cb ) + return S_OK; + return E_EOF; + } + }; + + // COM interface for readonly stream. You'll get these interfaces what you use [WriteStream] attribute in C#. + struct DECLSPEC_NOVTABLE iWriteStream : public IUnknown + { + DEFINE_INTERFACE_ID( "d7c3eb39-9170-43b9-ba98-2ea1f2fed8a8" ); + + virtual HRESULT COMLIGHTCALL write( const void* lpBuffer, int nNumberOfBytesToWrite ) = 0; + virtual HRESULT COMLIGHTCALL flush() = 0; + + template + inline HRESULT write( const std::vector& vec ) + { + const int cb = (int)details::sizeofVector( vec ); + return write( vec.data(), cb ); + } + }; +} \ No newline at end of file -- cgit v1.2.3