|
Always Welcome!
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi All
How can i create a New String Value in registry?Like this is path "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Cache".Now i want to create a new string "Name".Plz help me
|
|
|
|
|
You can use of CRegKey Class.
|
|
|
|
|
|
I need to write a function that will calculate standard deviation using an array and possibly a for loop.
my function reads in the array with the values. the number of values, and the average.
where can i start?
modified on Monday, November 3, 2008 1:03 AM
|
|
|
|
|
Dunno really. It's up to you - FindAverage seems like a perfectly suitable name.
Here's how I did it some time back:
#include <math.h>
#include <stdlib.h>
float calcArrayAvg(float *array, long numElements)
{
double tmp = 0;
long i;
for (i=0; i<numElements; i++)
tmp += array[i];
tmp /= numElements;
return tmp;
}
float calcStdDev(float *array, long numElements, float arrayAvg)
{
double thisDev;
double totalDev2 = 0.0;
double varience;
long i;
for (i=0; i<numElements; i++)
{
thisDev = array[i] - arrayAvg;
totalDev2 += thisDev*thisDev;
}
varience = totalDev2 / (float)numElements;
return sqrt(varience);
}
void setArrayMean(float *array, long numElements, float newMean)
{
double oldMean = calcArrayAvg(array, numElements);
double delta = newMean - oldMean;
long i;
for (i=0; i<numElements; i++)
array[i] += delta;
}
void setArrayStdDev(float *array, long numElements, float oldStdDev, float newStdDev)
{
double scale;
long i;
scale = newStdDev / oldStdDev;
for (i=0; i<numElements; i++)
array[i] *= scale;
}
void standard_normal(float *array, long numElements)
{
long i;
double mean, stdDev;
for (i=0; i<numElements; i++)
array[i] = ((float)rand()/(float)RAND_MAX);
mean = calcArrayAvg(array, numElements);
stdDev = calcStdDev(array, numElements, mean);
setArrayMean(array, numElements, 0.0);
setArrayStdDev(array, numElements, stdDev, 1.0);
}
Simon.
|
|
|
|
|
Simon, thank you so much. One thing I noticed though when running tests,
varience = totalDev2 / (float)numElements;
should be
varience = totalDev2 / ((float)numElements - 1);
|
|
|
|
|
Hi,
I am working on an MFC application which has chat feature in which there is an option for sending and receiving smileys.
I am getting the smiley codes. For the respective codes I want to show the bitmap image in a CRichEdit Control.
How to achieve it.
Please help me.
Thanks.
Dhiraj Kumar Saini
|
|
|
|
|
|
|
i want to connect USB WEBCAME in my vc++ application i am using following statment to select driver but i takes some time of processor to select driver which causes to slow speed of my application. and i have to connect and disconnect cammra again and again . can You help me how i can solve this porblem
capDriverConnect(hwnd,0) \\ use for default driver
or is there any method through which i have to select driver just once and i may able to change handle of frame with that driver without disconnecting cammra
|
|
|
|
|
The index selects the driver.
Connecting and disconnecting is going to be slow no matter which
driver you select.
What do you mean "change handle of frame"?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I want to add a Colour Picker Button to my Project. I am using VC++6.0 IDE and MFC.
I have found this nice Demo by Chris Maunder of exactly the sort of button I want to add to my dialog.
http://www.codeproject.com/KB/miscctrl/colour_picker.aspx
The demo compilies nicely and runs fine.
Indeed I can add the source files to my own project and compile fine too .
The understanding I am stuck with is how to add this custom control to my own dialog using the Resource Editor . Is there a way of adding it to the controls pallete or does it have to be added some other way ???
|
|
|
|
|
Since that particular control subclasses an existing button, put a button on the dialog and then subclass it as explained in the article.
|
|
|
|
|
I'm trying to understand exception handling in C++.
void main()
{
try
{
ios_base::open_mode d;
ofstream myfile;
myfile.open ("example.txt", d);
cout << "No excpetion thrown?" << endl;
system("Pause");
}
catch (exception& e)
{
cout << "ERROR:\r\n" << e.what() << endl;
system("Pause");
}
}
All I want to do is catch the exception with the general exception class.
I did enable C++ Exceptions in the project properties (/EHsc) but when debugging the exception (uninitialized variable 'd' and there is no file called "example.txt" either) isn't thrown because the application is interrupted by MSVC++.
However, the release build simply executes without any exception at all.
I want to use a general exception to catch all errors, in case something unexpected happens and I don't want to use catch(...) because I want to use the what() function to get some information about the error that occurred.
How would I go about it correctly?
Thanks in advance.
|
|
|
|
|
You only get an exception when you do something that results in an exception being thrown. d being uninitialized is a coding error, not a runtime error. open() is not documented as throwing on error, instead it calls setstate(failbit) on the object.
|
|
|
|
|
I see, thanks.
Could you tell me a way to get an exception without explicitly throwing one?
I want to see for myself how it works, so I can use it myself later.
Or am I approaching this from the wrong direction?
I'm used to everything throwing an exception the moment something doesn't work in C# but in C++ they don't seem to occur nearly as often.
Is it better to not worry that much about them and focus rather on catching errors by structuring the program in a way that it tells you what went wrong without exceptions?
Like simply displaying a message if a file wasn't found, the user inputted a string instead of a number, etc.?
|
|
|
|
|
Megidolaon wrote: Could you tell me a way to get an exception without explicitly throwing one?
I want to see for myself how it works, so I can use it myself later.
Not sure I understand. If the code you're calling doesn't throw exceptions, then the only way to generate an exception is to throw one yourself.
Megidolaon wrote: I'm used to everything throwing an exception the moment something doesn't work in C# but in C++ they don't seem to occur nearly as often.
MS decreed that exceptions were the way to signal errors in .net right from the beginning. In C++, exceptions aren't used nearly as often due to the many years that C++ existed without stable exception implementations, not to mention programmers who come from C, and those (like me) who just dislike exceptions entirely.
It all comes down to the code you're calling. If it uses return values to signal errors, check return values. Exactly how you tell your user that an error happened is a different discussion entirely (it would be worth starting a new post so more people see it; this one's already well-buried).
|
|
|
|
|
I see.
I'm just used to C# and was wondering because it's directly hard to get an exception not explicitly thrown C++.
On the other hand this is convenient because I can just check return values and rarely have to worry about an exception happening and code not being executed.
Since exceptions are so rare I guess catch(...) will suffice for my needs.
Thanks again.
|
|
|
|
|
Recently I've been experiencing something very irritating. I'm using Visual C++ 2008 EE, on Vista Premium, and sometimes when I hit the build button the IDE just hangs. I have to shut it down with the task manager, and when I do that a little balloon pops up in the corner saying that the DEP (Data Execution Prevention) has shut down VS because it was trying to execute malicious code. What makes this problem even more bizarre is that if I open up the IDE again and build the project (without any modifications whatsoever) it works just fine. But then the problem will come back when I least expect it.
I've tried to disable the DEP for Visual Studio but when I try to a dialog box pops up saying that I'm not allowed to disable it, even though I am the administrator of this computer. I've read that you can stop the DEP altogether in boot.ini, but I can't find it. And, would I really want to do that?
Any ideas?
Thanks,
Martin
|
|
|
|
|
Do you have any IDE plugins? If so, disable them and see if that helps.
|
|
|
|
|
dear all
urgent problem, how to delete icon of tool bar in vc++2008, and also how to change the title of project? thanks a lot
|
|
|
|
|
Do you want to change some icons of Visual studio or of your program and for second sextion you can use of SetWindowText ?
|
|
|
|
|
hi,
I allocate a memory on heap and copy some code to that heap from my program. Now, I want to execute that code from heap but I am unable to understand how I can jump or change instruction pointer to point to that(heap) location and start execution. I am using C to do this.
Thanks,
|
|
|
|
|
Use assembly, push the address of your code on the stack, then execute a ret instruction. Be sure to mark the memory as executable or the CPU may raise an exception (depending on the OS type, CPU type, and DEP settings).
|
|
|
|