|
|
I am struggling with an issue. I have a client on who's machine, when a CFrameView derived class comes up, (3 do this) shuts down the app without a message of any kind. The code is now using VC++.net 2003 and the problem surfaced in an older version originally built in VC++ 6
I think I know what is happening. In the base classes if Create returns -1, it puts a message in the message que sutting down the app.
Initially the app started shutting down in a CWin derived splash window due to the same issue, I got that straightened out, but the situation seems to be a bit more pervasive
Does anyone have a clue, what causes -1 to be returned by window creation code?
This app runs fine on many other machines, and has been reliable for quite a while, two of these classes are those that I draw custom on, the other uses the CHTMLView and uses a locally created html file.
Christopher J. Noyes
|
|
|
|
|
Ive got a self made class called Vessel which is a base class for the classes Surface Vessel and Submarine.
The base class holds the data needed for both submarines and surface vessels and then the submarines and surface vessels have thier own data and functions.
Now i have tried to do a linked list where the data in the node is a "Vessel". I can pass a surface vessel or a submarine into this but when i try to get the data back out it loses the inherited class specificities (is that even a word? lol) so i can only access the Vessel data for that particular surface vessel or sub and not the particulars of that class. How can i put a surface vessel or sub into a type "vessel" and get the specific data out again or perhaps change the node data to a sv or sub on the fly?
Cheers
Bill
|
|
|
|
|
Add (pure) virtual functions that return desired information to Vessel, and override them in SurfaceVessel and Submarine.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
so when i assign a sub to the variable of type Vessel its still holding it as a sub but just cant see the functions / data?
-- modified at 13:31 Sunday 23rd April, 2006
heres the vessel class so how could i impliment the pure functions in them because vessel would have to be totally abstract would it not?
Cheers
#ifndef VESSEL_H
#define VESSEL_H
#include <string>
#include "afxwin.h"
using namespace std;
class Vessel
{
protected:
int _prKey;
int _maxSpeed;
CString _name;
int _length;
int _maxRange;
int _maxDisplacement;
int _crewAmount;
CString _vesselType;
public:
int getKey();
void setKey(int pKey);
int getSpeed();
void setSpeed(int pSpeed);
CString getName();
void setName(CString pName);
int getLength();
void setLength(int pLength);
int getRange();
void setRange(int pRange);
int getDisplacement();
void setDisplacement(int pDisplacement);
int getCrew();
void setCrew(int pCrew);
CString getType();
void setType(CString pType);
};
class SurfaceVessel : public Vessel
{
protected:
int _helicopters;
public:
int getHeli();
void setHeli(int pHeli);
};
class AircraftCarrier : public SurfaceVessel
{
int _aircraft;
public:
int getAircraft();
void setAircraft(int pAircraft);
};
class Destroyer : public SurfaceVessel
{
bool _gunSystem;
bool _guidedMissileSystem;
public:
bool getGunSystem();
bool getGuidedSystem();
void setGunSystem(bool pGunSystem);
void setGuidedSystem(bool pGuidedSystem);
};
class FleetAux : public SurfaceVessel
{
protected:
int _deckSpace;
public:
int getDeckSpace();
void setDeckSpace(int pDeckSpace);
};
class Submarine : public Vessel
{
protected:
int _maxDiveDepth;
int _maxSubmergedSpeed;
int _displacementSubmerged;
public:
int getMaxDiveDepth();
int getSubSpeed();
int getDisplacementSub();
void setMaxDiveDepth(int pMDD);
void setSubSpeed(int pSubSpeed);
void setDisplacementSub(int pDisSub);
};
class SSB : public Submarine
{
int _slbms;
public:
int getSLBMS();
void setSLBMS(int pSLBMS);
};
class SSK : public Submarine
{
int _torpedoes;
public:
int getTorps();
void setTorps(int pTorps);
};
class Tanker : public FleetAux
{
int _storageCapacity; //Litres
public:
int getStorCap();
void setStorCap(int pStorCap);
};
class LandingPlat : public FleetAux
{
int _storageCapacity; // M^3
int _aircraftLand;
public:
int getStorCap();
void setStorCap(int pStorCap);
int getAircraftLand();
void setAircraftLand(int pAirAmount);
};
#endif
-- modified at 13:56 Sunday 23rd April, 2006
|
|
|
|
|
How are you placing the Vessels into the list?
If you are declaring the list to hold whole Vessel types, then that is what is well do. Which means it will only hold the part that represents the base vessel, basicaly slicing off every thing else.
list<Vessel> myList;
You need to store pointers to the base type Vessel in the list. Also remember that you will be responsible for deleting them when they are removed from the list and before the list is destroyed.
list<Vessel*> myList;
INTP
“Testing can show the presence of errors, but not their absence.”
Edsger Dijkstra
|
|
|
|
|
ahh i am basically just passing them in and obviously its being sliced because im only holding the data temporarily when its inputted by the user then it is stored in the nodes Vessel variable. Does this mean that i will have to have make a variable of each type in order to store any type?
Thanks
|
|
|
|
|
William Burton wrote: Does this mean that i will have to have make a variable of each type in order to store any type?
No. A base class pointer can point to any of it's derived class. When mixed with virtual functions you can ensure that the function in the correcct derived class is called even when invoked through a base class pointer.
Steve
|
|
|
|
|
the thing is that in my nodes in my linked list the data is held as a Vessel so if i used a pointer instead of a variable, i would have to declare the variable in the program and not in the class. At the minute im using a temporary variable declared depending on whether a sub or a surface vessel is made and then it assigns the temporary variable to the class variable. If i used a pointer to point to the temporary variable, if i tried to make another of the same type it would overwrite the old temporary variable would it not and therefore the previous node and pointer to the original values in the temporary variable would be worthless?
|
|
|
|
|
Can you show the code with this "temporary variable"?
Steve
|
|
|
|
|
if(_addtodb.DoModal() == IDOK)
{
UpdateData(true); // Retrieve Current Values
_addtodb._comboContent.MakeUpper();
if (_addtodb._comboContent == "SSB SUBMARINE")
{
SSB temp;
temp.setType("SSB Submarine");
temp.setKey(list.getNodeAmount());
temp.setName(_addtodb._vesselName);
temp.setSpeed(_addtodb._vesselMaxSpeed);
temp.setLength(_addtodb._vesselLength);
temp.setRange(_addtodb._vesselMaxRange);
temp.setDisplacement(_addtodb._vesselMaxDisplacement);
temp.setCrew(_addtodb._vesselCrew);
temp.setMaxDiveDepth(_addtodb._vesselMaxDiveDepth);
temp.setSubSpeed(_addtodb._vesselMaxSpeedSubmerged);
temp.setDisplacementSub(_addtodb._vesselDisplacementSubmerged);
temp.setSLBMS(_addtodb._vesselSLBMS);
list.addNode(&temp);
}
else if (_addtodb._comboContent == "SSK SUBMARINE")
{
SSK temp;
temp.setType("SSK Submarine");
temp.setKey(list.getNodeAmount());
temp.setName(_addtodb._vesselName);
temp.setSpeed(_addtodb._vesselMaxSpeed);
temp.setLength(_addtodb._vesselLength);
temp.setRange(_addtodb._vesselMaxRange);
temp.setDisplacement(_addtodb._vesselMaxDisplacement);
temp.setCrew(_addtodb._vesselCrew);
temp.setMaxDiveDepth(_addtodb._vesselMaxDiveDepth);
temp.setSubSpeed(_addtodb._vesselMaxSpeedSubmerged);
temp.setDisplacementSub(_addtodb._vesselDisplacementSubmerged);
temp.setTorps(_addtodb._vesselTopedoes);
list.addNode(&temp);
}
as a small example from my main prog, there are more elseifs too for other types chosen
|
|
|
|
|
I can see a number of problems here. One of them is the following usage pattern:
{
SSK temp;
list.addNode(&temp);
}
To fix this problem use code like this:
SSK pTemp = new SSK;
list.addNode(pTemp);
Now the pointer in "list" doesn't outlive the object it points to (when it does the pointer is known as a "dangling pointer").
You have to remember to delete the object you new ed when you no longer need it: with new you manage the lifetime of the object explicitly. For example to empty "list" and delete all the objects it contained you can use code like this:
template <typename T>
struct Delete_Object
{
bool operator()(T *pObj) const
{
delete pObj;
return true;
}
};
for_each(list.begin(), list.end(), Delete_Object<Vessel>());
list.clear();
Finally because we're calling delete on the base class but the actual object is of a derived type the descructor has to be virtual:
class Vessel
{
public:
virtual ~Vessel()
{
}
};
Steve
|
|
|
|
|
John R. Shaw wrote: “Testing can show the presence of errors, but not their absence.”
Edsger Dijkstra
For what its worth, Dijkstra's quote is actually:
"Program testing can be used to show the presence of bugs, but never to show their absence."
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
Thanks David, I knew I should have checked.
The quote came from one of my new class mates who insured me that it was accurate and that I did not need to verify the source, since he wrote a paper on the author.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
As Ronald Reagan once said, "Trust but verify."
Back when I was in college, Prof. Dijkstra came and gave a colloquium. It was intense, but I do remember him having a slight bit of humor, too.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
Hi, I have a quick question on the printing:
I have a VC++ 6.0 application that prints labels on the label paper. In my printer (Canon i550), it prints properly within the dimension of the label. The way I print from the application is that I use GetPrinterDC() and attach it to CDC and then do TextOut to print at certain location.
It prints correctly on my printer however when I tried to print on a different printer (Epson), the font became slightly bigger and the contents go out of the specified label area.
What do I do to fix this issue?
Here is the code that print:
CDC dc;
dc.Attach(printdlog.GetPrinterDC());
DOCINFO docinfo;
memset(&docinfo,0,sizeof(docinfo));
docinfo.cbSize = sizeof(DOCINFO);
docinfo.lpszDocName = "Labels"; // document name for the spooler
CFont f;
f.CreateFont(54,0,0,0,100,0,0,0,0,0,0,ANTIALIASED_QUALITY,0,"Arial");
dc.SelectObject(f);
if (dc.StartDoc(&docinfo) > 0)
{
dc.StartPage();
dc.SetMapMode(MM_TEXT);
dc.TextOut(i_Width-120, i_Height, m_Tit);
.
.
.
Thanks for your help,
JK
|
|
|
|
|
You can use GetTextExtent to see how 'wide' your text will be. If it is too wide for the label, then recreate the font with a smaller height so that it will fit on the label.
You are merely being subjected to the different interpretations of the fonts within the different printers.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Hi,
i want to extract a zip file for which i used ShellExecute()
from my VC++ program. since it is a password protected zip file i had to pass that password too to that function.but when i do that i got the error as
Winzip parameter validation error.
the code i used is
ShellExecute(NULL, "open", "winzip.exe", "-e -s"+bcs+" E:\\bcs.zip","C:\\extract\\here", SW_SHOWNORMAL);
where bcs is my password.
im not sure whether ShellExecute() is the appropriate fn for this.if anyone can suggest another method, please help me
lekshmi
|
|
|
|
|
|
hi
i just want to pass it thru the ShellExecute().
or is there any other methods by which i can do that?
lekshmi
|
|
|
|
|
you build a command line as described in the page i've sent you, and pass it to shell execute...
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
hi
thank you for the sudden reply
i am new to VC++.can you give me a mall example to build a command line.
thanks in advance.
|
|
|
|
|
it has nothing to do with vc++....
look at what you wrote :
ShellExecute(NULL, "open", "winzip.exe", "-e -s"+bcs+" E:\\bcs.zip","C:\\extract\\here", SW_SHOWNORMAL);
You already gave a command line ("-e -s"+bcs+" E:\\bcs.zip") just add the proper password command line ....
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Open a command line box and do it manually then use that for your ShellExecute values.
It might be worth copying the command line to a window so you know that you have generated the correct comand line.
Elaine
The tigress is here
-- modified at 12:06 Sunday 23rd April, 2006
|
|
|
|
|
lekshmipriya wrote: ShellExecute(NULL, "open", "winzip.exe", "-e -s"+bcs+" E:\\bcs.zip","C:\\extract\\here", SW_SHOWNORMAL);
Shouldn't -e be one of -ex, -en, -ef, -es, or -e0?
Is bcs the actual password, or is it a variable containing the password?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|