首页 > 解决方案 > 变量在 C++ DLL 中被垃圾收集

问题描述

我目前正在尝试使用此文档页面将AzureStorageCPP集成到 Unreal Engine 4 中。我正在做的是围绕 AzureStorageCPP 创建一个自定义 C++ DLL 包装器,然后在 Unreal Code 中使用 Unreal Link 这个 DLL。

我通过 vcpkg 将 AzureStorageCPP 安装为 DLL。完成后,wastorage.dll 是需要链接的重要 DLL 之一。

我围绕 AzureStorageCPP 编写的 C++ DLL 包装器如下:

#include "was/storage_account.h"
#include "was/blob.h"

void UploadFileToAzure(char* FileName)
{
    azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(U("DefaultEndpointsProtocol=https;AccountName=test;AccountKey=test"));

}

据我所知,azure::storage::cloud_storage_account::parse存在于wastorage.dll

问题是当这个解析代码作为 C++ 控制台执行时,它运行得很好。ConnectionString 正确地通过调用堆栈传递给wastorage.dll,并且连接字符串不是垃圾。

这是上面代码中调用堆栈下一层的视图。

图片

但是,如果我将代码放入我制作的名为 AzureStorage.DLL 的 C++ 包装 DLL 中,将其链接到 Unreal,然后从那里调用,使用相同的调用堆栈,当字符串被传递到 wastorage.dll 进行解析时,它就会变成垃圾。

图片 图片

我认为这可能与这个问题有关,但我仍然不明白如何解决这个问题,因为我不控制来自 AzureStorage 的 Parse 方法。

以下是我创建 C++ DLL 包装头的方法,源代码已在上面显示:

AzureStorage.h

#pragma once

#define AZURESTORAGEDLL_API _declspec(dllexport)

#ifdef __cplusplus      //if C++ is used convert it to C to prevent C++'s name mangling of method names
extern "C"
{
#endif

    void AZURESTORAGEDLL_API UploadFileToAzure(char* FileName);

#ifdef __cplusplus
}
#endif

标签: c++dllunreal-engine4

解决方案


推荐阅读