HELP: Passing std::list to a DLL 
Author Message
 HELP: Passing std::list to a DLL

Hi,

I have some difficulties when passing a std::list container in a
method. The class resides in a DLL. Everything works fine except
when the program exists, it results in a failed assertion in dbgheap.c.
Expression: _CrtlsValidHeapPointer(pUserdata).

The DLL class is defined as follows:

#ifdef MAKE_DLL
#define Export __declspec(dllexport)
#else
#define Export __declspec(dllimport)
#endif

class Export MyClass
public:
   class Export Data    // tried also without Export here; same fault
   public:
      long value;
   };

   typedef std::list<Data> DataList;

   bool getList(DataList& l);

private:
   MyClassImpl* impl;

Quote:
};

In main I call the getList method like this:

int main() {
   MyClass my;

   MyClass::DataList dataList;
   my.getList(dataList);

   return 0;

Quote:
}

The method calls the corresponding method in the implementation
class which is not exported by the DLL. The implementation
simply loads the data list with the values found in the internal
list (vector). Seen below.

class MyClassImpl
{
public:
   bool getList(DataList& l)
   {
      std::vector<MyClass::Data> it;

      l.clear();
      for (it=list_.begin(); it!=list_.end(); it++) {
         l.push_back(*it);
      }      
   }

   std::vector<MyClass::Data> list_;

Quote:
};

Everything works fine except for when the program exists. If I don't have
any elements in the internal vector then everything is fine, but then it
contains some elements and thus returns the element in the DeviceList
parameter, the program always results in an exception (when it ends).
The callback trace shows that the destructor in the vector is called
and that tries to release it's allocated memory.

Can anyone please give me an explaination why this happens, and
how to solve it.
Is it possible to use STL in method calls like this ??

Thanks,
Stefan



Tue, 15 May 2001 03:00:00 GMT  
 HELP: Passing std::list to a DLL
Check out Microsoft's Knowledge Base article 'Q172396'.  We were having the
exact same sort of errors until we ran across this article.  We then tested
to see if the errors really were because of the DLL by converting our DLL to
a static library.  Ran great linked in statically.  So, we're looking into
other STL implementations and are going to have to give up on Microsoft's.
Quote:

>Hi,

>I have some difficulties when passing a std::list container in a
>method. The class resides in a DLL. Everything works fine except
>when the program exists, it results in a failed assertion in dbgheap.c.
>Expression: _CrtlsValidHeapPointer(pUserdata).

>The DLL class is defined as follows:

>#ifdef MAKE_DLL
>#define Export __declspec(dllexport)
>#else
>#define Export __declspec(dllimport)
>#endif

>class Export MyClass
>public:
>   class Export Data // tried also without Export here; same fault
>   public:
>      long value;
>   };

>   typedef std::list<Data> DataList;

>   bool getList(DataList& l);

>private:
>   MyClassImpl* impl;
>};

>In main I call the getList method like this:

>int main() {
>   MyClass my;

>   MyClass::DataList dataList;
>   my.getList(dataList);

>   return 0;
>}

>The method calls the corresponding method in the implementation
>class which is not exported by the DLL. The implementation
>simply loads the data list with the values found in the internal
>list (vector). Seen below.

>class MyClassImpl
>{
>public:
>   bool getList(DataList& l)
>   {
>      std::vector<MyClass::Data> it;

>      l.clear();
>      for (it=list_.begin(); it!=list_.end(); it++) {
>         l.push_back(*it);
>      }
>   }

>   std::vector<MyClass::Data> list_;
>};

>Everything works fine except for when the program exists. If I don't have
>any elements in the internal vector then everything is fine, but then it
>contains some elements and thus returns the element in the DeviceList
>parameter, the program always results in an exception (when it ends).
>The callback trace shows that the destructor in the vector is called
>and that tries to release it's allocated memory.

>Can anyone please give me an explaination why this happens, and
>how to solve it.
>Is it possible to use STL in method calls like this ??

>Thanks,
>Stefan



Thu, 17 May 2001 03:00:00 GMT  
 HELP: Passing std::list to a DLL
See header xstring for the MS VC6 way to export instanciated template
classes from a DLL ...

--
BTW: It is normally better to answer to the group! For direct mail reply
remove ".no_spam"

Quote:

>Hi,

>I have some difficulties when passing a std::list container in a
>method. The class resides in a DLL. Everything works fine except
>when the program exists, it results in a failed assertion in dbgheap.c.
>Expression: _CrtlsValidHeapPointer(pUserdata).

>The DLL class is defined as follows:

>#ifdef MAKE_DLL
>#define Export __declspec(dllexport)
>#else
>#define Export __declspec(dllimport)
>#endif

>class Export MyClass
>public:
>   class Export Data // tried also without Export here; same fault
>   public:
>      long value;
>   };

>   typedef std::list<Data> DataList;

>   bool getList(DataList& l);

>private:
>   MyClassImpl* impl;
>};

>In main I call the getList method like this:

>int main() {
>   MyClass my;

>   MyClass::DataList dataList;
>   my.getList(dataList);

>   return 0;
>}

>The method calls the corresponding method in the implementation
>class which is not exported by the DLL. The implementation
>simply loads the data list with the values found in the internal
>list (vector). Seen below.

>class MyClassImpl
>{
>public:
>   bool getList(DataList& l)
>   {
>      std::vector<MyClass::Data> it;

>      l.clear();
>      for (it=list_.begin(); it!=list_.end(); it++) {
>         l.push_back(*it);
>      }
>   }

>   std::vector<MyClass::Data> list_;
>};

>Everything works fine except for when the program exists. If I don't have
>any elements in the internal vector then everything is fine, but then it
>contains some elements and thus returns the element in the DeviceList
>parameter, the program always results in an exception (when it ends).
>The callback trace shows that the destructor in the vector is called
>and that tries to release it's allocated memory.

>Can anyone please give me an explaination why this happens, and
>how to solve it.
>Is it possible to use STL in method calls like this ??

>Thanks,
>Stefan



Sun, 20 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing std::set and std::map objects between 2 dlls

2. std::vector passed to DLL class never arrives???

3. passing std::ofstream by reference to DLL

4. passing std::vector to a DLL by reference

5. Std::set and passing between DLLs

6. passing std::map based objects from an app to a dll

7. std::list, std::vector, push_back() and associated ::iterator validity

8. export classes using std namespace (ex std::vector) in a DLL

9. Help with standard template library (std::list) in MSVC++5.0

10. help: 'using namespace std' and lists

11. Help with standard template library (std::list) in MSVC++5.0

12. list vs std::list

 

 
Powered by phpBB® Forum Software