|
Thank you Roger, the qoute form MSDN makes perferct sense now
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Take the function void foo(unsigned char * param) . It does not change the value of the string (it's a Win32 API function, don't ask me why it's not const). Now i'd like to pass it the value of std::string MyString . I do this liek that
foo(reinterpret_cast<unsigned char *>(MyString.c_str()));
but this can hardly be the recommended way (it works, but it's bad). Any suggestions anyone ?
|
|
|
|
|
why not the simple static_cast ?
i can't see anything wrong otherwise...
|
|
|
|
|
static_cast gives a compiler error:
error C2440: 'static_cast' : cannot convert from 'const char *' to 'unsigned char *'
|
|
|
|
|
hum, yes, that's right (i have no compiler with me at the moment...).
does it work without any explicit cast ?
|
|
|
|
|
You cannot cast a 'const' value to a 'non-const' because that's the whole point of the 'const' keyword.
In this case you have to make a copy of the string and provide the second function with the copy.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
You want const_cast.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Dear All,
How can i read a binary data from the registry ?
Thanks.
|
|
|
|
|
There's articles and classes on this site, and all over the web, which answer this question.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Use REG_BINARY with RegQueryValueExv() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Hi all,
Will somebody advise me
1. how to build a C++ debugger or at least an rough architecture of a debugger?
2. what is the mechanism behind for a debugger to determine a breakpoint set by user is valid?
Appreciate your help....
br
Vincent
|
|
|
|
|
this[^] could be starting point.
|
|
|
|
|
hai ,
I am creating a set up dialog using InstallShield12.I wrote InstallScript for this.But some Issues/I want to add some text into it.But when i add a piece of text using these methods
hItem2=GetDlgItem(hDlg, STATIC_TEXT_ID);
SetWindowText(hItem2, "First");
SetWindowLong(hItem2, GWL_STYLE, nStyle1);
SetWindowPos(hItem2, NULL, 60,60,20,25, SWP_DRAWFRAME | SWP_SHOWWINDOW |SWP_NOSIZE|SWP_NOZORDER );
But only one line text is created ,
I want to add two sets of data.So I repatedly specifying the above code,
But either the first one or second one is displaying,
That is in the hItem having value at a single time only.
can anybody help me plz.....................
Jeeva
|
|
|
|
|
Jeeva Mary Varghese wrote: But only one line text is created
Be sure the ES_MULTILINE style is set when creating the edit control.
Besides that, your sample code obviouly only displays "First", which is indeed one line of text.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
Hi,
does anybody know how to resize a control or a CFormView view which contains the control when the view is nested in a CSplitterWnd Pane? I want the control to adapt its size when the size of the splitter window changes.
Thanks,
Frank.
|
|
|
|
|
I think you should add to your form a handler for WM_SIZE message (i.e. OnSize function) and do the adjustments of child controls here.
|
|
|
|
|
Thank you, it works. As in all other resizing dialogs. I don't know, why I've got problems with this. Somehow I thought that my CMDIChildFrame should handle the WM_Size message.
|
|
|
|
|
Hai all,
I have a dialog based programme.
-> I have Created CCustomStatic from CStatic using class wizard.
-> I havent inserted any CStatic Resource.
-> I created my static window in OnInitDialog() of dialogbox
st.Create(_T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER,CRect(10,10,150,50),this);
-> After this I have added OnEraseBackground() in my CCustomStatic and Wrote the following code
BOOL CCustomStatic::OnEraseBkgnd(CDC* pDC)
{
TRACE("\n ERASE BACKGROUND");
RECT rc;
GetClientRect(&rc);
CBrush brush(RGB(255,0,0));
pDC->FillRect(&rc,&brush);
return TRUE;
}
->But I didnt get a Static with Red Color.
->But Later when I added OnPaint Message Handler in my CCustomStatic class , I got Red colored Static Control.
->Why this is happening So.
->Here What is special with OnPaint() in CCustomStatic
Please Help me
Thanks in Advance
George
|
|
|
|
|
When using standard Win32 API you need to process the WM_CTLCOLORSTATIC message and return a HBRUSH to get a custom background. I don't know if this applies to MFC but hopefully it will give you something to think about.
|
|
|
|
|
Hi Steve,
When I checked in my CCustomStatic Messages
I didnt get WM_CTLCOLORSTATIC
I found WM_CTLCOLOR, and I used it as u said for WM_CTLCOLORSTATIC
And I got my Static control's color changed.
But Still I am doubted with my Onpaint() Magic in CCustomStatic.
Thanks
George
|
|
|
|
|
Write the code/algorithm for function "int* minChangeMac(int cents, int* cDenoms, int* cCounter)"
where minChangeMac converts cents into elements of cDenoms and returns a pointer to an array cCounter such that sum of elements in cCounter array is the minimum possible number.
example 1: if cents = 56 and cDenoms = [25, 10, 5, 1] then cCounter = [2, 0, 1, 1]
example 2: if cents = 31 and cDenoms = [25, 10, 1] then cCounter should be [0, 3, 1] and not [1, 0, 6]
|
|
|
|
|
AryaSoft wrote: Write the code
i generally don't like these kind of question, because they traduce a lazy person asking for other to do it's homework
|
|
|
|
|
You have to give the guy points for being honest, however, that it was an interview question.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|