|
Unfortunately, it has everything to do with your answer and code. Even though the OP is obviously new to C/C++, it doesn't hurt to learn good practices right from the start.
At any rate, it wasn't a suggestion: it's me saying that it is bad practice to use pointers and string literals in that way, for the reasons I explained. This is quite independent of the programmer's intentions.
So my point is: your solution was almost correct, except for that you should use 'const char*' everywhere to work with it like this. This could potentially save the OP lots of time trying to debug weird access violation errors later on, as the compiler will be able to inform you when you are doing something inappropriate that you are allowed to do when just defining it as 'char*'.
Now if you think I am entirely wrong and that it is in fact not poor practice, then I'd love to hear your arguments.
|
|
|
|
|
The other answers tell you how it can be done.
But there is a risk factor here, in that the size of the buffer is not known to the ChangeString function.
So it is always safe to pass in a second size parameter and only copy that many characters to the buffer inside the ChangeString function.
|
|
|
|
|
The issue is about changing a pointer whose address is given, not copying into a buffer, so no length is necessary.
The best things in life are not things.
|
|
|
|
|
hy guys,
i built small program in c++ (mini Paint) using classes, stacks and vector with STL (all in vs2010)
i sent the .exe file from the \Debug directory to my friends (vs 2008) and they got error missing "MSVCP100D.dll"
tried to build .exe file with the release option, didn't help at all...
sorry if my english is not the best...
can anyone help me please?
thanks, udi
|
|
|
|
|
|
|
You can install the runtime library separately as suggested or you can include that in the EXE by selecting the /MT (Release mode) or /MD (Debug mode) option from Project -> Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library .
This will however increase the size of the EXE.
|
|
|
|
|
I made a transparent icon saved as png, and in vc resource compiler, I write the statement:
MyIcon ICON "myIcon.png"
But the compiler complained the png did not comply with 3.0 format.
|
|
|
|
|
A png image is not a Windows Icon resource
ID_PNG PNG "res\\Test.png"
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
#include <stdio.h>
#include <conio.h>
typedef enum {FUNK0=0, FUNK1, FUNK2, FUNK3, FUNK4, FUNK5, FUNK_N} F_ENUM;
class F;
typedef F_ENUM(F::* F_member_fn_ptr)(void);
class F
{
public:
F_ENUM F0(void) {printf("class F F0\n"); return(FUNK2);};
F_ENUM F1(void) {printf("class F F1\n"); return(FUNK3);};
F_ENUM F2(void) {printf("class F F2\n"); return(FUNK4);};
F_ENUM F3(void) {printf("class F F3\n"); return(FUNK5);};
F_ENUM F4(void) {printf("class F F4\n"); return(FUNK1);};
F_ENUM F5(void) {printf("class F F5\n"); return(FUNK_N);};
static F_member_fn_ptr FUNK[FUNK_N];
};
F_member_fn_ptr F_FUNKS[FUNK_N]=
{&F::F0, &F::F1, &F::F2, &F::F3, &F::F4, &F::F5};
int main()
{
F f;
for(F_ENUM i=FUNK0; i<FUNK_N; i=(f.*F_FUNKS[i])())
;
return(getch());
}
|
|
|
|
|
Are you inventing from scratch COM ?
Why do you need to access that way member function?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am a scientist and the stuff I do is a bit more complicated than inventing COM for myself.
But thanks for the help all the same.
|
|
|
|
|
There's nothing more complicated than COM, of course. Anyway you, being just a scientist, cannot understand it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This would be a recursive type: "A function that returns a function that returns a function that ...". You can't do that!
The question now is what you want to achieve with that? To me that code looks rather obfuscated, making it error prone and hard to maintain. The sequence of function calls is encoded in the function implementations, rather in the implementation of the calling function. This is not only breaking the concept of encapsulation, it is also prone to mistakes causing endless loops, and later changes such as introducing more of these functions or changing the sequence will be very hard.
Why do you not simply write a sequence of function calls instead?
|
|
|
|
|
Thank you.
I have two types of app that should use this concept:
1.)A sort of scripting language that drives big image processing routines where the next result is only decided on the basis of execution. So these things are a sort of super high-level assembly language in which instructions do not have locations, but which perform a jump as part of every instruction.
2.)Breaking down really big scientific executions so that they may be executed in fragments witin OnIdle etc.....
|
|
|
|
|
I'd solve these cases like this:
1) Make an interpreter that analyzes the script and determines which function to call next.
2) Just split the execution into individual parts and call them sequentially. If the individual parts work or continue to work on a common context, make a struct to hold that context and pass a pointer to that as a parameter to each part-function.
In both cases there is no reason at all to encode the sequence of function calls right into the functions themselves. In fact, it would be bad to do so, for the very reasons pointed out above.
|
|
|
|
|
|
I use AlphaBlend blend the src( 0, 255, 0, 0 ) on dst( 128,128,128 ),expecting the result color should be the same as the dst( 128, 128, 128 ). But the result is ( 255, 128, 128 ). I have spent 5 hours try to find something, but unluckily I find nothing. it drives me crazy.
Could someon help me?
|
|
|
|
|
What are your BLENDFUNCTION values?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
BlendFunction.BlendOp = AC_SRC_OVER
.blendflag = 0
.SCA = 255
.AlphaFormat = AC_SRC_ALPHA
My bmp is per-pixel alpha channel bitmap.
I googled something articles and turuned out I didn't do the premultiple, but I am still comfused with the following formula:
Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red
where the Src.alpha's value making sense should be 0.0 - 1.0, but it is 0 - 255. I wonder OS translate the alpha value in background for us?
|
|
|
|
|
how to change selection-background-color of a CRichEditCtrl?
Default selection-background-color is black, I did see some software have other selection-background-color on their CRichEditCtrl.
How to do it?
.
|
|
|
|
|
MFC doesn't have WM_SETFONT message handle, such as OnSetFont(...), how to add it as standard MFC handle?
I mean, not use WindowProc(...) etc.
.
|
|
|
|
|
Are you wanting to intercept the WM_SETFONT message? Do you have a custom control that has a WndProc() function?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I think you can use ON_MESSAGE
0N_MESSAGE(WM_SETFONT, OnSetFont)...
where OnSetFont is declared as afx_msg LRESULT OnSetFont(WPARAM, LPARAM). and WPARAM contains HFONT.
http://www.mono-project.com/Main_Page
|
|
|
|
|
venkatmakam wrote: 0N_MESSAGE(WM_SETFONT, OnSetFont)...
While you probably meant ON_MESSAGE() , isn't that for user-defined messages and less-common Windows messages?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|