主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

matlab::cpplib::initMATLABLibraryAsync

异步初始化 MATLAB 函数库

描述

FutureResult<std::shared_ptr<MATLABLib>> initMATLABLibraryAsync(MATLABApplication & application, const std::u16string & ctfPath)

FutureResult<std::shared_ptr<MATLABLib>> initMATLABLibraryAsync(MATLABApplication & application, const std::u16string & ctfPath, const std::u16string& session_key = std::u16string())

异步初始化 MATLAB® 函数库,以便在初始化完成后获取指向新初始化的 C++ 共享库的指针。

或者,您可以指定十六进制编码的 64 字节 AES 解密密钥的附加参量,这允许您在运行时使用 C++ API 而不是 MEX 加载程序解密库。

参数

MATLABApplication & application

initMATLABApplication 返回的 MATLAB 应用程序对象。

const std::u16string & ctfPath

库的名称。如果省略路径,则假定它位于当前文件夹中。有关如何使用 ctfPath 的信息,请参阅matlab::cpplib::initMATLAB 库

const std::u16string& session_key = std::u16string()

AES 解密密钥,指定为具有 64 字节文件大小的十六进制编码 AES 密钥。

有关详细信息,请参阅 mcc -k

返回值

FutureResult<std::shared_ptr<MATLABLib>>

std::future 可以从中获取初始化过程的状态或库指针(一旦初始化完成)。

异常

matlab::cpplib::LibNotFound

在共享库路径上未找到具有给定名称的库。

matlab::cpplib::LibInitErr

无法初始化库。

示例

异步初始化 MATLABLibrary,并等待其初始化

auto future = mc::initMatlabLibraryAsync(matlabApplication, 
  mc::convertUTF8StringToUTF16String("libdoubleasync.ctf"));
if (!future.valid()) {
    throw std::future_error(std::future_errc::no_state);
}
std::future_status status;
do {
    status = future.wait_for(std::chrono::milliseconds(200));
    if (status == std::future_status::timeout) {
        std::cout << "Library initialization is in progress.\n";
    } else if (status == std::future_status::ready) {
        std::cout << "Library initialization has completed.\n";
    }
    std::this_thread::sleep_for(std::chrono::seconds(1));
} while (status != std::future_status::ready);
auto lib = future.get();

版本历史记录

在 R2018a 中推出