|
This question is difficult to ask. The concept is simple, but the details of explaining it just go on and on.
Using Visual Studio 2008, I have created an application with MFC. In this application there is to be a linked list of instantiated objects. This list is to live the lifetime of the program and be publically accessible.
Not being familiar at all with the windows concept, where do I instantiate/create this object? There is no place within the code that VS created that I recognize as being something that can hold a permanent variable.
If the question is clear at this point, you might want to stop reading now. I am confused so the remainder of this post may be even more confusing.
The base class that VS created is listed below. Where should I insert something like:
CMyClass myinstance = new( CMyClass );
Or maybe:
CMyClass myinstance;
I want that because in another class I wish to write:
CMyClass::myinstance.LinkNewItem( new_item );
Hopefully this will cause a new item to be linked in to the linked list and other code can traverse the list to work with the data.
It none of this is appropriate, please advise as to what is appropriate.
Here is the cpp file that VS created. Where does my code belong?:
// test1.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "test1.h"
#include "test1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Ctest1App
BEGIN_MESSAGE_MAP(Ctest1App, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// Ctest1App construction
Ctest1App::Ctest1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only Ctest1App object
Ctest1App theApp;
// Ctest1App initialization
BOOL Ctest1App::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
Ctest1Dlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
Thanks for your time
|
|
|
|
|
It seems you are creating a dialog based application. In that case you can put your data in the dialog class. In the example code you provided in the Ctest1Dlg which should be in the files test1Dlg.h and test1Dlg.cpp.
-Saurabh
|
|
|
|
|
I've tested when saving and loading, right, but not sure wheather it is always safe.
void CMyDoc::Serialize(CArchive& ar) {
CFile *pFile = ar.GetFile();
CString path = pFile>GetFilePath();
TCHAR buf[MAX_PATH];
DWORD dw = GetPrivateProfileString(m_sec,m_key,NULL,buf,MAX_PATH,path);
...
}
|
|
|
|
|
An INI file should have nothing to do with serializing CObjects. So it should be safe, but as always it depends on what the developer does.
|
|
|
|
|
When saving, the frameword open the file in mode
CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive ,
but the GetPrivateProfile still works
|
|
|
|
|
h3y hI every1 i am sorry for this childish question but actually i got a task to perform directory manipulation ... i have created folder by using _mkdir nd remove the folder my using _rmdir .. But i dont know how to show all the content of directory mean i have to show all files name in that folder and all directory names in that folder could any one help me .. i am using visual studio 2005 .. c++ Only in c++ no windows API no MFC nO <direct.h> Just purly c++ .. please reply me back
|
|
|
|
|
Member 3831312 wrote: c++ Only in c++ no windows API no MFC nO Just purly c++
Sorry. There are no "standard" C++ facilities to iterate through files or folders/directories. You have to use an interface to the operating system to do that (.NET, Win32 SDK, etc for Windows platforms; Unix/Linux has their counterparts).
Or, you can use a 3rd-party library (such as Boost) and use their interface.
Enjoy,
Robert C. Cartaino
|
|
|
|
|
Thanks FOr reply Robert ... Please tell me one thing more i am using 3rd party library booost ... but i cause me an error while compiling it says ,
"fatal error LNK1104: cannot open file 'libboost_filesystem-vc80-mt-gd-1_35.lib'"
do u have any idea about it ... hOw can i resolve it .. i have linked all the important path that i have to give but still its not working .. please do hit me back
thanks
|
|
|
|
|
The problem is clearly stated in the error message: the linker can't find the file "libboost_filesystem-vc80-mt-gd-1_35.lib". So two questions occur:
1. Has this file been built (Boost.FileSystem is NOT a header only library)?
2. Has the path to this file been specified in the project settings?
Steve
|
|
|
|
|
H3y hi every1 please help me out i am Just creating a small program in c++, which is use to show all the content Of a directory .. i am Using BOOST LIBRARY beacuse there is nO other option for e if there nay other option plzz do tell me and tell me how to resolve this prob actually prog is compiling but i dont know whats wrong its keep on giving this Error i am Using Visual STudio 2005 ... please help me
|
|
|
|
|
Download and install "BoostPro 1.35.0 Installer" from this site.
http://www.boostpro.com/products/free[^]
Then link with the library "libboost_filesystem-vc80-mt-gd-1_35.lib" which is included with the installer.
-Saurabh
|
|
|
|
|
thanks FOr reply But my dear brother i have already installed that but still itx not working i dont know about the prob PLzz help me
|
|
|
|
|
Have you linked the lib file in the Project-->Settings menu as Saurabh.Garg told you above?
|
|
|
|
|
yes i have linked the folder of lib in addition libraris . but still not working
|
|
|
|
|
Ah my bad I didnt look at the error more carefully. Linker is not able to find the lib file. Try giving the full path to the library or set the folder where boost libraries are under Project->Properties->Linker->Genral->Addition Library Directories.
-Saurabh
|
|
|
|
|
Hi all
I am trying to take exchange server 2003 backup and restore
programmatically. I am using Visual C++ for coding.
My backup function works fine. But i am in problem in restoring
database. My HrESERestoreAddDatabase is not working well. The
HrESERestoreAddDatabase is returning HRESULT -939587631.
Will anyone give me any link related exchange server 2003 backup? Or
can anyone give me sample code or link to sample code related to
HrESERestoreAddDatabase() method?
Thanks in advance
Nasif
Nasif
|
|
|
|
|
CThree.h is :
template < class T ><br />
class CThree<br />
{<br />
private:<br />
T a, b, c;<br />
public:<br />
CThree(T t1, T t2, T t3);<br />
T Min();<br />
T Max();<br />
};
CThree.cpp is :
template < class T ><br />
T CThree< T >::Min()<br />
{<br />
T minab = a < b ? a : b;<br />
return minab < c ? minab : c;<br />
}<br />
<br />
template < class T ><br />
T CThree< T >::Max()<br />
{<br />
T maxab = a < b ? b : a;<br />
return maxab < c ? c : maxab;<br />
}<br />
<br />
template < class T ><br />
CThree< T >::CThree(T t1, T t2, T t3):a(t1), b(t2), c(t3)<br />
{<br />
return;<br />
}
compile is ok, but when I use this Template Classe, it take wrong.
Usage code is :
CThree< int > obj1(2, 5, 4);<br />
int MAX1 = obj1.Max();<br />
int MIN1 = obj1.Min();
part of the wrong is :
1>TemplateFunction.obj : error LNK2019: unresolved external symbol "public: __thiscall CThree<int>::CThree<int>(int,int,int)" (??0?$CThree@H@@QAE@HHH@Z) referenced in function _wmain
Anybody tell me why?
Thanks!
|
|
|
|
|
|
It's a perfect article, thanks a lot!
|
|
|
|
|
You are welcome.
-Saurabh
|
|
|
|
|
|
Code must be written to be read, not by the compiler, but by another human being.
good word, thinks!
|
|
|
|
|
|
Hi everyone,
I want to learn make services but I don't know any thing about it do you know good reference or book for it?
|
|
|
|
|