0

Ask a problem,About CEdit control
i write code.....
<<<<<<<<<Static Dll>>>>>>>>
****************CmEdit.h**********

class AFX_NOVTABLE CmEdit : public CEdit
{
public:
 __declspec(dllexport) CString CmGetDlgItem(int nID);
};

***************CmEdit.Cpp**********

CString CmEdit::CmGetDlgItem(int nID)
{
  CString Str;
  GetDlgItem(nID)->GetWindowTextW(Str);
  return Str;
}

<<<<<<<<<<<<Static Exe>>>>>>>>>>>>>

#pragma comment(lib,"Dll.lib")
#include "CmEdit.h"
void SocialSecurityData::OnBnClickedOk()
{
  CmEdit d;
  CString r=d.CmGetDlgItem(IDC_EDIT1);
  MessageBox(r);
}

Start Debugging.....
Error...............
Why????
thank:)

3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

The main program cannot access controls in CmEdit class directly because they do not exist at the time you are attempting to access them. CDialog does not initialize the controls until OnInitDialog() is called, which is after DoModal(), and it destroys the controls when the CDialog returns from DoModal() (assuming you are using a model instead of modeless dialog).

To get around that problem I create a public CString object in the CDialog class that can be accessed from outside the CDialog class at any time. If the program needs the text from a CEdit control then the CDialog class sets this public variable before returning from either OnOK() or OnCancel() methods.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.