dll中的vector.h在我的应用中不可用
vector.h in dll not useable in my application
我是新来的...我的应用程序有问题。我写了一个DLL,其中使用了一个结构和矢量。在矢量中,我希望将我的结构实例放置。到目前为止,一切都很好。
在我的应用程序中导入的dll ist。现在,我想在应用程序中使用我的DLL的向量,但这不起作用。
我没有任何错误,我想做的是以这种方式在我的main(( - 应用程序中获取信息:
#include "lib.h"
#include <iostream>
int main()
{
char setData[4];
setData[0] = 0xBE;
setData[1] = 0x3E;
setData[2] = 0xB8;
setData[3] = 0x13;
getuseablePID(setData); //this function is in my dll and copies the information of my csv-Data to my vector
//here i want to know the size of my vector an want to print one element but this doesn't work
int a = globals::getInstance()._csvContent.size();
cout << globals::getInstance()._csvContent.PID;
return 0;
}
这是我的dll代码
#include <fstream>
#include <string>
#include <vector>
using namespace std;
#define EXPORT extern "C" __declspec(dllexport)
struct csvDatei_Para {
string PID;
string Beschreibung;
string Byteanzahl;
string Min;
string Max;
string Einheit;
string Wertetab;
};
struct globals {
static globals& getInstance()
{
static globals instance;
return instance;
}
std::vector<csvDatei_Para> _csvContent;
};
我也尝试过:
EXPORT struct globals {
static globals& getInstance()
{
static globals instance;
return instance;
}
std::vector<csvDatei_Para> _csvContent;
};
有人知道,为什么它不起作用并给我解决方案?
谢谢:(
请测试此代码:
#include <fstream>
#include <string>
#include <vector>
using namespace std;
#ifndef GUARD_DLLHDR_H
#define GUARD_DLLHDR_H
#if defined(BUILD_MY_DLL)
#define DLLSYM __declspec(dllexport)
#else
#define DLLSYM __declspec(dllimport)
#endif
#if defined(__cplusplus)
extern "C" {
#endif
struct csvDatei_Para
{
string PID;
string Beschreibung;
string Byteanzahl;
string Min;
string Max;
string Einheit;
string Wertetab;
};
struct globals {
static globals& getInstance()
{
static globals instance;
return instance;
}
std::vector<csvDatei_Para> _csvContent;
};
DLLSYM extern globals myGlobals;
#if defined(__cplusplus)
}
#endif
#endif
现在我有了解决方案。
我写了一个函数,该函数返回了全球实例。我可以使用此实例来获取我的结构的变量。
我的.h:
EXPORT struct globals getValues();
在我的.cpp中:
struct globals getValues(){
return globals::getInstance();
}
在我的应用程序中:
getValues()._csvContent.PID;
相关文章:
- 我的应用程序无法在安卓上使用OpenSSL进行链接
- 如何查询以确定我的 MacOS/X 应用程序是否处于应用程序午睡模式?
- 我的 c++ 应用程序中的运行时间从 0 增加到 60 太快了(例如一毫秒或一微秒)
- 设置我的应用程序 API 感知并防止系统使其模糊和错误定位
- 是否可以将不同的编译器嵌入到我的应用程序中?
- 即使在我关闭应用程序并重新启动它后,如何保持我的 ID 被阻止?
- 在我的应用逻辑中找不到错误
- 我的web应用程序的用户需要在浏览器上手动启用本机客户端吗
- 即使在我为我的应用程序授予管理员后也无法从 Windows 系统复制目录
- 计算有多少人执行我的C++应用程序
- Visual C++ wxWidgets应用程序仅适用于我的PC
- 为什么我的 C# 应用程序无法加载我的 C++ dll?
- 是否可以将 VBA 编程环境添加到我的C++应用程序?
- 从另一个应用启动我的应用时出现相对路径更改问题
- 指定在用户固定我的应用程序时用于运行应用程序的命令参数
- 如何在我的 Windows 应用程序中捕获按下和释放的 CTRL 键?
- 如何在关闭Qt控制台应用程序之前运行我的析构函数?
- 比较两个字符串数组,我的控制台应用程序"stops responding"
- LOCAL_SHARED_LIBRARIES使我的应用程序崩溃
- 为什么使用 nullPtr 调用函数不会使我的应用程序崩溃