1

I want to use DDX_Text with a member variable of type DBTIMESTAMP:

class CSerialView : public CFormView
{
    DECLARE_DYNCREATE(CSerialView)
    //.....
public:
    DBTIMESTAMP m_ProductionDate; // read from OLEDB consumer class
    //.....
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //......
}
void CSerialView::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_PRODUCTIONDATE, m_ProductionDate);
}

Compiling is fine, the used syntax of DDX_Text is listed in Intellisense, so it appears that Microsoft defined this function somewhere, however the linker bails out with error LNK2019. See attached picture.

enter image description here

Build output as listed here:

1>SerialView.obj : error LNK2019: unresolved external symbol "void __stdcall DDX_Text(class CDataExchange *,int,struct tagDBTIMESTAMP &)" (?DDX_Text@@YGXPAVCDataExchange@@HAAUtagDBTIMESTAMP@@@Z) referenced in function "protected: virtual void __thiscall CSerialView::DoDataExchange(class CDataExchange *)" (?DoDataExchange@CSerialView@@MAEXPAVCDataExchange@@@Z)
1>c:\dev\projects\HCPSOrders\Debug\HCPSOrdersApp.exe : fatal error LNK1120: 1 unresolved externals

I am not looking for an explanation of LNK2019 nor LNK1120, I know their meaning. I want to solve this particular error instance: so which reference(s) am I missing?

Bart
  • 547
  • 3
  • 16
  • What makes you think that structure is supported by [`DDX_Text`](https://msdn.microsoft.com/en-us/library/a1xttfdt.aspx)? How would you expect it to work? Do you even know the purpose of the [`DDX_Text`](https://msdn.microsoft.com/en-us/library/a1xttfdt.aspx) function? – Some programmer dude Sep 07 '15 at 09:27
  • Yes, I did. The particular overload is not even listed there, though there is one using COleDateTime. Maybe i should go with that one because it can be constructed from DBTIMESTAMP. – Bart Sep 07 '15 at 09:29
  • Yes, I know very well what the purpose of DDX_Text is. There is no need to lecture me on that topic or attempt to belittle me. One more thing, the overload that I want to use is suggested by Intellisense, so maybe it is not so far fetched to think it is supported. – Bart Sep 07 '15 at 09:30
  • 1
    I'm sorry if I sound condescending or rude or anything, I'm a little grumpy today. But the reason that Intellisense says it's okay is because of that `COleDataTime` overload, and that a `COleDataTime` implicitly can be constructed from a `DBTIMESTAMP` (the [`COleDateTime` constructor](https://msdn.microsoft.com/en-us/library/1yy4h318.aspx) isn't marked `explicit`). You might want to use that class instead. – Some programmer dude Sep 07 '15 at 09:38
  • I think I will try it using COleDateTime. I still think it is funny that the overload I intended to use is listed explicitly if the function is really not supported. – Bart Sep 07 '15 at 09:52
  • 1
    What version of VS do you have? In VS2015 I see 17 overloads for `DDX_Text`, none of them include `DBTIMESTAMP`, this fits with `DDX_Text` header file. Also, what do you see in the header file? (it should be called "afxdd_.h") – Barmak Shemirani Sep 07 '15 at 20:39
  • I use VS2012 professional. As you can see in the screenshot attached to the question, there are 21 overloads, intended overload being the first. I saw just now it is declared in afxdd_.h as void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, COleDateTime& value); When I use "goto declaration" in the context menu it takes me to this entry. Apparently Intellisense lists it because COleDateTime can be implicitly constructed from DBTIMESTAMP. Maybe this is a feature that can be disabled. I will have to look into that. This also answers my question, there is no such explicit overload. – Bart Sep 08 '15 at 07:22

1 Answers1

-1

This solved the problem for me:

DDX_Text(pDX, IDC_PRODUCTIONDATE, COleDateTime(m_ProductionDate));
Bart
  • 547
  • 3
  • 16
  • 3
    Probably not a good idea at all, since the `DDX_Text` takes the third argument by non-const reference, and you construct a temporary object that will be destructed once the `DDX_Text` function returns. Using a reference to a destructed object leads to undefined behavior. – Some programmer dude Sep 07 '15 at 10:34
  • After the function call returns I will not using the reference anymore. As the data is only meant to be read-only, this is not a problem. My code executes conditionally on pDX->m_bSaveAndValidate == false. You are right that there would be a problem if i wanted to update m_ProductionDate from my CFormView class. The updated object would be destroyed. – Bart Sep 07 '15 at 11:35