From: Joseph M. Newcomer on
I assumed the class had the appropriate AFX_EXT_CLASS or other suitable macro definition;
this should be added automatically when a project for an extension DLL is created. My
error. Of course, if the all-important source code had been included in the post, I might
have noticied this omission (but hey, why make it easy for the guys you are asking the
question of...?)
joe


On Fri, 16 Oct 2009 12:15:52 -0500, Stephen Myers
<""StephenMyers\"@discussions(a)microsoft.com"> wrote:

>Luigino wrote:
>>> confusing the C++ compiler with the linker here. They are different, and what you do in
>>> C++ has no implicit effect on the linker. Go to the Linker, Inputs, and add your .lib
>>> file to the additional libraries line.
>>
>> Ehm I did... I put under Linker-General in Additional Library
>> Directories the path of that Debug directory where the .lib file is
>> created once compiled the DLL and I added under Linker-Input, in
>> Additional Dependencies that CACharts.lib.....
>> So I also created now a control variable (from the class add variable
>> wizard) for this and implemented the code:
>>
>> CRect rect;
>> c_MyStaticControl.GetWindowRect(&rect);
>> ScreenToClient(&rect);
>> CCaChart c_MyControl;
>> c_MyControl.Create(rect, GetDlgItem
>> (c_MyStaticControl.GetDlgCtrlID()));
>> c_MyStaticControl.DestroyWindow();
>>
>> but I get these linker errors:
>>
>> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
>> "public: virtual __thiscall CCaChart::~CCaChart(void)" (??
>> 1CCaChart@@UAE(a)XZ) referenced in function "protected: virtual int
>> __thiscall Ctest_chartDlg::OnInitDialog(void)" (?
>> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
>> "public: virtual int __thiscall CCaChart::Create(class CRect const
>> &,class CWnd *)" (?Create(a)CCaChart@@UAEHABVCRect@@PAVCWnd@@@Z)
>> referenced in function "protected: virtual int __thiscall
>> Ctest_chartDlg::OnInitDialog(void)" (?
>> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
>> "public: __thiscall CCaChart::CCaChart(void)" (??0CCaChart@@QAE(a)XZ)
>> referenced in function "protected: virtual int __thiscall
>> Ctest_chartDlg::OnInitDialog(void)" (?
>> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>>
>> So, suspecting a possible issue of my VS2008, I tried to create from
>> scratch with class wizards a simple stupid DLL without adding or
>> modifying anything and trying to create a Test file from Visual Studio
>> IDE itself and when it asks me to choose the DLL project to test, it
>> returns "Unknown address 0"... then I try to create a test project for
>> the example, adding the .lib and I get same linker error I pasted
>> before...
>I thought you needed to export the symbols in the library.
>
>In CaChart.h
>
>Something like
>
>#ifdef MYLIB_BUILD
>#define MYDLL_IO _declspec(dllexport) //conditional on MYLIB_BUILD
>#else
>#define MYDLL_IO _declspec(dllimport)
>#endif
>
>class MYDLL_IO CCaChart: public ...
>
>Then add MYLIB_BUILD to the library project
>Configuration Properties
> C/C++
> Preprocessor
> Preprocessor Defines
>
>Steve
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Luigino on
On 16 Ott, 22:27, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
> I assumed the class had the appropriate AFX_EXT_CLASS or other suitable macro definition;
> this should be added automatically when a project for an extension DLL is created. My
> error. Of course, if the all-important source code had been included in the post, I might
> have noticied this omission (but hey, why make it easy for the guys you are asking the
> question of...?)
> joe
>
> On Fri, 16 Oct 2009 12:15:52 -0500, Stephen Myers
>
>
>
> <""StephenMyers\"@discussi...(a)microsoft.com"> wrote:
> >Luigino wrote:
> >>> confusing the C++ compiler with the linker here. They are different, and what you do in
> >>> C++ has no implicit effect on the linker. Go to the Linker, Inputs, and add your .lib
> >>> file to the additional libraries line.
>
> >> Ehm I did... I put under Linker-General in Additional Library
> >> Directories the path of that Debug directory where the .lib file is
> >> created once compiled the DLL and I added under Linker-Input, in
> >> Additional Dependencies that CACharts.lib.....
> >> So I also created now a control variable (from the class add variable
> >> wizard) for this and implemented the code:
>
> >> CRect rect;
> >> c_MyStaticControl.GetWindowRect(&rect);
> >> ScreenToClient(&rect);
> >> CCaChart c_MyControl;
> >> c_MyControl.Create(rect, GetDlgItem
> >> (c_MyStaticControl.GetDlgCtrlID()));
> >> c_MyStaticControl.DestroyWindow();
>
> >> but I get these linker errors:
>
> >> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
> >> "public: virtual __thiscall CCaChart::~CCaChart(void)" (??
> >> 1CCaChart@@UAE(a)XZ) referenced in function "protected: virtual int
> >> __thiscall Ctest_chartDlg::OnInitDialog(void)" (?
> >> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
> >> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
> >> "public: virtual int __thiscall CCaChart::Create(class CRect const
> >> &,class CWnd *)" (?Create(a)CCaChart@@UAEHABVCRect@@PAVCWnd@@@Z)
> >> referenced in function "protected: virtual int __thiscall
> >> Ctest_chartDlg::OnInitDialog(void)" (?
> >> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
> >> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
> >> "public: __thiscall CCaChart::CCaChart(void)" (??0CCaChart@@QAE(a)XZ)
> >> referenced in function "protected: virtual int __thiscall
> >> Ctest_chartDlg::OnInitDialog(void)" (?
> >> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>
> >> So, suspecting a possible issue of my VS2008, I tried to create from
> >> scratch with class wizards a simple stupid DLL without adding or
> >> modifying anything and trying to create a Test file from Visual Studio
> >> IDE itself and when it asks me to choose the DLL project to test, it
> >> returns "Unknown address 0"... then I try to create a test project for
> >> the example, adding the .lib and I get same linker error I pasted
> >> before...
> >I thought you needed to export the symbols in the library.
>
> >In CaChart.h
>
> >Something like
>
> >#ifdef MYLIB_BUILD
> >#define MYDLL_IO _declspec(dllexport) //conditional on MYLIB_BUILD
> >#else
> >#define MYDLL_IO _declspec(dllimport)
> >#endif
>
> >class MYDLL_IO CCaChart: public ...
>
> >Then add MYLIB_BUILD to the library project
> >Configuration Properties
> > C/C++
> > Preprocessor
> > Preprocessor Defines
>
> >Steve
>
> Joseph M. Newcomer [MVP]
> email: newco...(a)flounder.com
> Web:http://www.flounder.com
> MVP Tips:http://www.flounder.com/mvp_tips.htm

In fact now it works.... just a thing that I'm trying to draw a filled
ellipse (where in the place I'll code the real component) and I
implemented an OnPaint, since I guess right after calling Create
function it should paint the DC on the parent but at debug it doesn't
fire...
I coded the OnPaint like this:

in the .h

afx_msg void OnPaint();

in the .cpp

added ON_WM_PAINT() in the MESSAGE_MAP routine

void MyDLL::OnPaint()
{
CPaintDC dc(this);

CDC MemDC;
if (!MemDC.CreateCompatibleDC(&dc))
return;

CRect rect;
GetClientRect(rect); // because it is a client
MemDC.FillRect(rect, CBrush::FromHandle((HBRUSH)
GetStockObject(BLACK_BRUSH)));
MemDC.Ellipse(rect);
}

I tried also to move the creation thing to the test app in the way to
have an OnCreate(LPCREATESTRUCT lpCreateStruct) with same code of
OnPaint in the way to apply the drawing of the ellipse right after
creation of the DC and during Create(...) call it doesn't even fire
OnCreate(...) event to draw the ellipse, plus at SetWindowPos
execution I get an assert error on this line and at debug reports
passing the WndStatic variable (got by: CWnd* WndStatic = GetDlgItem
(c_MyStaticControl.GetDlgCtrlID()); since c_MyStaticControl control
variable is CStatic type), the m_hWnd in the function has value 0....
Shall I have missed something?....

Thanks
Ciao
Luigi
From: Stephen Myers on
Luigino wrote:
> On 16 Ott, 22:27, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> I assumed the class had the appropriate AFX_EXT_CLASS or other suitable macro definition;
>> this should be added automatically when a project for an extension DLL is created. My
>> error. Of course, if the all-important source code had been included in the post, I might
>> have noticied this omission (but hey, why make it easy for the guys you are asking the
>> question of...?)
>> joe
>>
>> On Fri, 16 Oct 2009 12:15:52 -0500, Stephen Myers
>>
>>
>>
>> <""StephenMyers\"@discussi...(a)microsoft.com"> wrote:
>>> Luigino wrote:
>>>>> confusing the C++ compiler with the linker here. They are different, and what you do in
>>>>> C++ has no implicit effect on the linker. Go to the Linker, Inputs, and add your .lib
>>>>> file to the additional libraries line.
>>>> Ehm I did... I put under Linker-General in Additional Library
>>>> Directories the path of that Debug directory where the .lib file is
>>>> created once compiled the DLL and I added under Linker-Input, in
>>>> Additional Dependencies that CACharts.lib.....
>>>> So I also created now a control variable (from the class add variable
>>>> wizard) for this and implemented the code:
>>>> CRect rect;
>>>> c_MyStaticControl.GetWindowRect(&rect);
>>>> ScreenToClient(&rect);
>>>> CCaChart c_MyControl;
>>>> c_MyControl.Create(rect, GetDlgItem
>>>> (c_MyStaticControl.GetDlgCtrlID()));
>>>> c_MyStaticControl.DestroyWindow();
>>>> but I get these linker errors:
>>>> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
>>>> "public: virtual __thiscall CCaChart::~CCaChart(void)" (??
>>>> 1CCaChart@@UAE(a)XZ) referenced in function "protected: virtual int
>>>> __thiscall Ctest_chartDlg::OnInitDialog(void)" (?
>>>> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>>>> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
>>>> "public: virtual int __thiscall CCaChart::Create(class CRect const
>>>> &,class CWnd *)" (?Create(a)CCaChart@@UAEHABVCRect@@PAVCWnd@@@Z)
>>>> referenced in function "protected: virtual int __thiscall
>>>> Ctest_chartDlg::OnInitDialog(void)" (?
>>>> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>>>> 1>test_chartDlg.obj : error LNK2019: unresolved external symbol
>>>> "public: __thiscall CCaChart::CCaChart(void)" (??0CCaChart@@QAE(a)XZ)
>>>> referenced in function "protected: virtual int __thiscall
>>>> Ctest_chartDlg::OnInitDialog(void)" (?
>>>> OnInitDialog(a)Ctest_chartDlg@@MAEHXZ)
>>>> So, suspecting a possible issue of my VS2008, I tried to create from
>>>> scratch with class wizards a simple stupid DLL without adding or
>>>> modifying anything and trying to create a Test file from Visual Studio
>>>> IDE itself and when it asks me to choose the DLL project to test, it
>>>> returns "Unknown address 0"... then I try to create a test project for
>>>> the example, adding the .lib and I get same linker error I pasted
>>>> before...
>>> I thought you needed to export the symbols in the library.
>>> In CaChart.h
>>> Something like
>>> #ifdef MYLIB_BUILD
>>> #define MYDLL_IO _declspec(dllexport) //conditional on MYLIB_BUILD
>>> #else
>>> #define MYDLL_IO _declspec(dllimport)
>>> #endif
>>> class MYDLL_IO CCaChart: public ...
>>> Then add MYLIB_BUILD to the library project
>>> Configuration Properties
>>> C/C++
>>> Preprocessor
>>> Preprocessor Defines
>>> Steve
>> Joseph M. Newcomer [MVP]
>> email: newco...(a)flounder.com
>> Web:http://www.flounder.com
>> MVP Tips:http://www.flounder.com/mvp_tips.htm
>
> In fact now it works.... just a thing that I'm trying to draw a filled
> ellipse (where in the place I'll code the real component) and I
> implemented an OnPaint, since I guess right after calling Create
> function it should paint the DC on the parent but at debug it doesn't
> fire...
> I coded the OnPaint like this:
>
> in the .h
>
> afx_msg void OnPaint();
>
> in the .cpp
>
> added ON_WM_PAINT() in the MESSAGE_MAP routine
>
> void MyDLL::OnPaint()
> {
> CPaintDC dc(this);
>
> CDC MemDC;
> if (!MemDC.CreateCompatibleDC(&dc))
> return;
>
> CRect rect;
> GetClientRect(rect); // because it is a client
> MemDC.FillRect(rect, CBrush::FromHandle((HBRUSH)
> GetStockObject(BLACK_BRUSH)));
> MemDC.Ellipse(rect);
> }
>
> I tried also to move the creation thing to the test app in the way to
> have an OnCreate(LPCREATESTRUCT lpCreateStruct) with same code of
> OnPaint in the way to apply the drawing of the ellipse right after
> creation of the DC and during Create(...) call it doesn't even fire
> OnCreate(...) event to draw the ellipse, plus at SetWindowPos
> execution I get an assert error on this line and at debug reports
> passing the WndStatic variable (got by: CWnd* WndStatic = GetDlgItem
> (c_MyStaticControl.GetDlgCtrlID()); since c_MyStaticControl control
> variable is CStatic type), the m_hWnd in the function has value 0....
> Shall I have missed something?....
>
> Thanks
> Ciao
> Luigi

CWnd* WndStatic = GetDlgItem(c_MyStaticControl.GetDlgCtrlID());

is not at all the way things should be done. There is no reason to
create WndStatic. GetDlgItem should not be used in MFC. Check the
source of your code snippets. Chances are very good they are either not
written for MFC or written by someone who had not figured out what you
get with MFC.

Use c_MyStaticControl. instead of WndStatic->

This will not cirrect your problem.

I suspect that the real problem is due to accessing the control before
it is created (in OnInitDialog).

Steve
From: Luigino on
> CWnd* WndStatic = GetDlgItem(c_MyStaticControl.GetDlgCtrlID());
>
> is not at all the way things should be done. There is no reason to
> create WndStatic. GetDlgItem should not be used in MFC. Check the
> source of your code snippets. Chances are very good they are either not
> written for MFC or written by someone who had not figured out what you
> get with MFC.
>
> Use c_MyStaticControl. instead of WndStatic->
>
> This will not cirrect your problem.
>
> I suspect that the real problem is due to accessing the control before
> it is created (in OnInitDialog).
>
> Steve

HI Steve,

the fact is I created a CStatic in the resource window, and I created
a Control Variable for this CStatic so the variable created is a
CStatic type and the first parameter of SetWindowPos() which is a
const CWnd *pWndInsertAfter wouldn't cast from CStatic to const CWnd,
that's why I declared that variable.
Actually I can "create" my cwnd derived class which now fires an
OnCreate event and it executes those instructions:

CPaintDC dc(this);
CDC MemDC;

if (!MemDC.CreateCompatibleDC(&dc))
return;

CRect rect;
GetClientRect(rect); // because it is a client
MemDC.FillRect(rect, CBrush::FromHandle((HBRUSH) GetStockObject
(BLACK_BRUSH)));
MemDC.Ellipse(rect);

but when I SetWindowPos with WndCStatic it appears the window without
showing the control...

in the OnInitDialog I coded like here:

CRect rect;
c_MyStaticControl.GetWindowRect(&rect);
ScreenToClient(&rect);
CCaChart c_MyControl;
CWnd* WndStatic = GetDlgItem(c_MyStaticControl.GetDlgCtrlID());
c_MyControl.Create(_T("MFCCaChartCtrl"), _T(""), WS_CHILD|WS_VISIBLE|
WS_BORDER, rect, this, IDC_MYCONTROL);
c_MyControl.SetWindowPos(c_WndStatic, 0, 0, 0, 0, SWP_NOSIZE|
SWP_NOMOVE);
c_MyStaticControl.DestroyWindow();

from an example at begin of this post I tried to put c_MyStaticControl
in the SetWindowPost but no cast available...
From: David Wilkinson on
Luigino wrote:
> the fact is I created a CStatic in the resource window, and I created
> a Control Variable for this CStatic so the variable created is a
> CStatic type and the first parameter of SetWindowPos() which is a
> const CWnd *pWndInsertAfter wouldn't cast from CStatic to const CWnd,
> that's why I declared that variable.

There is no reason you cannot pass &c_MyStaticControl to a function expecting
const CWnd*. Perhaps you were forgetting the '&'?

When something doesn't work, try to figure out why. Don't turn around and do
something that makes no sense at all (even if it works...). The main purpose of
control variables is so you do not have to use GetDlgItem().

--
David Wilkinson
Visual C++ MVP