|
If yes then ignore #1
I meant those were two possible reasons for the error based on what I could see.
I put #1 just in case you had it declared inside a class.
Did fixing the cast work then?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes! it worked, now i only got a warning C4312: 'type cast' : conversion from 'int' to 'LPVOID' of greater size
I hope this warning doesn't affect anything.
Thanks!
|
|
|
|
|
You get a warning if you do it like this?
CWinThread* pThread=AfxBeginThread(Start,(LPVOID)hDrv,THREAD_PRIORITY_BELOW_NORMAL);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes, the warning is warning C4312: 'type cast' : conversion from 'int' to 'LPVOID' of greater size
i think it's because hDrv was declared as int
|
|
|
|
|
Ohh it's a 64-bit compatibility warning
You can use the LONG_PTR type instead of int or disable the warning if you want to.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
ok...thanks!
and 1 more question regarding start() function,
i need to use the function and variable in the my CXXXDlg class, what's the syntax for that?
say what if i want to use the m_CListBox.AddString function, m_ClistBox is the CListBox object declared in the CXXXDlg class
-- modified at 17:08 Friday 27th July, 2007
|
|
|
|
|
Typically you'd pass a pointer to the class object to the thread.
In the thread proc, cast the LPVOID back to a pointer to the object.
In your case, a pointer to the dialog class object that creates the thread is probably appropriate.
The thread proc can be a static member of the class.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How would you implement a critical section between two or more windows in a single thread, i.e. if one winproc tries to access it, it halts in place till its available, while other windows in thread continue to function and continue to recieve messages. I know CriticalSections work for threads, not windows - I was thinking of something implemented with GetMessage, PeekMessage or whatever. Maybe this is impossible.
|
|
|
|
|
If you only have one thread there's no way to halt that thread and have anything else happen in your windows or window proc(s) (aside from asynchronous
callbacks, of course, but those are separate threads).
With a single thread, while a windowproc is handling a message, all other window procs are halted.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: If you only have one thread there's no way to halt that thread and have anything else happen in your windows or window proc(s) (aside from asynchronous
callbacks, of course, but those are separate threads).
With a single thread, while a windowproc is handling a message, all other window procs are halted.
Well, if a resource is unavailable, why couldn't a WinProc start a GetMessage-Translate-Dispatch loop right there until a special message was sent indicating the resource was available, at which point the WinProc would halt the GetMessage Loop and continue as normal. I'm not understanding why this doesn't work.
|
|
|
|
|
Because that "GetMessage-Translate-Dispatch loop" is running on the same thread you start it on. Everything occurs serially until there's another thread.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am experimenting in OpenGL and want to switch between full screen mode and windowed mode. I have code that does this, but I think ALT + ENTER is a standard key combination for this function so I want to add it in my code. I tried processing WM_KEYDOWN messages, but I'm not sure what key code to look for. I am not even sure if I am processing the right message.
Any suggestions?
|
|
|
|
|
For WM_KEYDOWN, something like this
if (VK_RETURN == wParam)
{
// enter
if (0 > ::GetKeyState(VK_MENU))
{
// alt-enter
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark, but it does not work consistently. The first time I press the combination it works, but after that it does not. I also use F11 and that works flawlessly.
I tried printing wParam and lParam to a file to see what is generated and it does not even show the codes for the WM_KEYDOWN events which make me wonder if it is being processed under a different message. Any Ideas?
Code snippets as follows...
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
...
case WM_KEYDOWN:
...
OnKeyDown(wParam, lParam);
break;
...
}
...
}
...
void OnKeyDown(int pKeyCode, DWORD pFlags) {
...
switch (pKeyCode) {
case 122:
...
DestroyWin();
CreateWin();
break;
case VK_RETURN:
if (GetKeyState(VK_MENU)) {
...
DestroyWin();
CreateWin();
}
break;
}
}
|
|
|
|
|
The keyboard messages go to the window with keyboard focus. If your WndProc is the only window proc
for all your windows, you should get all of them, except ones that go to windows of classes that aren't
yours (e.g. un-subclassed controls). Is focus going to another window?
I'm not sure how WM_KEYDOWN/VK_F11 could work flawlessly but you don't receive WM_KEYDOWN/VK_RETURN.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I only defined one WndProc() and created only one window. However, I am not experienced enough to tell if windows were defined somewhere else without my knowledge. Its a basic application skeleton with no controls yet.
I tested again and realised that the sysmenu (the one to the top left of the screen that is attached to the window's icon) activates when I hold down the alt key. Maybe this is responsible? Interestingly "CTL + ENTER", "SHIFT + ENTER" and "ENTER" work, which is not the behaviour I was expecting.
|
|
|
|
|
Try using WM_SYSKEYDOWN instead of WM_KEYDOWN for ALT key combinations.
Better yet, try this for ALT-ENTER:
case WM_SYSCOMMAND:
if (SC_KEYMENU == (wParam & 0xFFF0))
{
// alt - enter
}
else
{
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I need to develop an application that records sound amplitude and plot in on a graph with a function of time, using a microphone. Is the best approach to do this using DirectSound. If so is there any sample code that is available for this, or some kind of tutorial.
Thanks in Advance.
|
|
|
|
|
Either DirectSound or the Windows Multimedia APIs will work. If you choose DirectSound then download the latest
DirectSound SDK and you'll find sample apps to get you started, along with documentation. The "CaptureSound Sample"
is a good start
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have an application where everything is written in serial fashion, one after the other and this included computation and updating certain displays within the main application. All these secondary displays are the child windows of the main application. This is a closed loop system where I need to update the displays in each iteration. While updating these displays takes 80% of the total time for each iteration, we want to increase the speed of the closed loop. So, I created different thread for updating displays while the computation loop works on it own and sets the flag for the display datasets when they r ready. My threads are defined in main application dialog file.
Here comes the problem, inorder to update the displays I am calling a method of the corresponding dialog box, which inturn calls the OnPaint() function of that dialog. This is where the program crashes with Abort Assertion Failed error.
Any ideas??
-Pavan.
Pavan
|
|
|
|
|
At first glance, this sounds like a bad design, destined for failure. How many dialogs and threads are we talking about here? Are the threads directly updating a UI component that does not belong to them?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes, its not a good design at all, but its been written long time back at the time when I am not here. The application is a common dialog box design with 9 child dialog boxes in it. I have defined a separate thread in the main dialog box(where all the child dialog boxes are defined). There is only one thread that is defined additionally where atleast 4 dialog boxes are being refreshed by calling the methods one after the other already defined in them which inturn calls OnPaint() function of the corresponding dialog box. So we are looking at updating 4 dialog boxes from that thread. This thread is created whenever user starts closeloop and they are terminated when he stops closeloop.
Pavan
|
|
|
|
|
Pavan Berkeley wrote: So we are looking at updating 4 dialog boxes from that thread.
By posting or sending a message?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all. I made a simple function that acts off of whether there's a certain string placed in a buffer.
<br />
string match1;<br />
string match2="virtualspace";<br />
<br />
if(client.find("matchup") != string::npos){<br />
if(client.find(word) != string::npos){<br />
if(match1 == match2){<br />
cout << "Found a match";<br />
}<br />
else{<br />
cout << "No match";<br />
}<br />
So once the first function is called and the buffer is filled it works fine. Then .clear() to empty the buffer works fine too. But when i try to fill the same buffer with the same characters from before it doesnt work. So i figured, maybe theres something left over in the buffer. So i tried to clear the buffer several times with .erase() and .clear() and i even did something like this.
string var="";
buffer << var;
Again it cleared the buffer (i think) but didnt allow me to put anything back in it.
My question is, once you wipe a buffer is there no way to re-fill it with the same data from before? And if you can, how? I've searched far and wide for an explanation. I've never dealt with something like this so i have no clue as to what i should be doing. Any suggestions? Thanx in advance!
|
|
|
|
|
void yourecrazy()
{
string str = "you are crazy";
cout << str.c_str() << endl;
str.clear();
cout << str.c_str() << endl;
str = "you are crazy";
cout << str.c_str() << endl;
}
|
|
|
|