|
I used VS.NET 2003 to create a windows installer package but if I try and install the resulting msi package over the top of a previous install it complains with a message "... you must uninstall the previous version first"
Is there any way to allow installing over an existing one? and a related topic is can I set certain files to not be copied to the target if they exist already?
|
|
|
|
|
I have looked at the Modern C++ Design book and since none of the examples work in VC6 world, figured I should come up with something of my own.
So to start with, what do you think about this Singleton implementation?
header file
#include <windows.h>
class CSingleton
{
public:
static CSingleton & GetSingletonInstance ();
static void Guard();
static void UnGuard();
private:
CSingleton();
CSingleton(const CSingleton & );
virtual ~CSingleton();
static CSingleton * m_pSingleton;
static CRITICAL_SECTION m_CriticalSection;
static long m_lGuardCount;
};
cpp file
#include "Singleton.h"
CSingleton * CSingleton::m_pSingleton;
CRITICAL_SECTION CSingleton::m_CriticalSection;
long CSingleton::m_lGuardCount;
CSingleton::CSingleton()
{
}
CSingleton::~CSingleton()
{
}
CSingleton::CSingleton(const CSingleton & )
{
}
CSingleton & CSingleton::GetSingletonInstance()
{
if(!m_pSingleton)
{
Guard();
if(!m_pSingleton)
m_pSingleton = new CSingleton();
UnGuard();
}
return *m_pSingleton;
}
void CSingleton::Guard()
{
EnterCriticalSection(&m_CriticalSection);
m_lGuardCount++;
}
void CSingleton::UnGuard()
{
LeaveCriticalSection(&m_CriticalSection);
m_lGuardCount--;
}
How does this implementation look to you? The GuardCount is just there for reference. Doyou think Critical Section is enough or should I be using Events or Mutexes?
|
|
|
|
|
What does happen if
Anonymous wrote:
m_pSingleton = new CSingleton();
produce an exception?
How do you dispose of m_pSingleton when program ends?
|
|
|
|
|
As for the disposal part, wouldn't be cleaned up automatically as it is a static variable?
|
|
|
|
|
It is usually not very practical (system resources, unwritten files, database connections etc.), and it is extremely annoying during maintenance. I strongly recommend using std::auto_ptr or something similar.
|
|
|
|
|
Hi,
I am extremely new to using MFC, and am programming a simple application with a couple dialog boxes. I created the dialog boxes and the menu items, but I can not figure out how to set one of the radio buttons as the default choice. I was trying to use the CheckRadioButton feature but it doesn't work.
Any help would be appreciated...
Thanks in advance.
|
|
|
|
|
One solution is via resource editor. Look for an option to set the default button. Another solution is to initialize the radio buttons in OnInitDialog(). Call SetCheck().
Kuphryn
|
|
|
|
|
If you don't have a member variable for each of the radio buttons, you can use:
BOOL CMyDialog::OnInitDialog()
{
CheckRadioButton(ID_RADIO1, ID_RADIO5, ID_RADIO2);
}
Otherwise, create a member variable for each of the radio buttons. Then in OnInitDialog(), set the state of each with SetCheck().
BOOL CMyDialog::OnInitDialog()
{
m_btn1.SetCheck(FALSE);
m_btn2.SetCheck(TRUE);
m_btn3.SetCheck(FALSE);
m_btn4.SetCheck(FALSE);
m_btn5.SetCheck(FALSE);
}
|
|
|
|
|
Use ClassWizard to add a member variable tied to the first radio button in the group. The variable will be of type int . In the dialog box class's constructor, you will see that the variable is set to -1 . This means that none of the radio buttons are selected. Set this to 0 (for the first radio button in the group), 1 (for the second in the group) etc.
Hope this helps
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thanks for all the help.
Did the trick....
|
|
|
|
|
I'm having trouble understanding the use of vectors in C++, perhaps someone could comment about this snippet of code (found on the internet). In particular, the area I'm most confused about is in bold below...
How do you add elements to the list without having to assign objects names first? I'm trying to find a way to nest vectors of stuctures. From posts on this board, I've found that CArray is not recommended.
Here's the snippet of code... It's an array of people, each may have a variable number of nickels (dimes and pennies could be added).
************ nickel.h ********************************
#include < list >
#include < vector >
#include < algorithm >
#include < iostream >
using namespace std;
class nickel
{
public:
nickel();
virtual ~nickel();
};
class person
{
public:
person();
virtual ~person();
void addNickel(nickel *n) {myNickels.push_back(n);}
void removeLastNickel() {myNickels.erase(myNickels.end());}
private:
list < nickel * > myNickels;
};
**********KDlg.cpp*******************
void CKDlg::OnNewPerson()
{
//These don't work
NewNickel = new nickel;
NewPerson = new person; //doesn't work
NewPerson.addNickel(NewNickle) //expected constant expression
//This works, but forces me to assign objects to each element of the array...seems to defeat the purpose of a resizable array.
person p1,p2;
nickel n1,n2,n3;
p1.addNickel(&n1);
}
|
|
|
|
|
nickel* nn = new nickel;
person* np = new person;
np->addNickel(nn);
|
|
|
|
|
Hi!
I'm developing on a Win2k platform and I need to use the SP_DRVINFO_DATA to be defined as SP_DRVINFO_DATA_V2 instead of SP_DRVINFO_DATA_V1. As stated in MSDN:
"If your component will be used only on Windows 2000 and later, do not define the identifier. If the identifier is not defined, SP_DRVINFO_DATA_V2 is used."
Here's the define they're talking about: #define USE_SP_DRVINFO_DATA_V1 1
Obviously, I didn't defined this but SP_DRVINFO_DATA is still defined as SP_DRVINFO_DATA_V1.
Then, I went to the setupAPI.h file to see what was going on:
#if USE_SP_DRVINFO_DATA_V1 || (_SETUPAPI_VER < 0x0500)
...
typedef SP_DRVINFO_DATA_V1 SP_DRVINFO_DATA;
#else
***
typedef SP_DRVINFO_DATA_V2 SP_DRVINFO_DATA;
Since I didn't define the first condition, it's obvisous that the _SETUPAPI_VER is < than 0x0500. _SETUPAPI_VER is actually defined as (in my environment)
#if defined(_WIN32_WINNT) && (!defined(_WIN32_WINDOWS) || (_WIN32_WINNT < _WIN32_WINDOWS))
#define _SETUPAPI_VER _WIN32_WINNT // SetupAPI version follows Windows NT version
_WIN32_WINNT as a value of 0x0400. If I change this value (to 0x0500 for instance)or if I don't define it at all, some other stuff break in my code (error LNK2001: unresolved external symbol _CLSID_DOMDocument40)
Anyone has an idea how I could fix this conflict? Thanks in advance!
Jean-Francois !
|
|
|
|
|
I got a rather difficult question for the group.
Here it is:
I have created a program that records flight simulator data. I added a feature that allows the user to record the data to a file.
I would like to have a feature that wrote the simulator data to memory and if the user wanted to playback the data they would hit a button and the data that was written to memory would be played back.
I was thinking alongs the lines as a circulatory buffer. (Once it reaches the end it starts over) I thought about making a timestamp, so they can choose from time (a) to time (b)
I don't know how large to make the buffer?
This program is the only thing running on the machine besides Windows
Any ideas on how I should go about this?
thanks,
steven
|
|
|
|
|
You might want to consider Memory file. It is resizable and it automatically maps physical file into memory.
|
|
|
|
|
MSDN "Managing Memory-Mapped Files in Win32"
|
|
|
|
|
is this a type of file or a class?
What exactly is a memory file?
steven
|
|
|
|
|
Hi all,
I'm writing an ActiveX button control that uses the Caption stock property to display the text on the face of the button. I'm having a big problem getting the caption stock property to work correctly. I've added the caption stock property to my control class using the automation tab of classwizard, and added the appropriate drawing code in my OnDraw() function of the control. Everything works fine using the activex test container, but everything goes haywire in the program I embed the control in. In the application, the button face displays the caption as entered into the property page of the control, but when I try to change the caption using the stock caption put property method, the first time it will change, then any subsequent changes are not reflected, and the text on the button face is frozen (cannot be changed). This is also reflected in the VC++ 6.0 IDE. When I open the control property page in the IDE of the project I'm embedding the control in, and set the caption for the first time, it looks fine. But when if I need to change the caption in the IDE using the property page, it reverts back to the original caption. Does anyone have any ideas?
The activex control project runs under windows 2000, and compiles and registers fine. The project I'm embeding the control under also runs under windows 2000 and has no compile errors, but also uses the directx sdk.
I'm willing to send the source code for both projects to anyone willing to help me with this issue.
Please help!! This problem is maddening to me.
Thanks all,
Marion
|
|
|
|
|
This maybe an easy question.. How do I write a function that can return a pointer to a CArray or a structure?
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Either pass in a pointer to a CArray and fill it in the function, or allocate a new CArray from the heap and return a pointer to it (don't forget to delete it!). EX:
METHOD 1:
void SomeFunc()
{
CArray oArray;
ArrayFunc(&oArray);
}
void ArrayFunc(CArray *pArray)
{
pArray->Add(?);
pArray->Add(??);
}
METHOD 2:
void SomeFunc()
{
CArray *pArray = ArrayFunc();
if (pArray)
{
// do something with it...
delete pArray;
}
}
CArray *ArrayFunc()
{
CArray *pRetval = new CArray;
if (pRetval)
{
pRetval->Add(?);
pRetval->Add(??);
}
return pRetval;
}
<span style="border: 2px outset silver;background-color:yellow;color:green;font-family:Verdana,Arial;font-size:8pt;font-style:italic"> onwards and upwards... </span>
|
|
|
|
|
Thanks for the quick reply!! I knew I was doing something stupid
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
basically, it's easy:
CArray * GetMyArray()
{
CArray * newArray = new CArray;
newArray->SetSize(yadda);
...
return newArray;
}
However, to allocate memory inside the class, and requiring the caller to free it, is often a bad idea. If possible wrap he resource in a class, or use a smart pointer to a reference-counted class.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
I have an IOCP based server. Currently the sockets are in blocking mode, but I want to change them to non-blocking. Is there any known ill-effects of using overlapped reads and writes, IOCP, and non-blocking sockets?
Note: I googled and went through MSDN, and could not find anything that discusses this combination. Now, I need experienced people to guide me
Thank you.
Thomas
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thomas George wrote:
Is there any known ill-effects of using overlapped reads and writes...
As long as they are not to/from the same memory address.
|
|
|
|
|