|
I was hoping you'd say that... :P
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I avoid preprocessor where ever possible, as a general rule.
About defines... I personaly think enums are better b/c they do not polute global namespace. I put them into scope of my class and access them with CMyClass::VALUE1, CMyClass::VALUE2 (like in your exmaple).
|
|
|
|
|
"I avoid preprocessor where ever possible, as a general rule."
oh, I ment in C++...
with C this rule wouldn't be possible. But C++ introduced so many features which reduces use of preprocessor/precompiler to a vanishing minimum.
|
|
|
|
|
Enums are type safe which is a nice thingtm. They are also recognized by the compiler and can be displayed using the symbolic name in debuggers which is also a nice thingtm.
I use #define's sometimes though. But that's because all those countless hours of C-coding has affected my brain.
--
This space for rent.
|
|
|
|
|
Thank-you all for your comments. Now to convince about a half-dozen people to listen...
You've all had good arguments for enums.
Thanks
Brad
|
|
|
|
|
|
A thread pool is a collection of threads the programmers instantiates, but the operating system initialize and deallocate. In other words, the operating system does the cleanup. The programmers adds new threads to the pool and their callback functions.
Kuphryn
|
|
|
|
|
When you start with multithread programming, soon you'll notice that the thread creation and setup and later destruction has a cost. This cost can be too much in a machine with a high utilization (e.g. a web server in a busy web site). So, a optimization algorithm is pre-creation of a number of threads and make them wait watching for "jobs" that need to be processed, and quickly returning to the "wait" state.
I see dumb people
|
|
|
|
|
Hi all,
what I'm trying to do, and failing obviously, is to create .wav files from .raw files (plain text files, just full of integers).
the problem is that I dont know how to create the header for the wav file properly. I'm going to be creating the same type of wav file all the time, ie 16khz, mono, 8-bit unsigned.
What I'm doing so far is using the fstream function but I'm not sure how to calculate all the required information from the .raw file.
The only change will be the size of the file, so I think that a fairly generic header would do the job, with the only thing having to change being the samples.
Can anyone help me here, I've looked around but still lost.
Thanks in advance all,
Chris
|
|
|
|
|
This[^]has everything you will need, I think. Goes into a detailed header description, too.
Have fun and maybe use it to write an article
If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
I just had a look at the code injected by the compiler when using the __event, __hook and
__raise keywords on native C++ code. The sample in the help-files which come with VC 7.0
define a void-event like so;
__event void MyEvent( int value );
and __hook a reciever to it and subsequently __raise it.
Fine.
So I changed it to this;
__event int MyEvent( int value );
and looked at the generated code for the __raise, ( now returning an int ), which is like so;
<br />
inline void CSource::MyEvent(int i1) <br />
{<br />
__EventingCS.Lock();<br />
__eventNode_CSource_MyEvent* node = __eventHandlerList_CSource_MyEvent;<br />
<br />
int hr = (int) 0;<br />
for (; node != 0; node = node->next) <br />
{<br />
hr = node->__invoke(i1);<br />
if ( hr!=0 )<br />
{<br />
return hr;
}<br />
}<br />
<br />
__EventingCS.Unlock();<br />
<br />
return hr;<br />
}<br />
( that comment is mine, not MS' ),
Is it just me or is this code broken ? The only way this code is not broken is
if there is some secret exception handling semantics going on which I don't know about.
If that's the case I stand corrected.
However, if it is not, then that piece of code will die somewhere bad due to a deadlock.
Anyone ?
cheers
-=jarl=-
----------------------------
jarl ostensen
Lead Technology Programmer
Bullfrog/Electronic Arts Inc.
|
|
|
|
|
Hi,
I execute my pgm two times .
I would like to know how can I do for inhibe the second pgm execution
I would like to show the first pgm and close the second pgm.
Best Regards
youssef
|
|
|
|
|
Here is a very extensive article on what you want to do by Joseph M. Newcomer. Check it out.
Avoiding Multiple Instances of an Application[^]
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
A member posted a simular question at CodeGuru. Here is the thread.
http://www.codeguru.com/forum/showthread.php?s=&threadid=221071
Kuphryn
|
|
|
|
|
im having this strange problem with a program im developing.
The program compiles & links with 0 errors, and 0 warnings on both Debug, and Release Configurations.
The Problem is midway thru execution of the main function on my Release Compile , I get one of those mysterious MFC error dialog boxes (send / dont send to microsoft) that doesnt really tell me much about the problem....
the code that this error is contained in is .......(sorry , i know its a little hard to read this way, this text box takes out the formatting... )
/// here will start the directory iteration
for (int ji=0;ji<fia.GetSize();ji++) {
char *c1 = new char[100000];
//read into c1
FILE *input;
if ( (input = fopen( fia[ji].GetFilePath(), "r" ) ) == NULL )
{
AfxMessageBox( "Could not open file....\n" );
}
numread = fread( c1, sizeof( char ), 100000, input );
c1[++numread] = '\0';
fclose( input );
// call api function
if(NULL != dllHandle)
{
// If the function address is valid, call the api's function.
if (runTimeLinkSuccess = (NULL != BounceCheckPtr))
{
result = BounceCheckPtr(*c1, *c2, len, *c3, *c4);
}
}
///// prepare database entry
UCHAR szSqlStr[128];
if (result == 0) {
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('GB', '%s')",c2);
}
if (result == 1) {
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('HB', '%s')",c2);
}
if (result == 2) {
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('SB', '%s')",c2);
}
if (result == 3) {
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('GB', '%s')",c2);
}
if (result == 9) {
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('GB', '%s')",c2);
}
// set return code
int m_iIdentification_Code = result;
// Switch Structure
switch( m_iIdentification_Code )
{
case 1:
// Allocate memory for the statement handle
retcode = SQLAllocStmt (hDBC, &hStmt);
// Prepare the SQL statement by assigning it to the statement handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
// Execute the SQL statement handle
retcode = SQLExecute (hStmt);
// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);
// Get row of data from the result set defined above in the statement
retcode = SQLFetch (hStmt);
// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);
break;
default:;
}
// delete memory i create on heap
delete[] c1;
}
it loops once, and then it dies on the second file read section...
any ideas / suggestions... would be appreciated
|
|
|
|
|
Just having a quick look; ye code looks a bit dodgy;
<br />
numread = fread( c1, sizeof( char ), 100000, input ); <br />
c1[++numread] = '\0';<br />
which can lead to
<br />
if numread==100000 )<br />
{<br />
DoOverwritePseudoRandomMemory( '\0' );<br />
}<br />
in debug-build you would have some pad-bytes which might silently swallow this.
Don't know if this is the problem, but it certainly can be a problem.
-=jarl
----------------------------
jarl ostensen
Lead Technology Programmer
Bullfrog/Electronic Arts Inc.
|
|
|
|
|
jDawwg wrote:
char *c1 = new char[100000];
jDawwg wrote:
FILE *input;
if ( (input = fopen( fia[ji].GetFilePath(), "r" ) ) == NULL )
Why are you using C style file handling and fixed size buffers ? If you use iostreams and std::string, you can do this so much nicer, and without there being any risk of a buffer overrun or truncated read, nor would you allocate a huge buffer that you do not need.
jDawwg wrote:
retcode = SQLAllocStmt (hDBC, &hStmt);
// Prepare the SQL statement by assigning it to the statement handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
// Execute the SQL statement handle
retcode = SQLExecute (hStmt);
// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);
// Get row of data from the result set defined above in the statement
retcode = SQLFetch (hStmt);
// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);
What is the point of grabbing the error status if you never check it ?
jDawwg wrote:
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('GB', '%s')",c2);
I think that &szSqlStr[0] is nicer syntax, but that's just me.
I reckon if you used C++ file handling and strings, your problem would probably go away.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Excellant ! thanks for the help Chris / Jarl! !
(jarl, thanks for the followup email too)
Im going to implement these suggestions and ill update you on how it goes..
i appreciate all the tips on making my code better too, because Im not really a c++ expert (yet, im optimistic ). the current experience I do have w/C++ has been hacking together projects out of neccessity so im sure its sloppy....
|
|
|
|
|
jDawwg wrote:
appreciate all the tips on making my code better too, because Im not really a c++ expert (yet, im optimistic ).
So long as you maintain this attitude, you will end up being better than most. Good luck !!
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hello,
I want to change the caption of my Property Page at runtime.
SetWindowText does not the trick. The Caption Text specified
in the Dialog editor is always used, no change after a SetWindowText
call in OnInitDialog.
Any Idea ?
|
|
|
|
|
Wow - deja vu, I am having the EXACT SAME PROBLEM. Although my scenario is a little different - my property page is in Wizard mode.
If you know the new title when the constructor of the property page is called, you can put this in the property page constructor:
<br />
m_psp.dwFlags |= PSP_USETITLE;<br />
m_psp.pszTitle = "Some New Title";<br />
BUT... this will NOT work after the property page has already been created! If anyone knows of a way to change the property page title (especailly in a wizard-mode property page) at run-time (NOT in the constructor) that actually works, I'm all ears.
I hate property sheets.. one of these days I'll write my own custom version of them and avoid all the silly restrictions they have.
Even a broken clock is right twice a day.
|
|
|
|
|
|
Cool,
it works for me too.
Thanks
|
|
|
|
|
There is a PROPSHEETPAGE pointed to by the m_psp class member of a property. This contains a field
pszTitle which contains the the title of the property page. Yoy will need to set the PSP_USETITLE flag in the dwflags of the property sheet to use this. You might give this a try.
|
|
|
|
|
The following is my code:
CAsyncSocket socksrv;
char buff[500];
...
UINT ClientThread(LPVOID lParam)
{
CSocket* s = new CSocket;
s = (CSocket*) lParam;
while (1) {
s->Receive(buff, 500*sizeof(char), 0);
if (strlen(buff)) {
::SetFocus(NULL);
AfxMessageBox(buff);
}
}
return 0;
}
UINT ServerThread(LPVOID lParam)
{
CSocket s;
socksrv.Create(55599);
socksrv.Listen();
while (1) {
if (socksrv.Accept(s)) {
AfxBeginThread(ClientThread, (LPVOID) &s);
}
}
return 0;
}
void CServerDlg::OnStartServer()
{
AfxBeginThread(ServerThread, NULL);
}
When I execute the following, and try to connect the client, an exception occurs. Please tell me where my mistake is, and if you know what the multithreading sequence must be using CSocket or CAsyncSocket...
Thank you!
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|