diff --git a/wfassoc-cdylib/cbinding/wfassoc++.h b/wfassoc-cdylib/cbinding/wfassoc++.h index cbdc4ff..df91eeb 100644 --- a/wfassoc-cdylib/cbinding/wfassoc++.h +++ b/wfassoc-cdylib/cbinding/wfassoc++.h @@ -24,8 +24,16 @@ */ namespace wfassocpp { -/** @brief Type representing a null-terminated UTF-8 C-style string */ -using CString = wfassoc::WFCString; +/** @brief Type representing a pointer to a null-terminated UTF-8 C-style string */ +using StrPtr = wfassoc::WFStrPtr; +/** + * @brief Type representing an error code returned by FFI functions + * + * WFERROR_OK is the only value representing absolute success. + * Any other value's meaning is decided by this library, + * currently WFERROR_ERR represents a generic failure. + */ +using Error = wfassoc::WFError; /** * @brief Type representing a handle/token for managed objects * @@ -39,10 +47,12 @@ using Token = wfassoc::WFToken; * This type is equivalent to the Win32 HICON type. */ using HICON = wfassoc::WFHICON; +/** @brief Invalid token value used as a sentinel for no object */ +constexpr Token INVALID_TOKEN = wfassoc::WF_INVALID_TOKEN; /** @brief Invalid icon handle value */ -using INVALID_HICON = wfassoc::WF_INVALID_HICON; +constexpr HICON INVALID_HICON = wfassoc::WF_INVALID_HICON; /** @brief Invalid index value used for error conditions */ -using INVALID_INDEX = wfassoc::WF_INVALID_INDEX; +constexpr size_t INVALID_INDEX = wfassoc::WF_INVALID_INDEX; /** * @brief Registration scope for file associations * @@ -60,30 +70,15 @@ using View = wfassoc::WFView; * @private * @brief Check the result of a C API call and throw on failure * - * @param[in] result Boolean result from a C API call - * @throws std::runtime_error if result is false, with the error message from WFGetLastError() + * @param[in] result Error code returned from a C API call + * @throws std::runtime_error if result is not WFERROR_OK, with the error message from WFGetLastError() */ -inline void _Check(bool result) { - if (!result) { +inline void _Check(wfassoc::WFError result) { + if (result != wfassoc::WFERROR_OK) { throw std::runtime_error(wfassoc::WFGetLastError()); } } -/** - * @private - * @brief Get the invalid token value - * - * In theory, invalid token value should be a constant value. - * However, due to the library used in Rust side, this value can only be fetched at runtime. - * This function caches the value on first call for subsequent use. - * - * @return An invalid token value - */ -inline Token _INVALID_TOKEN() { - static Token v = wfassoc::WFInvalidToken(); - return v; -} - /** * @brief Schema object for defining a program's file association configuration * @@ -106,7 +101,7 @@ public: * Releases resources associated with the Schema object. */ ~Schema() { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFSchemaDestroy(_token); } } @@ -117,15 +112,15 @@ public: Schema& operator=(const Schema&) = delete; /** @brief Move constructor */ - Schema(Schema&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } + Schema(Schema&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; } /** @brief Move assignment operator */ Schema& operator=(Schema&& other) noexcept { if (this != &other) { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFSchemaDestroy(_token); } _token = other._token; - other._token = _INVALID_TOKEN(); + other._token = INVALID_TOKEN; } return *this; } @@ -240,7 +235,7 @@ private: */ Token Release() noexcept { Token t = _token; - _token = _INVALID_TOKEN(); + _token = INVALID_TOKEN; return t; } @@ -270,7 +265,7 @@ public: * Releases resources associated with the icon resource. */ ~IconRc() { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFIconRcDestroy(_token); } } @@ -281,15 +276,15 @@ public: IconRc& operator=(const IconRc&) = delete; /** @brief Move constructor */ - IconRc(IconRc&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } + IconRc(IconRc&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; } /** @brief Move assignment operator */ IconRc& operator=(IconRc&& other) noexcept { if (this != &other) { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFIconRcDestroy(_token); } _token = other._token; - other._token = _INVALID_TOKEN(); + other._token = INVALID_TOKEN; } return *this; } @@ -334,7 +329,7 @@ public: * Releases resources associated with the extension status. */ ~ExtStatus() { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFExtStatusDestroy(_token); } } @@ -345,15 +340,15 @@ public: ExtStatus& operator=(const ExtStatus&) = delete; /** @brief Move constructor */ - ExtStatus(ExtStatus&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } + ExtStatus(ExtStatus&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; } /** @brief Move assignment operator */ ExtStatus& operator=(ExtStatus&& other) noexcept { if (this != &other) { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFExtStatusDestroy(_token); } _token = other._token; - other._token = _INVALID_TOKEN(); + other._token = INVALID_TOKEN; } return *this; } @@ -415,7 +410,7 @@ public: * Releases resources associated with the self extension status. */ ~SelfExtStatus() { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFSelfExtStatusDestroy(_token); } } @@ -426,15 +421,15 @@ public: SelfExtStatus& operator=(const SelfExtStatus&) = delete; /** @brief Move constructor */ - SelfExtStatus(SelfExtStatus&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } + SelfExtStatus(SelfExtStatus&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; } /** @brief Move assignment operator */ SelfExtStatus& operator=(SelfExtStatus&& other) noexcept { if (this != &other) { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFSelfExtStatusDestroy(_token); } _token = other._token; - other._token = _INVALID_TOKEN(); + other._token = INVALID_TOKEN; } return *this; } @@ -525,7 +520,7 @@ public: * Releases resources associated with the Program. */ ~Program() { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFProgramDestroy(_token); } } @@ -536,15 +531,15 @@ public: Program& operator=(const Program&) = delete; /** @brief Move constructor */ - Program(Program&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } + Program(Program&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; } /** @brief Move assignment operator */ Program& operator=(Program&& other) noexcept { if (this != &other) { - if (_token != _INVALID_TOKEN()) { + if (_token != INVALID_TOKEN) { wfassoc::WFProgramDestroy(_token); } _token = other._token; - other._token = _INVALID_TOKEN(); + other._token = INVALID_TOKEN; } return *this; } @@ -576,7 +571,7 @@ public: * @throws std::runtime_error if the operation fails */ IconRc ResolveIcon() { - Token token = _INVALID_TOKEN(); + Token token = INVALID_TOKEN; _Check(wfassoc::WFProgramResolveIcon(_token, &token)); return IconRc(token); } @@ -614,7 +609,7 @@ public: * @throws std::runtime_error if the operation fails */ SelfExtStatus ResolveExt(size_t index) { - Token token = _INVALID_TOKEN(); + Token token = INVALID_TOKEN; _Check(wfassoc::WFProgramResolveExt(_token, index, &token)); return SelfExtStatus(token); } @@ -676,9 +671,9 @@ public: * @throws std::runtime_error if the operation fails */ std::optional QueryExt(View view, size_t index) { - Token token = _INVALID_TOKEN(); + Token token = INVALID_TOKEN; _Check(wfassoc::WFProgramQueryExt(_token, view, index, &token)); - if (token == _INVALID_TOKEN()) { + if (token == INVALID_TOKEN) { return std::nullopt; } return ExtStatus(token); diff --git a/wfassoc-cdylib/cbinding/wfassoc.h b/wfassoc-cdylib/cbinding/wfassoc.h index 13f2ae4..246698c 100644 --- a/wfassoc-cdylib/cbinding/wfassoc.h +++ b/wfassoc-cdylib/cbinding/wfassoc.h @@ -34,7 +34,15 @@ namespace wfassoc { #ifdef __cplusplus /** Type representing a null-terminated UTF-8 C-style string */ -using WFCString = const char*; +using WFStrPtr = const char*; +/** + * @brief Type representing an error code returned by FFI functions + * + * WFERROR_OK is the only value representing absolute success. + * Any other value's meaning is decided by this library, + * currently WFERROR_ERR represents a generic failure. + */ +using WFError = uint32_t; /** * @brief Type representing a handle/token for managed objects * @@ -49,18 +57,28 @@ using WFToken = uint64_t; */ using WFHICON = void*; #else // __cplusplus -typedef const char *WFCString; +typedef const char *WFStrPtr; +typedef uint32_t WFError; typedef uint64_t WFToken; typedef void *WFHICON; #endif // __cplusplus #ifdef __cplusplus +/** The error code representing absolute success. */ +constexpr WFError WFERROR_OK = 0u; +/** The error code representing a generic failure. */ +constexpr WFError WFERROR_ERR = 1u; +/** Invalid token value used as a sentinel for no object */ +constexpr WFToken WF_INVALID_TOKEN = 0u; /** Invalid icon handle value */ constexpr WFHICON WF_INVALID_HICON = nullptr; /** Invalid index value used for error conditions */ constexpr size_t WF_INVALID_INDEX = static_cast(-1); #else // __cplusplus +static const WFError WFERROR_OK = 0u; +static const WFError WFERROR_ERR = 1u; +static const WFToken WF_INVALID_TOKEN = 0u; static const WFHICON WF_INVALID_HICON = NULL; static const size_t WF_INVALID_INDEX = ((size_t)-1); #endif // __cplusplus @@ -111,25 +129,6 @@ static const WFView WF_VIEW_HYBRID = 2u; extern "C" { #endif // __cplusplus -/** - * @brief Initialize the wfassoc library - * - * This function must be called before using the MOST of any other wfassoc functions. - * - * @return true on success, false on failure. - */ -bool WFStartup(void); - -/** - * @brief Shutdown the wfassoc library - * - * Cleans up all allocated resources and object pools. - * Should be called when done using the library. - * - * @return true on success, false on failure. - */ -bool WFShutdown(void); - /** * @brief Get the last error message * @@ -137,46 +136,25 @@ bool WFShutdown(void); * The returned error message string is valid until the next API call. * * For most functions located in this library, except some special function indicated in their notes, - * they return boolean value indicating whether function is successful or not. + * they return WFERROR_OK when the function is successful, and WFERROR_ERR when the function is failed. * Once they fail, you can call this function to get a human-readable error message. * - * The execution of this function do not need to be wrapped by WFStartup() and WFShutdown(). - * * The string this function return use different buffer with function return string value. - * So you don't worry about that calling this function may invalidate function function return string value. + * So you don't worry about that calling this function may invalidate function return string value. * * @return Null-terminated UTF-8 string containing the error message. * If no error has occurred, the string is empty. * There is no possibility of a NULL return value. */ -WFCString WFGetLastError(void); +WFStrPtr WFGetLastError(void); /** * @brief Check if the current process has administrative privileges * - * This function will not throw any error. - * There is no necessity to call WFGetLastError() after this function. - * The return value only indicates whether the current process has administrative privileges or not. - * - * The execution of this function do not need to be wrapped by WFStartup() and WFShutdown(). - * - * @return true if running with admin privileges, false otherwise + * @param[out] out_has Pointer to receive whether the current process has administrative privileges. + * @return WFERROR_OK on success, WFERROR_ERR on failure. */ -bool WFHasPrivilege(void); - -/** - * @brief Get an invalid token value - * - * In theory, invalid token value should be a constant value. - * However, due to the library I used in Rust side, this value only can be fetched at runtime. - * So I expose this function to make programmer can fetch this constant value. - * Theoretically, you just need to fetch this function only once at the beginning of your program. - * - * The execution of this function do not need to be wrapped by WFStartup() and WFShutdown(). - * - * @return An invalid token value - */ -WFToken WFInvalidWFToken(void); +WFError WFHasPrivilege(bool *out_has); /** * @brief Create a new Schema object @@ -189,9 +167,9 @@ WFToken WFInvalidWFToken(void); * The receiver take the ownership of this Schema object. * And it should be freed by calling WFSchemaDestroy() when it is no longer needed, * or consumed by creating a Program object via WFProgramCreate(). - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaCreate(WFToken *out_schema); +WFError WFSchemaCreate(WFToken *out_schema); /** * @brief Destroy a Schema object @@ -202,9 +180,9 @@ bool WFSchemaCreate(WFToken *out_schema); * because the convertion function from Schema to Program will consume given Schema object to produce Program object. * * @param[in] in_schema Schema token to destroy - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaDestroy(WFToken in_schema); +WFError WFSchemaDestroy(WFToken in_schema); /** * @brief Set the program identifier for a Schema @@ -213,9 +191,9 @@ bool WFSchemaDestroy(WFToken in_schema); * @param[in] in_value Null-terminated UTF-8 string containing the identifier. * This identifier should not be empty, must start with alphabet character, * and follow with alphabet characters, digits, underline, or hyphens. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaSetIdentifier(WFToken in_schema, WFCString in_value); +WFError WFSchemaSetIdentifier(WFToken in_schema, WFStrPtr in_value); /** * @brief Set the program path for a Schema @@ -223,9 +201,9 @@ bool WFSchemaSetIdentifier(WFToken in_schema, WFCString in_value); * @param[in] in_schema Schema token * @param[in] in_value Null-terminated UTF-8 string containing the program path. * This path should be the fully qualified path to the application. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaSetPath(WFToken in_schema, WFCString in_value); +WFError WFSchemaSetPath(WFToken in_schema, WFStrPtr in_value); /** * @brief Set the program CLSID for a Schema @@ -234,36 +212,36 @@ bool WFSchemaSetPath(WFToken in_schema, WFCString in_value); * @param[in] in_value Null-terminated UTF-8 string containing the CLSID. * This CLSID string should be in the format of @c {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} . * Please note that curly braces are required. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaSetClsid(WFToken in_schema, WFCString in_value); +WFError WFSchemaSetClsid(WFToken in_schema, WFStrPtr in_value); /** * @brief Set the program name for a Schema (optional) * * @param[in] in_schema Schema token * @param[in] in_value Null-terminated UTF-8 string containing the name, or NULL to clear - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaSetName(WFToken in_schema, WFCString in_value); +WFError WFSchemaSetName(WFToken in_schema, WFStrPtr in_value); /** * @brief Set the program icon for a Schema (optional) * * @param[in] in_schema Schema token * @param[in] in_value Null-terminated UTF-8 string containing the icon path, or NULL to clear - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaSetIcon(WFToken in_schema, WFCString in_value); +WFError WFSchemaSetIcon(WFToken in_schema, WFStrPtr in_value); /** * @brief Set the program behavior for a Schema (optional) * * @param[in] in_schema Schema token * @param[in] in_value Null-terminated UTF-8 string containing the behavior command, or NULL to clear - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaSetBehavior(WFToken in_schema, WFCString in_value); +WFError WFSchemaSetBehavior(WFToken in_schema, WFStrPtr in_value); /** * @brief Add a string resource entry to a Schema @@ -272,9 +250,9 @@ bool WFSchemaSetBehavior(WFToken in_schema, WFCString in_value); * @param[in] in_name Null-terminated UTF-8 string containing the name of this entry * @param[in] in_value Null-terminated UTF-8 string containing the value of this entry. * It can be a plain string or a reference string to resource. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaAddStr(WFToken in_schema, WFCString in_name, WFCString in_value); +WFError WFSchemaAddStr(WFToken in_schema, WFStrPtr in_name, WFStrPtr in_value); /** * @brief Add an icon registry entry to a Schema @@ -283,9 +261,9 @@ bool WFSchemaAddStr(WFToken in_schema, WFCString in_name, WFCString in_value); * @param[in] in_name Null-terminated UTF-8 string containing the name of this entry * @param[in] in_value Null-terminated UTF-8 string containing the value of this entry. * It can be a path to icon or a reference string to resource. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaAddIcon(WFToken in_schema, WFCString in_name, WFCString in_value); +WFError WFSchemaAddIcon(WFToken in_schema, WFStrPtr in_name, WFStrPtr in_value); /** * @brief Add a behavior registry entry to a Schema @@ -294,9 +272,9 @@ bool WFSchemaAddIcon(WFToken in_schema, WFCString in_name, WFCString in_value); * @param[in] in_name Null-terminated UTF-8 string containing the name of this entry * @param[in] in_value Null-terminated UTF-8 string containing the value of this entry. * It should be a valid command line string which use \c %1, \c %2, etc. to represent parameters. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaAddBehavior(WFToken in_schema, WFCString in_name, WFCString in_value); +WFError WFSchemaAddBehavior(WFToken in_schema, WFStrPtr in_name, WFStrPtr in_value); /** * @brief Add a file extension to a Schema @@ -309,13 +287,13 @@ bool WFSchemaAddBehavior(WFToken in_schema, WFCString in_name, WFCString in_valu * This name should be registered by calling WFSchemaAddIcon(). * @param[in] in_ext_behavior Null-terminated UTF-8 string containing the name pointing to associated behavior for this extension. * This name should be registered by calling WFSchemaAddBehavior(). - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSchemaAddExt(WFToken in_schema, - WFCString in_ext, - WFCString in_ext_name, - WFCString in_ext_icon, - WFCString in_ext_behavior); +WFError WFSchemaAddExt(WFToken in_schema, + WFStrPtr in_ext, + WFStrPtr in_ext_name, + WFStrPtr in_ext_icon, + WFStrPtr in_ext_behavior); /** * @brief Create a Program object from a Schema @@ -331,9 +309,9 @@ bool WFSchemaAddExt(WFToken in_schema, * @param[out] out_program Pointer to receive the Program token. * The receiver take the ownership of this Program object. * And it should be freed by calling WFProgramDestroy() when it is no longer needed. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramCreate(WFToken in_schema, WFToken *out_program); +WFError WFProgramCreate(WFToken in_schema, WFToken *out_program); /** * @brief Destroy a Program object @@ -341,9 +319,9 @@ bool WFProgramCreate(WFToken in_schema, WFToken *out_program); * Releases resources associated with the Program. * * @param[in] in_program Program token to destroy - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramDestroy(WFToken in_program); +WFError WFProgramDestroy(WFToken in_program); /** * @brief Resolve the provided program name of this Program @@ -356,9 +334,9 @@ bool WFProgramDestroy(WFToken in_program); * @param[out] out_name Pointer to receive the resolved name. * There is no possibility that this value is NULL. * This string will be freed at the next API call. Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramResolveName(WFToken in_program, WFCString *out_name); +WFError WFProgramResolveName(WFToken in_program, WFStrPtr *out_name); /** * @brief Resolve the Program icon resource @@ -371,18 +349,18 @@ bool WFProgramResolveName(WFToken in_program, WFCString *out_name); * @param[out] out_icon_rc Pointer to receive the icon resource token. * The caller take the ownership of created icon resource object. * And it should be freed by calling WFIconRcDestroy() when it is no longer needed. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramResolveIcon(WFToken in_program, WFToken *out_icon_rc); +WFError WFProgramResolveIcon(WFToken in_program, WFToken *out_icon_rc); /** * @brief Get the number of file extensions in the Program * * @param[in] in_program Program token * @param[out] out_len Pointer to receive the number of extensions - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramExtsLen(WFToken in_program, size_t *out_len); +WFError WFProgramExtsLen(WFToken in_program, size_t *out_len); /** * @brief Find a file extension by its body (extension string) @@ -390,9 +368,9 @@ bool WFProgramExtsLen(WFToken in_program, size_t *out_len); * @param[in] in_program Program token * @param[in] in_body Null-terminated UTF-8 string containing the file extension name (without leading dot) to find. * @param[out] out_index Pointer to receive the file extension index, or WF_INVALID_INDEX if not found. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramFindExt(WFToken in_program, WFCString in_body, size_t *out_index); +WFError WFProgramFindExt(WFToken in_program, WFStrPtr in_body, size_t *out_index); /** * @brief Resolve this program provided extension's details by index @@ -402,27 +380,27 @@ bool WFProgramFindExt(WFToken in_program, WFCString in_body, size_t *out_index); * @param[out] out_self_ext_status Pointer to receive the self extension status token. * The caller take the ownership of created self extension status object. * And it should be freed by calling WFSelfExtStatusDestroy() when it is no longer needed. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramResolveExt(WFToken in_program, size_t in_index, WFToken *out_self_ext_status); +WFError WFProgramResolveExt(WFToken in_program, size_t in_index, WFToken *out_self_ext_status); /** * @brief Register the Program in the specified scope * * @param[in] in_program Program token * @param[in] in_scope Registration scope - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramRegister(WFToken in_program, WFScope in_scope); +WFError WFProgramRegister(WFToken in_program, WFScope in_scope); /** * @brief Unregister the Program from the specified scope * * @param[in] in_program Program token * @param[in] in_scope Registration scope - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramUnregister(WFToken in_program, WFScope in_scope); +WFError WFProgramUnregister(WFToken in_program, WFScope in_scope); /** * @brief Check if the Program is registered in the specified scope @@ -431,9 +409,9 @@ bool WFProgramUnregister(WFToken in_program, WFScope in_scope); * @param[in] in_scope Registration scope for checking * @param[out] out_is_registered Pointer to receive the registration status. * True if the Program is registered in the specified scope, false otherwise. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramIsRegistered(WFToken in_program, WFScope in_scope, bool *out_is_registered); +WFError WFProgramIsRegistered(WFToken in_program, WFScope in_scope, bool *out_is_registered); /** * @brief Link a file extension in the specified scope @@ -441,9 +419,9 @@ bool WFProgramIsRegistered(WFToken in_program, WFScope in_scope, bool *out_is_re * @param[in] in_program Program token * @param[in] in_scope Registration scope * @param[in] in_index Index of the extension to link - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramLinkExt(WFToken in_program, WFScope in_scope, size_t in_index); +WFError WFProgramLinkExt(WFToken in_program, WFScope in_scope, size_t in_index); /** * @brief Unlink a file extension in the specified scope @@ -451,9 +429,9 @@ bool WFProgramLinkExt(WFToken in_program, WFScope in_scope, size_t in_index); * @param[in] in_program Program token * @param[in] in_scope Registration scope * @param[in] in_index Index of the extension to unlink - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramUnlinkExt(WFToken in_program, WFScope in_scope, size_t in_index); +WFError WFProgramUnlinkExt(WFToken in_program, WFScope in_scope, size_t in_index); /** * @brief Query the status of a file extension @@ -461,21 +439,21 @@ bool WFProgramUnlinkExt(WFToken in_program, WFScope in_scope, size_t in_index); * @param[in] in_program Program token * @param[in] in_view View viewpoint. * @param[in] in_index Index of the extension to query - * @param[out] out_ext_status Pointer to receive the extension status token, or invalid token if not found. + * @param[out] out_ext_status Pointer to receive the extension status token, or WF_INVALID_TOKEN if not found. * If the extension is not found, it usually means that this extension is not registered in the specified scope. * The caller take the ownership of created extension status object. * And it should be freed by calling WFExtStatusDestroy() when it is no longer needed. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFProgramQueryExt(WFToken in_program, WFView in_view, size_t in_index, WFToken *out_ext_status); +WFError WFProgramQueryExt(WFToken in_program, WFView in_view, size_t in_index, WFToken *out_ext_status); /** * @brief Destroy an extension status object * * @param[in] in_ext_status Extension status token to destroy - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFExtStatusDestroy(WFToken in_ext_status); +WFError WFExtStatusDestroy(WFToken in_ext_status); /** * @brief Get the display name from an extension status object @@ -488,9 +466,9 @@ bool WFExtStatusDestroy(WFToken in_ext_status); * There is no possibility that this value is NULL. * We will try to use localized name first, then use raw ProgId name if localized name is not available. * This string will be freed at the next API call. Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFExtStatusGetName(WFToken in_ext_status, WFCString *out_name); +WFError WFExtStatusGetName(WFToken in_ext_status, WFStrPtr *out_name); /** * @brief Get the icon from an extension status object @@ -502,17 +480,17 @@ bool WFExtStatusGetName(WFToken in_ext_status, WFCString *out_name); * @param[out] out_icon Pointer to receive the icon handle. * This icon handle will be freed once this icon resource object is destroyed. * Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFExtStatusGetIcon(WFToken in_ext_status, WFHICON *out_icon); +WFError WFExtStatusGetIcon(WFToken in_ext_status, WFHICON *out_icon); /** * @brief Destroy a self extension status object * * @param[in] in_self_ext_status Self extension status token to destroy - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSelfExtStatusDestroy(WFToken in_self_ext_status); +WFError WFSelfExtStatusDestroy(WFToken in_self_ext_status); /** * @brief Get the display name from a self extension status object @@ -524,9 +502,9 @@ bool WFSelfExtStatusDestroy(WFToken in_self_ext_status); * @param[out] out_name Pointer to receive the name string. * There is no possibility that this value is NULL. * This string will be freed at the next API call. Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSelfExtStatusGetName(WFToken in_self_ext_status, WFCString *out_name); +WFError WFSelfExtStatusGetName(WFToken in_self_ext_status, WFStrPtr *out_name); /** * @brief Get the icon from a self extension status object @@ -538,9 +516,9 @@ bool WFSelfExtStatusGetName(WFToken in_self_ext_status, WFCString *out_name); * @param[out] out_icon Pointer to receive the icon handle. * This icon handle will be freed once this self extension status object is destroyed. * Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSelfExtStatusGetIcon(WFToken in_self_ext_status, WFHICON *out_icon); +WFError WFSelfExtStatusGetIcon(WFToken in_self_ext_status, WFHICON *out_icon); /** * @brief Get the extension string (without leading dot) from a self extension status object @@ -549,9 +527,9 @@ bool WFSelfExtStatusGetIcon(WFToken in_self_ext_status, WFHICON *out_icon); * @param[out] out_inner Pointer to receive the file extension name (without leading dot). * There is no possibility that this value is NULL. * This string will be freed at the next API call. Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSelfExtStatusGetExt(WFToken in_self_ext_status, WFCString *out_inner); +WFError WFSelfExtStatusGetExt(WFToken in_self_ext_status, WFStrPtr *out_inner); /** * @brief Get the dotted extension string (with leading dot) from a self extension status object @@ -560,17 +538,17 @@ bool WFSelfExtStatusGetExt(WFToken in_self_ext_status, WFCString *out_inner); * @param[out] out_inner Pointer to receive the file extension string (with leading dot). * There is no possibility that this value is NULL. * This string will be freed at the next API call. Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFSelfExtStatusGetDottedExt(WFToken in_self_ext_status, WFCString *out_inner); +WFError WFSelfExtStatusGetDottedExt(WFToken in_self_ext_status, WFStrPtr *out_inner); /** * @brief Destroy an icon resource object * * @param[in] in_icon_rc Icon resource token to destroy - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFIconRcDestroy(WFToken in_icon_rc); +WFError WFIconRcDestroy(WFToken in_icon_rc); /** * @brief Get the icon handle from an icon resource object @@ -580,9 +558,9 @@ bool WFIconRcDestroy(WFToken in_icon_rc); * There is no possibility that this value is WF_INVALID_HICON. * This icon handle will be freed once this icon resource object is destroyed. * Please make a copy immediately if you need to use it longer. - * @return true on success, false on failure + * @return WFERROR_OK on success, WFERROR_ERR on failure */ -bool WFIconRcGetIcon(WFToken in_icon_rc, WFHICON *out_icon); +WFError WFIconRcGetIcon(WFToken in_icon_rc, WFHICON *out_icon); #ifdef __cplusplus } // extern "C"