|
eli15021979 wrote:
CString string; <br />
char *temp; <br />
double dNumber; <br />
temp = string.GetBuffer(string.GetLength()); <br />
sprintf(temp,"%f",dNumber);
Well, using your code exactly as shown is incorrect because [1] the string has no contents, so calling CString::GetLength() to size the returned buffer is incorrect, [2] you did not call CString::ReleaseBuffer() to relock the written-to buffer, and [3] you did not enforce the length of the data written to the buffer (memory overrun potential).
(Mis)using CString :
<br />
CString string; <br />
char *temp = string.GetBuffer( 32 + 1 ); <br />
double dNumber = 12345.54321; <br />
<br />
_snprintf( temp, 32, "%f", dNumber );
temp[ 32 ] = '\0';
string.ReleaseBuffer();
You will want to add proper exception handling and testing of the pointer returned by CString::ReleaseBuffer() .
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Don't you think he should try to do the work by himself?????
I just wanted to give him general direction.
BTW:
I just realized that he wanted convertion from string to double(i.e this wasn't the suitable example) so :
CString string = "1234.5678";
char *temp;
double dNumber;
temp = string.GetBuffer(string.GetLength());
sscanf(temp,"%f",dNumber);
<big>string.ReleaseBuffer();:laugh:</big>
Regards,
Eli
|
|
|
|
|
eli15021979 wrote:
Don't you think he should try to do the work by himself?????
I just wanted to give him general direction.
Given general direction is fine, but at least give proper direction; do not lead someone down a path that will cause them problems in the future.
-And, actually, your example is wrong, too...!
You need to pass the address of dNumber to sscanf(...) . Better to use a function designed for this specific purpose, like strtod(...)/_tcstod(...) instead of a more general purpose function, like sscanf(...) .
Calling GetLength() in the context shown above will still return an incorrectly sized buffer.
<br />
double dNumber1 = ::_tcstod( _T( "1234.5678" ) ); <br />
double dNumber2 = ::strtod( "1234.5678" ); <br />
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Is google broken on your PC ? I've answered this question a few times lately ( I assume you're asking over and over, or all your class is looking for help on the same assignment ) and I've just been cutting and pasting the demo code from the first match google hits.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Here is
char *t;
double dt=::strtod(m_edit6,&t);
CString str;
//check is we got correct double value
str.Format("%e",dt);
MessageBox(str);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
how can i convert this double value into its corresponding ascii value??
|
|
|
|
|
|
hello,
i write a service and do something,but what can i do to not allow others to stop my service or modify the start type,status of the service?who can help me?
best regards
|
|
|
|
|
When you create the service via CreateService() specify the desired access rights.
You can not prevent an admin from stopping or modifying a service.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi,
Anybody knows about software modems. Or any helpful links to know about?
Actually my objective is to test the (already present)software modem in
my system. Diagnostics purpose.
Thanks
Tom
|
|
|
|
|
Hi..
I had posted this query few days back also.. i am still not able to get the solution..
I need to maintain a log file that should contain the entries for the time a playback started and the time it ended. I am playing the wave files using Directx's DirectSound.. A separate thread takes care of the playback..
Mr. cedric had told me to find out what the callback function does.. the SetCallback function gets the audio stream data..
Is it possible to record the start and end times of the playback???
I am giving the related code here...
==================================================
void CPhoneDlg::OnPlay()
{ ......
CTime theTime=CTime::GetCurrentTime();
CString startTime=theTime.Format( "%H:%M:%S, %B %d, %Y" );
WriteLogFile(startTime);
m_pMyDS->Play();
m_timerID = timeSetEvent(500, 100, TimerProc, (DWORD)this, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
CTime getTime=CTime::GetCurrentTime();
CString endTime=getTime.Format( "%H:%M:%S, %B %d, %Y" );
WriteLogFile(endTime);
......
}
void CPhoneDlg::WriteLogFile(const char* szString)
{
FILE* pFile = fopen("logFile.txt", "a");
fprintf(pFile, "%s\n",szString);
fclose(pFile);
}
//Some methods in the MyDirSound Class
void CALLBACK TimerProcess(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CMyDirSound *pDDS = (CMyDirSound *)dwUser;
pDDS->TimerCallback();
}
void CMyDirSound::SetCallback(LPGETAUDIOSAMPLES_PROGRESS Function_Callback, LPVOID lpData)
{
m_lpGETAUDIOSAMPLES = Function_Callback;
m_lpData = lpData;
}
void CMyDirSound::Play()
{
//Check if the DirectSound was created successfully
..........................
//Check if the callback function is valid
..........................
//Check if SetFormat successfully
..........................
if (0 == m_dwCircles1)
{
//Get audio data by callback function
DWORD dwRetSamples = 0, dwRetBytes = 0;
m_lpGETAUDIOSAMPLES(m_lpAudioBuf, m_WFE.nSamplesPerSec, dwRetSamples, m_lpData);
dwRetBytes = dwRetSamples*m_WFE.nBlockAlign;
//Write the audio data to DirectSoundBuffer
.....
//Lock DirectSoundBuffer
.....
//Copy Audio Buffer to DirectSoundBuffer
.....
//Unlock DirectSoundBuffer
....
}
//Beging Play
m_lpDSB->Play(0, 0, DSBPLAY_LOOPING);
//timeSetEvent
m_timerID = timeSetEvent(300, 100, TimerProcess, (DWORD)this, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
}
==============================================================
The waveforms which i play are all greater than 10ms.. even then the start and the end times of playback are coming same..
If someone can tell if it can done and if so how.. i will very thankfull..
regards
pallavi
|
|
|
|
|
I presume there's a callback you can register for that will notify you when the file stops playing.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi..
thank you..
Can you explain it in a bit detail.. I am new to DirectSound and programming multimedia applications.. What i should do exactly?
regards
pallavi
|
|
|
|
|
Have a look at the IDirectSoundNotify interface.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
iam using Doc - View architecture for an MDI application.
I need to scroll the MDI child windows using horizontal and vertical scroll bars.
can anyone let me know the procedure.
thanx in advance
laiju
|
|
|
|
|
Hi guys
I am having a small problem on refreshing screen, because when i insert digital gates that i created on Bitmap they were disappear immediately if i minimize or maximize the screen, any one can give me a hand thanks
From: Guibert
|
|
|
|
|
when u refresh screen , u must reinsert digital gates. Or u can store digital gates in bitmap.
|
|
|
|
|
Does anybody know how you can disable Microsoft Word's Spell check engine using VC++??
Any help would be greatly appreciated.
|
|
|
|
|
Hi,
The codes below used to create a window to display something. Could some of you tell me that how can I display the real time clock (H:M:S) inside this window... Thanks!
hwnd = CreateWindow(
szWinName, /* name of window class */
"Capture Testing", /* title */
WS_OVERLAPPEDWINDOW, /* window style - normal */
CW_USEDEFAULT, /* X coordinate - let Windows decide */
CW_USEDEFAULT, /* Y coordinate - let Windows decide */
480, /* width - let Windows decide */
320, /* height - let Windows decide */
HWND_DESKTOP, /* no parent window */
NULL, /* no menu */
hThisInst, /* handle of this instance of the program */
NULL /* no additional arguments */
);
g_inst=hThisInst;
/* Display the window. */
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
hWndG=hwnd;
SetTimer(hWndG,1,100,NULL);
|
|
|
|
|
You need to create a control that shows the time, and then set a timer in that control that keeps calling Invalidate, so that a paint message is recieved.
Do you need to use Win32 ? If you can use MFC, it will make life a lot easier for you.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
An other solution:
Add a hook to WM_PAINT message and use TextOut to display your message...
You can use this method to display bitmap for Digit like in electronic clock or draw line like in mechanic clock.
A++
...
|
|
|
|
|
MSN Article Q138594 tells us how to print raw-data such as EPS file, the snippets are as follows.
But another problem is, the picture always printed on the paper's top-left corner, and always the same size regardless of paper size.
How to set the position and scale for raw data printing? that is,
Can we set printing properties(position and scale) before sending data to printer?
///////////////////////////////////////////////////
DOC_INFO_1 DocInfo;
HANDLE hPrinter;
DWORD dwBytes;
char line[256] = {0};
char *szPrinterName = "HP DesignJet 1050C PS3";
if (OpenPrinter(szPrinterName, &hPrinter, NULL))
{
DocInfo.pDocName = "EPS Document";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "RAW";
if (StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo) != 0)
{
if (StartPagePrinter(hPrinter))
{
Open_EPS_File();
while (Read a line)
WritePrinter(hPrinter, line, strlen(line), &dwBytes);
Close_EPS_File();
}
}
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
}
|
|
|
|
|
Purpose: copy the content from the input file twice to the output file
Problem: only happens ones, program won't write a second file to the outputfile ...
Note: yes the filepaths need to be WIDECHARS
I tried following but this doesn't work :
--------------------------------------------
wchar_t *in = L"D:\\TEST\\in.txt";
wchar_t *out = L"D:\\TEST\\out.txt";
wchar_t * buffer;
long size;
std::wofstream outfile (_wfopen(out,L"a"));
for (int i=0; i<2; i++)
{
std::wifstream infile (_wfopen(in, L"r"));
infile.seekg(0,wifstream::end);
size=infile.tellg();
infile.seekg(0);
// allocate memory for file content
buffer = new wchar_t ;
// read content of infile and write to output file
infile.read (buffer,size);
outfile.write (buffer,size);
delete[] buffer;
infile.close();
}
outfile.close();
----------------------------------------
Now, following is the code to copy the content from a txt file twice into an output file; The filepaths here are char*
(This works)
const char *in = "D:\\TEST\\in.txt";
const char *out = "D:\\TEST\\out.txt";
char * buffer;
long size;
ofstream outfile (out,ofstream::app);
for (int i=0; i<2; i++)
{
ifstream infile (in,ifstream::binary);
infile.seekg(0,ifstream::end);
size=infile.tellg();
infile.seekg(0);
// allocate memory for file content
buffer = new char [size];
// read content of infile and write to output file
infile.read (buffer,size);
outfile.write (buffer,size);
// release dynamically-allocated memory
delete[] buffer;
infile.close();
// end of calls to copy content from the tempfiles
}
outfile.close();
So last piece of code works for file with char* filepaths, but I need something like this for files with wchar_t filepaths
Hope you can help me out ...
|
|
|
|
|
christophek wrote:
Note: yes the filepaths need to be WIDECHARS
The 'basic_ofstream' template behind wofstream takes 'const char*' form of file name. ie, if you want to write wide chars to a file also, still you have to give the file name in ordinary char form while opening it.
christophek wrote:
std::wofstream outfile (_wfopen(out,L"a"));
There is no overloaded constructor for basic_ofstream which takes FILE* returned by _wfopen().
christophek wrote:
buffer = new wchar_t ;
you missed to give the buffer size required.
suhredayan There is no spoon.
|
|
|
|
|
right, it should be buffer = new wchar_t [size]; (the forum mispasted this)
But I don't want to write wide chars to a file, I just want to open a file with a widechar filepath and copy the content to another file also with a widechar filepath
|
|
|
|
|