C ++ DLL返回指针到std :: list< std :: wstring> [英] C++ DLL returning pointer to std::list<std::wstring>

查看:244
本文介绍了C ++ DLL返回指针到std :: list< std :: wstring>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dll与以下原型:

I got a dll with the following prototype:

DLL_EXPORT std::list<std::wstring>* c_ExplodeWStringToList(std::wstring in_delimiter, std::wstring in_string, int in_limit);

应用程序使用这样:

std::list<std::wstring>* exploded = mydllclass->c_ExplodeWStringToList(L" ", in_command.c_str(), 0);

这在XP 32下工作得很好,但是当我在Vista中使用我的程序时,关闭自己。没有错误,没有警告?

This works great under XP 32, but when I try this at home with my Vista 64 my program just closes itself. No error and no warning?

有些天前,DLL直接返回列表 - 没有指针。但我切换到VC ++ 2010 Express,我无法编译我的DLL没有这个修改。

Some days ago the DLL was returning the list directly - no pointer. But I switched to VC++ 2010 Express, and I could not compile my DLL without this modification.

我没有看到这里吗?

谢谢:)

更新:

DLL_EXPORT std::list<std::wstring>* c_ExplodeWStringToList(std::wstring in_delimiter, std::wstring in_string, int in_limit)
{
 std::list<std::wstring>* returnlist = new std::list<std::wstring>();
 std::list<std::wstring>* stringlist = new std::list<std::wstring>();
 UINT pos = 0;

 while(true)
 {
      pos = in_string.find(in_delimiter, 0);

      if(pos == std::string::npos)
      {

           stringlist->push_back(in_string.substr(0, pos));
           break;
      }
      else
      {

           stringlist->push_back(in_string.substr(0, pos));
           in_string = in_string.substr(pos + in_delimiter.length());
      }
 }

 // ****
// Here is missing some code I've commented out while searching for the error.
 // ****
returnlist = stringlist;

return returnlist;
}

T

推荐答案

我没有深入的代码,但我得到一个结论,关于使用DLLs是不返回任何东西,但原始类型从DLL函数。这是因为由于不同的编译器或不同的开关或项目设置结构和类不对齐,相同的在DLL和调用DLL的代码中不具有相同的大小。

I didn't dig into the code, but a conclusion I came to regarding working with DLLs is to not return anything but primitive types from DLL functions. This is because due to different compilers or different switches or project settings structs and classes are not aligned the same not have the same size in the DLL and in the code calling the DLL.

因此,从调用程序中返回DLL中的列表可能被认为格式错误。

So returning a list from a DLL might be considered malformed in the caller application.

因此,最好只导出返回基本类型的C函数(表示错误代码)。

So, best is export only C functions that return primitive types (to denote error codes).

这篇关于C ++ DLL返回指针到std :: list&lt; std :: wstring&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆