|
the VARIANT has only the pointer to the data, it gets allocated with SysAllocString(wchItems);
Where happened the execption?
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
The following code runs 'exception-free' on my system:
#include <windows.h>
void main()
{
char lpszitems[2500];
wchar_t wchItems[2500];
memset(lpszitems, 'A', 2499);
lpszitems[2499]= '\0';
int n =MultiByteToWideChar(CP_ACP, 0, lpszitems, -1, wchItems,
2500);
if (n==0)
{
DWORD dw = GetLastError();
int k=5;
}
VARIANT * lpList, vt;
lpList = &vt;
VariantInit(lpList);
lpList->vt = VT_BSTR;
lpList->bstrVal = SysAllocString(wchItems);
}
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]
|
|
|
|
|
Hello,
Why doesn´t this code return "sumatorio=5"???
<br />
#include <stdio.h><br />
<br />
int main(void)<br />
{<br />
int sumatorio;<br />
int sum;<br />
<br />
sumatorio=0;<br />
for(sum=0; sum<5; sum++)<br />
{<br />
sumatorio=sumatorio+1 ;<br />
}<br />
<br />
printf("Sum: %i .\n", sumatorio);<br />
<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
the code looks good (tested on xcode on mac); sumatorio is 5 after the loop.
This signature was proudly tested on animals.
|
|
|
|
|
does it return "Sum: 5 ."? sumatorio is indeed 5.
|
|
|
|
|
because the coder wrote "return 0;"
PS: the biggest failure cause sits before the PC
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
The printf statement needs a %d for outputting an integer:
printf("Sum: %d .\n", sumatorio);
|
|
|
|
|
jon_fallon wrote: The printf statement needs a %d for outputting an integer:
For signed decimal integers we could use: %d or %i . They are synonymous for the output (printf() ). You can check this here[^].
Regards,
Nuri Ismail
|
|
|
|
|
programmer202 wrote: Why doesn´t this code return "sumatorio=5"???
Because you did not tell it to!
|
|
|
|
|
Hello,
I am using a Static Element of type "enhanced metafile" on a dialog to display metafiles. Now I'd like to have the metafile displayed rotated by 180 degree. I s there an easy way to do this, for example by defining a new viewport, and how can this be done?
|
|
|
|
|
below is my code.i m using CIPAddressCtrl contorl of vc++(mfc).problem is that we thia case statement is execatuted messagebox is dispaly twice.I wont understand .Plz anyone has idea about this help me to solve my problem..
void CServerIPAddress::OnIpnFieldchangedServerIpaddress(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMIPADDRESS pIPAddr = reinterpret_cast<LPNMIPADDRESS>(pNMHDR);
*pResult = 0;
int nFieldIndex = pIPAddr->iField;
int nValue = pIPAddr->iValue;
CString csValueFormat;
switch(nFieldIndex)
{
case 0:
{
if(nValue < 1 || nValue > 223)
{
csValueFormat.Format(_T("%d Is not a valid entry."),nValue);
csValueFormat.Append(_T("Please specify a value between 1 and 223"));
AfxMessageBox(csValueFormat);
}
}
break;
default:break;
}
}
|
|
|
|
|
jadhavjitendrar wrote: Why Messagebox display twice It's Urgent
It shows two times because it's urgent.
BTW:
- reposting isn't good.
- urgentz requests go automatically into the recycle bin.
- your code snippet is not properly formatted.
- you may modify you original post, adding more details (for instance is your application multithreaded?).
Please read the forum guidelines [^], before posting.
[added]
'Mr.Univoter The Coward' beware: "the spiderman is having you for dinner tonight"!
[/added]
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]
modified on Wednesday, September 23, 2009 6:36 AM
|
|
|
|
|
As Cpallini said, you should have added to your previous message instead of posting a new message. anyway, you didnt answer my earlier query i.e. whether by any chance OnNotify is called twice?
I dont know why i feel i had this stupid problem of a piece of code executing twice inside some windows message handler.
and the problem in my case was that windows was sending the message to my control as well as to its parent also and parent was forwarding the message to its child. So, in effect, child was receiving the same message twice.
You are suggested to put breakpoints at *all possible places* and check if your message handler is being called twice.
Happy programming.
|
|
|
|
|
If you consider that the SysIPAddress32 control is comprised of four Edit controls, those edit controls are sending EN_CHANGE and EN_UPDATE notifications. That may not be an exact answer to your question, but it should give you enough to plow through Spy++ to see exactly what is going on.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Good morning,
I have trouble creating a wave file from the data stream I got from the microphone input.
The recording seems to go quite well but know I´m stuck at the task of converting that data into a wave file.
I recorded the mic data into a WAVEHDR structure like this ...
const int NUMPTS = 44100 * 10;
int sampleRate = 44100;
short int waveIn[NUMPTS];
HWAVEIN hWaveIn;
WAVEHDR WaveInHdr;
MMRESULT result;
int main( int argc, char *argv[] )
{
WAVEFORMATEX pFormat;
pFormat.wFormatTag=WAVE_FORMAT_PCM;
pFormat.nChannels=1;
pFormat.nSamplesPerSec=sampleRate;
pFormat.nAvgBytesPerSec=sampleRate*2;
pFormat.nBlockAlign=2;
pFormat.wBitsPerSample=16;
pFormat.cbSize=0;
result = waveInOpen(&hWaveIn, WAVE_MAPPER,&pFormat, 0L, 0L, WAVE_FORMAT_DIRECT);
if (result)
{
char fault[256];
waveInGetErrorText(result, fault, 256);
return 1;
}
WaveInHdr.lpData = (LPSTR)waveIn;
WaveInHdr.dwBufferLength = NUMPTS*2;
WaveInHdr.dwBytesRecorded=0;
WaveInHdr.dwUser = 0L;
WaveInHdr.dwFlags = 0L;
WaveInHdr.dwLoops = 0L;
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
result = waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
if (result)
{
return 1;
}
result = waveInStart(hWaveIn);
if (result)
{
return 1;
}
do
{
}
while (waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR))==WAVERR_STILLPLAYING);
waveInClose(hWaveIn);
save();
std::cin.get();
return 0;
}
... and now I am trying to store the data to a wave file like this:
bool save()
{
int subchunk2size = WaveInHdr.dwBufferLength*1*2;
fstream myFile ("test.wav", ios::out | ios::binary);
myFile.seekp (0, ios::beg);
myFile.write ("RIFF", 4);
myFile.write ((char*) 36+subchunk2size, 4);
myFile.write ("WAVE", 4);
myFile.write ("fmt ", 4);
myFile.write ((char*) 16, 4);
myFile.write ((char*) 1, 2);
myFile.write ((char*) 1, 2);
myFile.write ((char*) 44100, 4);
myFile.write ((char*) 88200, 4);
myFile.write ((char*) 2, 2);
myFile.write ((char*) 16, 2);
myFile.write ("data", 4);
myFile.write ((char*) subchunk2size, 4);
myFile.write (WaveInHdr.lpData, WaveInHdr.dwBufferLength);
return true;
}
But somewhere I got a bad memory access or such something since I get a read error (in memcpy.asm).
Can anybody help me here?
Souldrift
|
|
|
|
|
Well, nevermind. I just fixed it .
Modified the save function like this:
bool save()
{
int bitsPerSample = 16;
int subchunk1size = 16;
int numChannels = 1;
int subchunk2size = WaveInHdr.dwBufferLength*numChannels;
int chunksize = 36+subchunk2size;
int audioFormat = 1;
int byteRate = sampleRate*numChannels*bitsPerSample/8;
int blockAlign = numChannels*bitsPerSample/8;
fstream myFile ("test.wav", ios::out | ios::binary);
myFile.seekp (0, ios::beg);
myFile.write ("RIFF", 4);
myFile.write ((char*) &chunksize, 4);
myFile.write ("WAVE", 4);
myFile.write ("fmt ", 4);
myFile.write ((char*) &subchunk1size, 4);
myFile.write ((char*) &audioFormat, 2);
myFile.write ((char*) &numChannels, 2);
myFile.write ((char*) &sampleRate, 4);
myFile.write ((char*) &byteRate, 4);
myFile.write ((char*) &blockAlign, 2);
myFile.write ((char*) &bitsPerSample, 2);
myFile.write ("data", 4);
myFile.write ((char*) &subchunk2size, 4);
myFile.write (WaveInHdr.lpData, WaveInHdr.dwBufferLength);
return true;
}
Cheers
Souldrift
|
|
|
|
|
Hi,
How to split a string
something like making "hello world" into an array of "hello" and "world"...
Thanks in advance.
|
|
|
|
|
Are you using MFC CString?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
See CStringArray.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I included the header file, #include <string>;, for CString.
But CString is nowhere found. Do I need to include any other headerfiles to access CString?
|
|
|
|
|
Actually you don't need CString , you may also use strtok [^] for the purpose.
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]
|
|
|
|
|
string first = strtok(str,"C");
str is the string type which I would like to split by character 'C'.
Got the following compiler error,
'strtok' : cannot convert parameter 1 from 'std::string' to 'char *'
Can we convert the string to char * type.
|
|
|
|
|
You don't need strtok for dealing with std::string . Use std::string.find instead. For instance
#include <string>
#include <iostream>
void main()
{
const int SIZE = 10;
std::string s[SIZE];
std::string str = "Hello folks, welcome!";
int i;
int start_pos, end_pos = 0;
for (i = start_pos=0; i <SIZE && (end_pos = str.find(' ', start_pos)) != std::string::npos; i++)
{
s[i] = str.substr(start_pos, end_pos-start_pos+1);
start_pos=end_pos+1;
}
if ( start_pos < str.length() && i < SIZE)
{
s[i] = str.substr(start_pos, str.length()- start_pos+1);
i++;
}
for (int j=0; j<i; j++)
{
std::cout << "s[" << j << "]=" << s[j] << std::endl;
}
}
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]
|
|
|
|
|
NarVish wrote: Can we convert the string to char * type.
Try:
const char* cstr = str.c_str();
string first = strtok(cstr, "C");
Or just the simple
string first = strtok(str.c_str(), "C");
[EDIT]Or, just use CP's solution[/EDIT]
|
|
|
|
|
Whit CString s, for instance, your best bet is the Tokenize method [^], some extra work is required, however.
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]
|
|
|
|
|