|
Thanks Vimal.
You make a lot of sense and you are correct. However, I had done just what you recommended before posting the note, and everything did work for me.
But when examined, overloading the stream insertion operator "<<" didn't looked like it bought me anything, because I could have obtained the same result if I had not used constructor conversion and had done things the regular way, using an "int" instead for my print() parameter.
I figured as part of the ctor conversion technique, one of the benefits I would obtain, would be NOT having to overload the "<<" operator. Secondly (and this is the part that made me refused to give up), I thought somebody might know of a way (that I didn't) to make what I was trying to achieve, work.
I thank you for your response because it tells me what I was dreaming of doing, will just not work.
Thanks again!
William
Fortes in fide et opere!
|
|
|
|
|
Try changing the print to take a reference:
void print (Number &nbr)
|
|
|
|
|
Friends, i am doing something like:
using namespace std;
hash_set<string> myhashstring;
myhashstring.insert("USA");
As such program is giving me error that:
(38): error C2440: 'type cast' : cannot convert from 'const std::string' to 'size_t'
But if i use "set" instead of "hash_set" the program works normally. Any one guess whats the problem ???
|
|
|
|
|
hash_set is a container. In your code, you did not include the correct template parameters.
http://www.sgi.com/tech/stl/hash_set.html
Kuphryn
|
|
|
|
|
I try to make a CComboBox dynamically which have owner draw.
first, I tried it myself.
It compiled ok, but "Unhandled Access Violation" when execute.
So, I find exercises about ComboBox which have owner draw in CodeProject and Codeguru.
Though So many exercies are, they are not dynamically, but static in dialog
How can I Create CComboBox dynamically which have owner draw?
to be Ace.
|
|
|
|
|
Kindly tell what is a #pragma and why is it a must to use it at some places
Gaurav Gumber
|
|
|
|
|
#pragma gives commands to the compiler. The ones I commonly use are pack to change how struct members are arranged in memory, and comment(lib) to make the linker use a particular import LIB file.
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
I would like to achive the following:
91.26464 --> 91.26 (2 digits after the floating point at most)
91.20464 --> 91.2 (because of the 0 at the second position)
91.00464 --> 91 (first 2 digits sfter the floating point are 00)
I tried to use setpresicion and setiosflags but it seems I don't know how to get these results.
-----------------------
Go USA Go
|
|
|
|
|
I have a vexing problem related to CListCtrls and in-place edit.
Very standard stuff here, the CListCtrl is on CPropertyPage.
Inplace editing is called for 4 SubItems/Columns and works perfectly however when
SubItems greater than 0 are dblClicked (i.e list.EditLabel() & OnBeginLabelEdit) the ListItem in column 0 becomes blank until editing is complete (i.e OnEndLabelEdit) when all is restored and OK.
Somehow the SubClassed EditCtrl Overwrites the list.Item before being repositioned over SubItem?
DWORD dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_CHILDRES
WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | LVS_EDITLABELS ;
DWORD dwEXStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | WS_EX_CLIENTEDGE;
======OnBeginLabelEdit Handler========
CRect rc;
c_List.GetSubItemRect(iItem, iSubItem, LVIR_LABEL, rc );
HWND hWnd = (HWND)c_List.SendMessage(LVM_GETEDITCONTROL);
ASSERT(hWnd != NULL);
VERIFY(m_SubClassedCEdit.SubclassWindow(hWnd));
ASSERT(::IsWindow(m_SubClassedCEdit.m_hWnd));
m_SubClassedCEdit.m_Rec = rc;
m_SubClassedCEdit.SetWindowText(c_List.GetItemText(iItem, iSubItem));
=========================
It must be obvious but I cannot see it. I have tried Invalidating the item, the list ...?$#
Anyone have a working example of item/subitem in-place edit of CListCtrl?
If there are any kind souls out there - please help
Regards In Advance
Bonnie
|
|
|
|
|
While I was looking at an example of class operations I saw something I never seen before. Where the constructor for class Position is declared there is a “:x(xx),y(yy)” statement and I can’t understand what it is doing. I seems like it is using float x and y as functions, and this even before the “{}”. Please explain this statement, what it does, how it does it, what else strange statements like this you can do and if there is any where I can read more about this?
#include<iostream.h><br />
<br />
class Position {<br />
float x,y;<br />
public:<br />
Position(float xx, float yy=0):x(xx),y(yy) {}<br />
Position operator + (const Position& e) const;<br />
Position operator - (const Position& e) const;<br />
<br />
void Display(void)<br />
{ cout << "(" << x << ", " << y << ")" << endl; }<br />
void Input(void)<br />
{ cout << "enter x och y:"; cin >> y;; }<br />
};<br />
<br />
Position Position::operator + (const Position& e) const<br />
{<br />
Position res = *this;<br />
res.x += e.x;<br />
res.y += e.y;<br />
return (res);<br />
}<br />
<br />
Position Position::operator - (const Position& e) const<br />
{<br />
Position res = *this;<br />
res.x -= e.x;<br />
res.y -= e.y;<br />
return (res);<br />
}
Aidman » over and out
|
|
|
|
|
|
Hi,
I've overide a WM_KEY and WM_GETDLGCODE of an CEdit to know when the user presse "enter" key like this :
UINT CMyEdit::OnGetDlgCode()
{
return DLGC_WANTALLKEYS;
}
void CMyEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar==0x0000000d)
Funtion();
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
this way, i can call Function() when user press "enter"... Unfortunalty, there is a "bip" (sound system) when the "enter" key is pressed...
Does anyone know how to disable this "bip" ??
Thanks yyou veru much
|
|
|
|
|
I am writing a C++ DLL which will be called by Visual Basic for Applications in Excel. Should I be using BOOL vs. bool as the type of arguments passed to/from the DLL. For some reason bool doesn't work ... Both C++'s true and false are interpreted as True in VB. Does anyone know why?
Is bool just a 1-byte character whereas BOOL is like an int? What is Boolean type in VB equivalent to in C++?
|
|
|
|
|
Anton A. Loukine wrote:
Should I be using BOOL vs. bool
BOOL
and tell the VB users to use a Long on their end.
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|
So BOOL is a 32-bit integer?
|
|
|
|
|
Anton A. Loukine wrote:
So BOOL is a 32-bit integer?
yep.
it's #define'd as int or long, depending on which set of #include files you happen to pick up. but they're both 32 bits in Win32.
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|
You should be using VARIANT_BOOL , which is a 2-byte type and the VB/VBA version of a boolean. Use the two constants VARIANT_TRUE and VARIANT_FALSE for the values.
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
I am currently trying to perform a mathematical addition on two strings. I was curious if there were any built-in functions available for this. If not that is okay. Thx for any help.
|
|
|
|
|
Hi,
I've written a small application, very basic, that works on Windows Me, Windows XP and Windows 2000, but (I am told) crashes with the error "abnormal program termination" in Windows 98. The program uses the common control progress bar (and uses Initcommoncontrolsex etc to set it up), a ZipArchive library, and not really much more. I can't see why I might be getting this error.
I'm a fairly inexperienced programmer, so if somebody could tell me where I might start looking (the types of things I need to look at) in my program, or the general things that might cause a crash on Win98 where it works on other systems, I would be really grateful.
Thank you,
Keith B.
|
|
|
|
|
First check if it crashes on more than one Win98 system. The problem may be related to the user's PC which just happens to run Win98, and not Win98 itself. I'd look for missing files that the program expects to find. It's possible that you may not have adequate error recovery in your code.
For example, stuff like this is dangerous:
FILE* fp = fopen ("C:\\file.dat");
char szLine [256];
fgets (szLine, 255, fp);
fclose (fp);
It's safer to do:
FILE* fp = fopen ("C:\\file.dat");
if (fp == NULL)
displayError();
else {
char szLine [256];
fgets (szLine, 255, fp);
fclose (fp);
}
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi,
Thanks for the reply. I have done as you suggested and added a lot more error checks, and sent the executable out for more testing (hopefully it will at least spew up a more helpful error message that way, thanks for the suggestion). I still don't understand it, though, as I've tested it on a Windows 95 system and it works fine. I can't quite understand why it would work on Windows 95 and Windows Me, but not on Windows 98 - and a couple of Win98 systems have been tested, so it seems that it's not just the user's PC...
Many thanks,
Keith
|
|
|
|
|
Keith, the problem may be with Zip library you're using. Check the vendor's site (assuming it's a commercial product) for release notes regarding Win98.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi Ravi,
Thanks again for the help. I have now located the problem but haven't figured out how to fix it yet. The problem lies with password encrypted zip files. If the zip files that are extracted aren't password encrypted, they work fine on Win98. If they are, they spew the error. So far I don't know if this has to do with the zip library I'm using (I don't think so, as it is supposed to be compatible with Win98 - it is the one from http://www.artpol-software.com), or with the password encryption I'm using. I'm using cryptography.cpp and cryptography.h, which use the Windows CryptoAPI (got them from Planet Source Code), to encrypt the password and store it in an INI file. The program then reads the encrypted password, converts it and passes it to the Zip...
I doubt posting the code will help as it's very specific (relying on cryptography.cpp and .h and the zlip library from artpol software), but I'll post it just in case. The code I am using is really straight out of the example files (I do a GetPrivateProfileString for Password_str, the default being "NO_PASSWORD_DEFINED"):
//Open the Zip file:
CZipArchive zip;
zip.Open(ZipFile_str);
//If there is a password, decrypt and set it:
if(strcmp(Password_str,"NO_PASSWORD_DEFINED")!=0)
{
//DECRYPT PASSWORD FOR ZIP FILE:
char *sUnencrypted;
clsCryptography MyCrypt;
//Decrypt data:
MyCrypt.bDecryptData(Password_str, "zE76c78cae9opzz231fx" );
// Allocate enough memory to hold unencrypted value
sUnencrypted = new char[MyCrypt.lGetBufferLength() + 1];
// Store unencrypted value in variable
strcpy( sUnencrypted, MyCrypt.sGetBuffer() );
//Pass the decrypted password into the ZIP file:
zip.SetPassword(MyCrypt.sGetBuffer());
delete[] sUnencrypted;
}
Many thanks,
Keith
|
|
|
|
|
According to the documentation, memcpy does not guarantee the result if the source and destination overlap; on the other hand, memmove will graciously handle the case, by coping first the overlapping region.
Consider the following example :
char szTempCpy[] = "this is the most reliable test";
char szTempMov[] = "this is the most reliable test";
memcpy( szTempCpy + 5, szTempCpy, 25);
memmove( szTempMov + 5, szTempMov, 25);
printf("memcpy : %s\nmemmove : %s\n", szTempCpy, szTempMov);
Now, when this is compiled in release you will get the correct behavior : memcpy will trash the data ( the ouput is "this this this this ...") and memmove will get it right ( "this this is the most ...").
The surprise comes when you compile debug : both memcpy and memmove will yield the same result ( the correct one ) - "this this is the most ...". Does anybody have a good explanation for this ?
|
|
|
|
|
the memcpy function has this little bit at the front:
; Check for overlapping buffers:
; If (dst <= src) Or (dst >= src + Count) Then
; Do normal (Upwards) Copy
; Else
; Do Downwards Copy to avoid propagation
mov eax,ecx ;V - eax = byte count...
mov edx,ecx ;U - edx = byte count...
add eax,esi ;V - eax = point past source end
cmp edi,esi ;U - dst <= src ?
jbe short CopyUp ;V - yes, copy toward higher addresses
cmp edi,eax ;U - dst < (src + count) ?
jb CopyDown ;V - yes, copy toward lower addresses
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|