|
varsha_vm wrote: fstream objFileStream(strFileName,(ios::out|ios::in|ios::nocreate|ios::binary),filebuf::sh_read);
You are using ios::binary, so of course the file is going to be opened in binary mode. Remove it to open in ASCII mode.
-Saurabh
|
|
|
|
|
Thanks for reply
But even if I remove the ios::binary, I am getting the same result. I don't have ios::binary in my original code. This is something I have tried when I was getting the undesired result. I have edited my original code sample.
|
|
|
|
|
varsha_vm wrote: objFileStream.write("\n",3);
This looks suspicious. Why 3?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
David
Thanks for pointing out the error. I have added it for another new line, but removing it now. Program is working fine.
Thanks again.
|
|
|
|
|
Hi! I have a problem about release build
I'm using Visual Studio 2005. The project is worked on MFC
When I build the project what I working in debug mode, It builds done successfully.
but in release mode, Output window shows next
1>Compiling resources...
1>Linking...
1>Generating code
and then.. it doesn't pass.
It seems like be stoped.
After 20 min ,I just canceld build.
It has been built well before.
I just added some files(.h .cpp) and resorces(.bmp), not special code
and it happened.
one more thing,
if I set 'Off' at configuration 'Warnning Level', it builds succesffully.
What's involved in that?
Do you have any idea about that?
please help me
|
|
|
|
|
Try rebuild all, because it will delete all temporary files and start building your project fresh.
if doesn't work fine, could you please delete the "Release" folder and ncb files located in the project directory? If the project is too large, the linking may take long time.
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
I did it already.
but it doesn't work.
after that problem happend,
I found that all .obj files are made even .exe in 'Release' Folder.
.exe file size is 2MB ,excuting abnormally.
what the... T.T
|
|
|
|
|
Hi,
I found some code to play sounds. It works well but I can't figure out how to change the duration of the sound, e.g. to play for 100ms, 1000ms, 5000ms etc.
Here is the code. I added the DurationMillisecs parameter but I don't know how to utilize it.
BOOL Test1(long FREQUENCY, long DurationMillisecs)
{
#define BUFFERSIZE 4860 // 4k sound buffer
#define PI 3.14159265358979
HWAVEOUT hWaveOut;
WAVEFORMATEX WaveFormat;
WAVEHDR WaveHeader;
char Data[BUFFERSIZE];
HANDLE Done;
double x;
int i;
WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
WaveFormat.nChannels = 2;
WaveFormat.wBitsPerSample = 8;
WaveFormat.nSamplesPerSec = 11025;
WaveFormat.nBlockAlign = WaveFormat.nChannels * WaveFormat.wBitsPerSample / 8;
WaveFormat.nAvgBytesPerSec = (WaveFormat.nSamplesPerSec * WaveFormat.nBlockAlign);
WaveFormat.cbSize = 0;
Done = CreateEvent (0, FALSE, FALSE, 0);
if (waveOutOpen(&hWaveOut,0,&WaveFormat,(DWORD) Done,0,CALLBACK_EVENT) != MMSYSERR_NOERROR)
{
MessageBox(0,"Sound card cannot be opened.", "error", 0);
return TRUE;
}
for (i=0; i < BUFFERSIZE; i++)
{
x = sin(i*2.0*PI*(FREQUENCY)/(double)WaveFormat.nSamplesPerSec);
Data[i] = (char)(127*x+128);
}
WaveHeader.lpData=Data;
WaveHeader.dwBufferLength=BUFFERSIZE;
WaveHeader.dwFlags=0;
WaveHeader.dwLoops=0;
if (waveOutPrepareHeader(hWaveOut,&WaveHeader,sizeof(WaveHeader)) != MMSYSERR_NOERROR)
{
Message("Error preparing Header!");
return TRUE;
}
ResetEvent(Done);
if (waveOutWrite(hWaveOut,&WaveHeader,sizeof(WaveHeader)) != MMSYSERR_NOERROR)
{
Message("Error writing to sound card!");
return TRUE;
}
if (WaitForSingleObject(Done,INFINITE) != WAIT_OBJECT_0)
{
Message("Error waiting for sound to finish");
return TRUE;
}
if (waveOutUnprepareHeader(hWaveOut,&WaveHeader,sizeof(WaveHeader)) != MMSYSERR_NOERROR)
{
Message("Error unpreparing header!");
return TRUE;
}
if (waveOutClose(hWaveOut) != MMSYSERR_NOERROR)
{
Message("Sound card cannot be closed!");
return TRUE;
}
CloseHandle(Done);
return FALSE;
}
void Message(LPCSTR msg)
{
MessageBox(0, msg, " ",0);
}
|
|
|
|
|
Duration(msec) / 1000.0 = durationSec
durationSec * samplesPerSecond = numOfSamplesRequired
for (i=0; i<numOfSamplesRequired; i++)
{
// ** Generate the sound wave based on FREQUENCY define
}
WaveHeader.dwBufferLength = numOfSamplesRequired * bytesPerSample
|
|
|
|
|
Thanks. I didn't quite understand what the code does. It seems to me you mean that I should loop for the number of seconds I want to sound to last. But that creates a non-smooth sounds, like noise.
But I understood from your code that by playing with the size of BUFFERSIZE I can make the sound shorter or longer, and that seems to work well.
Thank you.
|
|
|
|
|
That's okay. I hope you can forgive me for my poorly formatted (i.e - not at all)
answer.
I had hoped you would understand as much as I do from what I wrote, and it seems to have served its purpose.
Have a nice weekend.
|
|
|
|
|
It certainly did serve it's purpose. Thank you, it was helpful.
|
|
|
|
|
Hi, I have started to use Visual Studio 2010, and First I started to make a sample dialog based application when I used the new controls of MFC like CMFCMenuButton or CMFCPropertyGridCtrl I found that these controls loose their visual style at ruining time, I should notice that I derived my dialog class from CDialog not CDialogEx, after all How could i solve the problem.
|
|
|
|
|
Did you ensure that, the project contains the manifest file? All other controls in the Window are enabled with Visual Styles?
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
Thank you for replaying the post, I just use the Visual Studio wizard to create the Dialog and again the Other buttons and controls lies on their own style and this happens only to new controls , I tested this experience for several times and the result was the same. I wonder if others had the same problem or not.
|
|
|
|
|
i met the same problem. At first,I deleted all features in mfc wizard because i draw all window by myself,but at last i found i need a dialog.I used ::InitCommonControlsEx() and it returned TRUE.
OK,this function did not work probably as it said on msdn,all controls on the dialog looks like old win98 style.I also modified the manifest file to enable xp style,but this style only appears in xp OS.
i dont why the ::InitCommonControlsEx() returned TRUE but it didnt do anything i could see.
|
|
|
|
|
Hy everyone ! What is the best way to send an mail through MFC application ? I study some methods , but I wish to send an mail whitout default mail settings ... is imposible ?
|
|
|
|
|
|
|
That's why I said "If you can afford it" and then added that you can search for SMTP code here on code project (or through Google.)
|
|
|
|
|
Sorry , I understand that .. my mistake !
|
|
|
|
|
|
Yes , it will help , that's what I'm looking for ... thanks !
|
|
|
|
|
Happy coding! Let me know if you have further questions.
|
|
|
|
|
hi,
for(int i = 0;i < n; i++)
{
try
{
//.........
}
catch(exception e)
{
//........
}
}
In tha above code,in catch block im printing some error message after the for loop terminated.my problem is when the for loop get terminates,im having the last error message only(the catch is called 2 times,so i need to display 2 error messages)...
pls help me...
|
|
|
|