c++ - 变量在 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
解决方案
推荐阅读
- asp.net - 如何清除 asp listview 中的数据表?
- pointers - spaCy在自定义组件中添加指向另一个令牌的指针
- origen-sdk - Origen test_ids next in range 接受 Proc/Lambda?
- sql-server - 如果不存在则插入以避免竞争条件
- php - 停止在 magento 中拆分订单的多重发货
- dart - 捕捉嵌套异步方法的错误
- c# - 基于另一个列值的唯一 id 集合的 Linq 查询
- c++ - nan 输出由于 maclaurin 系列正弦扩展,控制台崩溃
- oauth-2.0 - OAuth2:究竟什么是“客户端”
- firebase - EmberFire 关系持久性