|
v2.0 wrote: int() creates a new int instance calling the int copy constructor.
int is an integral type, not a class. How can it have a constructor, or even a method?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
even intregral types can be considered - due to the fact that C++ is an OO language - like a class... of course, there are restrictions to this, but int() and (int) are not identical in theory...
|
|
|
|
|
v2.0 wrote: even intregral types can be considered...like a class
How so, and why would you want to? No OO-specific topics relate to them (e.g., they can't be inherited from).
v2.0 wrote: ...but int() and (int) are not identical in theory...
Which implies they are identical in practice. Yes?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: No OO-specific topics relate to them (e.g., they can't be inherited from).
i said there were limitation, not that all OO topics were applying.
DavidCrow wrote: Which implies they are identical in practice. Yes?
hum, looking at the assembler generated, i must agree that both are identical for the processor, but i still believe that it remains a compiler specificity
|
|
|
|
|
Page 70,
$ 5.2.3 Explicit type Conversion
1. A simple-type-specifier (7.1.5) followed by a parenthesized expression-list constructs a value of the specified type given the expression list. If the expression list is a single expression, the type conversion expression is equivalent (in definedness, and if defined in meaning) to the corresponding cast expression (5.4). If the simple-type-specifier specifies a class type, the class type shall be complete. If the expression list specifies more than a single value, the type shall be a class with a suitably declared constructor (8.5, 12.1), and the expression T(x1, x2, ...) is equivalent in effect to the declaration T t(x1, x2, ...); for some invented temporary variable t, with the result being the value of t as an rvalue.
Maxwell Chen
|
|
|
|
|
ok, thanks Maxwell, that's more clear now.
|
|
|
|
|
Sometimes I need to display a bitmap much smaller then its original size, by using the StretchBlt API I get sadly ugly outcomes, I've noticed many picture-viewer applications have the ability of stretch-displaying pictures while maintaining high quality, some of them(IE 6.0, etc) can even do that job absolutely perfect. I wonder if I too can implement that in my own projects? Any help are appreciated.
|
|
|
|
|
for starters, see SetStretchBltMode
if that doesn't do it, you'll need to explore the world of image resizing algorithms and resize the image yourself. i hear there are toolkits out there to help with this.
=[ Abin ]= wrote: some of them(IE 6.0, etc) can even do that job absolutely perfect
no method is perfect. the best you can hope for, especially when enlarging, is adequate.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
i want to create a button which actully create in DLL and set in my dialog(which is executable)
how it is possible.
Bankey Khandelwal
Software Engineer
|
|
|
|
|
Use MFC Extended DLL.
Fly Like An Eagle With MIGHTY POWER.
|
|
|
|
|
Hi,
I have a custom combobox derived from CWnd.
I want to use this control with DDX_Control.
The combobox have a child control member m_Edit (CEdit).
Where can i call the m_Edit Create function?
|
|
|
|
|
Hi zuma77,
Do you need to insert Edit to Combobox?
|
|
|
|
|
Hi WhiteSky,
No, the Combobox have an Edit (if the style isn't CBS_DROPDOWNLIST),
and a dropdown list.
I call the Edit Create in the OnCreate of the Combobox,
but if i use DDX_Control to create Combobox, than the OnCreate function
in not called.
Where can i call the the edit create function in this case?
|
|
|
|
|
zuma77
Hope I understood your question
I see you use DDX_Control then (I think)you can't use Oncreate for create edit
I suggestion(Im not sure that is very good) you enter your code in the
function in classs derived(ccombobox) but with one if (if m_Eidt.m_hwnd==NULL then create)
|
|
|
|
|
Thanks for your help.
The PreSubclassWindow function was the key.
|
|
|
|
|
DDX_Control calls SubclassDlgItem for an existing control. In this case, the control has already been created. You will need to locate and subclass the edit control.
Software Zen: delete this;
|
|
|
|
|
Thanks for your help.
It works now
|
|
|
|
|
Hi,
How to simulate DoEvents() function of Visual Basic in Visual C++? Please help if you know.
|
|
|
|
|
Something might work
void DoEvents()<br />
{<br />
MSG dispatch;<br />
while (::PeekMessage( &dispatch, NULL, 0, 0, PM_NOREMOVE))<br />
{<br />
if (!AfxGetThread()->PumpMessage());<br />
}<br />
}
|
|
|
|
|
|
|
i am defining a bunch of exception classes from a dll that are supposed to be thrown from within the DLL code to the GUI which loaded the dll.
it seems that i'm having trouble with the STL std::string::c_str() function when releasing its string.
here is my code :
DLL Exceptions header :
<font color=blue>#ifdef</font> VCALCPARSER_EXPORTS
<font color=blue>#define</font> VCALCPARSER_API <font color=blue>__declspec</font>(<font color=blue>dllexport</font>)
#else
<font color=blue>#define</font> VCALCPARSER_API <font color=blue>__declspec</font>(<font color=blue>dllimport</font>)
<font color=blue>#endif</font>
<font color=blue>#include</font> <STRING> <font color=green>
<font color=blue>class</font> VCALCPARSER_API CVCalcParserException {
<font color=blue>protected</font>:
ExceptionNumbers m_enExceptionNumber;
std::string m_strExceptionMsg;
<font color=blue>long</font> m_iErrorPos;
CVCalcParserException(ExceptionNumbers enExceptionNumber,
<font color=blue>const</font> std::string& strExceptionMsg,
<font color=blue>int</font> iErrorPos);
<font color=blue>public</font>:
<font color=blue>virtual</font> ~CVCalcParserException();
ExceptionNumbers GetExceptionNumber();
std::string GetMessage();
<font color=blue>long</font> GetErrorPos();
};
<font color=blue>class</font> VCALCPARSER_API CSyntaxException : <font color=blue>public</font> CVCalcParserException {
<font color=blue>protected</font>:
CSyntaxException(ExceptionNumbers enExceptionNumber,
const</font> std::string& strExceptionMsg,
<font color=blue>int</font> iErrorPos);
<font color=blue>public</font>:
<font color=blue>virtual</font> ~CSyntaxException();
};
<font color=blue>class</font> VCALCPARSER_API CMathematicExpressionExpectedException : <font color=blue>public</font> CSyntaxException {
<font color=blue>public</font>:
CMathematicExpressionExpectedException(<font color=blue>int</font> iErrorPos);
~CMathematicExpressionExpectedException();
};
then, when an such an error occurs (Mathematic expression expected), i send this exception :
VALUES_TYPE CVCalcParser::Evaluate(<font color=blue>const</font> std::string& strSource)
<font color=blue>throw</font>(CVCalcParserException) {
<font color=blue>this</font>->ResetParserMembers(strSource);
<font color=blue>try</font> {
VALUES_TYPE valResult = <font color=blue>this</font>->Level_1();
<font color=green></font>
}
<font color=blue>catch</font> (CVCalcParserException) {
<font color=blue>throw</font>;
}
<font color=blue>catch</font> (...) {
<font color=blue>throw</font> CUnknownException(0);
}
}
VALUES_TYPE CVCalcParser::Level_1(<font color=blue>void</font>)
<font color=blue>throw</font>(CVCalcParserException) {
VALUES_TYPE valLeftOperand = <font color=blue>this</font>->Level_2();
<font color=green></font>
}
VALUES_TYPE CVCalcParser::Level_2(<font color=blue>void</font>)
<font color=blue>throw</font>(CVCalcParserException) {
VALUES_TYPE valLeftOperand = <font color=blue>this</font>->Level_3();
<font color=green></font>
}
VALUES_TYPE CVCalcParser::Level_3(<font color=blue>void</font>)
<font color=blue>throw</font>(CVCalcParserException) {
VALUES_TYPE valLeftOperand = <font color=blue>this</font>->Level_4();
<font color=green></font>
}
VALUES_TYPE CVCalcParser::Level_4(<font color=blue>void</font>)
<font color=blue>throw</font>(CVCalcParserException) {
VALUES_TYPE valLeftOperand = <font color=blue>this</font>->Level_5();
<font color=green></font>
}
VALUES_TYPE CVCalcParser::Level_5(<font color=blue>void</font>)
<font color=blue>throw</font>(CVCalcParserException) {
VALUES_TYPE valLeftOperand = <font color=blue>this</font>->Primary();
<font color=green></font>
}
VALUES_TYPE CVCalcParser::Primary(<font color=blue>void</font>)
<font color=blue>throw</font>(CVCalcParserException) {
<font color=blue>this</font>->GetToken();
<font color=blue>switch</font> (<font color=blue>this</font>->m_tokCurrentToken) {
<font color=blue>case</font> ...:
<font color=green></font>
<font color=blue>default</font>:
<font color=blue>throw</font> CMathematicExpressionExpectedException(<font color=blue>this</font>->m_iCurrentIndex);
}
}
and at last, i catch this exception thrown from the dll in my GUI MFC project :
<font color=blue>void</font> CVisualCalcDlg::OnCalculate() {
CString strSource, strDest;
m_peInput->GetWindowText(strSource);
<font color=green>
<font color=blue>try</font> {
VALUES_TYPE valResult = m_Parser.Evaluate((LPCTSTR)strSource);
<font color=green></font>
}
<font color=blue>catch</font> (CSyntaxException& ex) {
strDest.Format(<font color=gray>"Syntax error %d : %s"</font>, ex.GetExceptionNumber(), ex.GetMessage().<code>c_str()</code>);
m_peInput->SetSel(ex.GetErrorPos(), ex.GetErrorPos());
}
<font color=blue>catch</font> (...) {
strDest.Format(<font color=gray>"Unknown parser internal error"</font>);
}
<font color=green></font>
}
when i look at the call stack, i see that the destructor of the std::string object is call at that point (it didn't leave the scope yet), and sope other functions are called down, until i get a dark message, that seems to say that i have a pointer that's been invalidated.
when i put a breakpoint on the line which contains that c_str() call and watch the ex exception object, all his datas (exception description message, position and error code) are correctly set.
i'm really stuck about that, because that behavior weren't happening when the code that i moved in the DLL was in the same project as the GUI.
any hint anybody ?
|
|
|
|
|
Probably what's happening (not sure at all) is that the string is allocating dynamically memory for its internal purpose. Then, when firing the exception, it will be catched in your exe and upon calling the destructor of this string, it will try to delete this memory. Unfortunately, as it hasn't been allocated by the same module (by the dll and not by your exe) this will crash.
But this is difficult to understand because you don't know how it works internally. A thing is sure: when you allocate memory in a dll and try to delete it inside your exe, this will crash the program. That's why classes exported from a dll have a Destroy method (it is just a delete this).
But here, I don't know how it works when an exception is fired...
|
|
|
|
|
hum, so you suggest me to have a Destroy() function in each my classes exported by the DLL ?
anyway, this seems to be much complicated, so i ask you a favour : can i send you the sources by email ?
thank you very much.
|
|
|
|
|
v2.0 wrote: hum, so you suggest me to have a Destroy() function in each my classes exported by the DLL ?
No, sorry, you misunderstood what I was saying (I took that just as an example).
I'm still thinking hard about what's happening here. One thing is almost sure: the string allocates memory dynamically for its own purpose. Now, as it is a template, I think (but at this point, my brain give me headache ) that the memory will be freed by your application when destructor is called. But at this point, I'm not sure. But if this is the case, this is what is causing the crash.
Can you tell me at which point the program breaks (I know it will be in a specific file). So give me the file and the line number. I have VC2005 installed so chances are that the files will be different. Can you post some code around the crashing point ?
That will help me to check if I'm right or not.
Otherwise I'm thinking of a solution but I don't find one right now. I'll keep searching
|
|
|
|