Solved

Problems with Window class

Posted on 2011-02-23
4
615 Views
Last Modified: 2012-05-11
Hello,

I have a problem with a CWindow class I use in a DLL. I load the class from the DLL.
The compile throws a message, and I am sure this is a problem of some crashes, too.
So anybody can give me a hint what is wrong here?

Ocrana

Compileroutput:
1>c:\projects\dvdranger2\trunk\dvdconvdll\mediawnd.h(120) : warning C4275: non dll-interface class 'ATL::CWindow' used as base for dll-interface class 'ATL::CWindowImplRoot<TBase>'
1>        with
1>        [
1>            TBase=ATL::CWindow
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\atlwin.h(686) : see declaration of 'ATL::CWindow'
1>c:\projects\dvdranger2\trunk\dvdconvdll\mediawnd.h(289) : warning C4251: 'MediaWnd::frameBuffers' : class 'std::list<_Ty>' needs to have dll-interface to be used by clients of class 'MediaWnd'
1>        with
1>        [
1>            _Ty=BYTE *
1>        ]
#pragma once
#ifdef MOBILE_CONV_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif

#include <atlbase.h>
#include <atlctl.h>
#include <list>

class DLLEXPORT MediaWnd : public CWindowImpl<MediaWnd, CWindow>
{
	BEGIN_MSG_MAP(MediaWnd)
		DEFAULT_REFLECTION_HANDLER()
		MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
		....
	END_MSG_MAP()

public:
	MediaWnd();
	virtual ~MediaWnd();

	virtual void CreateWnd(HWND hWnd);
	....
	std::list<BYTE *> frameBuffers;
	....
	
}

Open in new window

0
Comment
Question by:Ocrana
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 34965824
You are hitting a mine field here - see http://support.microsoft.com/kb/168958 ("How to export an instantiation of a Standard Template Library (STL) class and a class that contains a data member that is an STL object"). In short: Don't make an STL object publicly accessible in a DLL, always use accessors that conceal the object, e.g.
#pragma once
#ifdef MOBILE_CONV_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif

#include <atlbase.h>
#include <atlctl.h>
#include <list>

class DLLEXPORT MediaWnd : public CWindowImpl<MediaWnd, CWindow>
{
	BEGIN_MSG_MAP(MediaWnd)
		DEFAULT_REFLECTION_HANDLER()
		MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
		....
	END_MSG_MAP()

public:
	MediaWnd();
	virtual ~MediaWnd();

	virtual void CreateWnd(HWND hWnd);
	....

        BYTE* GetNextFrame() { */ ... */ }

protected:
	std::list<BYTE *> frameBuffers;
	....
	
}

Open in new window

0
 

Author Comment

by:Ocrana
ID: 34968843
Hi,

I have set it to protected but the compiler is still naging with the same issue. So no change there.

Ocrana
0
 
LVL 34

Expert Comment

by:sarabande
ID: 34969768
the std::list<BYTE*> cannot exported/imported between dll boundaries (at least not without efforts).

so you may think of using array of BYTE* instead.

Sara
0
 

Author Comment

by:Ocrana
ID: 34971338
I use the std:list<BYTE*> for internal use.It is portected now. It contains the rendering buffer for the MEdiaWnd (a set of images). A "simple" Byte Arry is the worst solution.But why the compile see a protected member as a export one? It is not public, so not available to the export.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
In this post we will learn different types of Android Layout and some basics of an Android App.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question