c++ - 将嵌套结构变量从 C++ 传递到 C++ dll 会导致 (L"Buffer is too small"&& 0)

标签 c++ dll

我有结构

NewStruct1
{
  uint factor;
  NewStruct2 assert[3];
  char name[21];

}

还有一个

NewStruct2 
{
  uint newFactor;
  char newName[21];
}

这里我在dll中调用了一个函数'func',如下所示

NewStruct1 var;

func(&var);

函数是

func(NewStruct1 *v)
{
  std::string myName = "werttt";
  strcpy_s(v->assert[0].newName, myName.size(), myName.c_str());
}

这样做时 strcpy_s 给出 (L"Buffer is too small"&& 0) 即使有足够的空间容纳。任何人都可以帮我解决这个问题吗?

最佳答案

strcpy_s 的第二个参数必须是 destination 中的元素数,即 21(newName 中的字符数),不是源的长度。

关于c++ - 将嵌套结构变量从 C++ 传递到 C++ dll 会导致 (L"Buffer is too small"&& 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11753939/

相关文章:

c# - 访问冲突异常 : Attempted to read/write protected memory

c++ 每 5 分钟调用一次函数

c++ - DownloadManager 对 vtable 的 undefined reference

c++ - 在 C++ 中使用 map() 时出错

Python Ctypes 异常 : access violation reading

mysql - AutoHotKey 无法从目录加载 libmySQL.dll

c++ - 为什么 while 循环从不执行?

c++ - OpenCV 标识符 "Tracker"未定义

visual-studio - 为什么我的智能设备应用程序会创建 *.asmmeta.dll 文件?

python - Python C 扩展的 DLL 文件的兼容性