|
::GetWindowThreadProcessID
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
ok let me see if I can articulate my problem. If I don't let me know.
I have a class called clientsocket that Is a derived from CAsyncSocket. I've overridden OnReceive to just put a AfxMessageBox on the screen when it is triggered.
ok heres the problem.
When I create the listening socket and accept the connection from inside a thread the OnReceive never triggers. I can send messages from the server to client but never get the Onreceive when sending something from the client to the server. The part that I can't figure out is that if I cut and paste the exact same code into a method that is called by a button on the main dialog window it works correctly. just not when I put the code in a thread... does this make sense? if not let me know and I can try to elaborate.
|
|
|
|
|
How do you know the routine isn't getting called? Have you set a breakpoint in the routine?
If you are just going by the lack of a message box, then maybe it is caused by trying to access windows in another thread and thus failing.
Instead of calling AfxMessageBox from a worker thread, just try ::MessageBox (NULL, "Made it", "Made it", MB_OK);
But these are all guesses.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I thought about that and added a break point put it doesn't break so I assume it never gets in there.
anybody that wants a copy of the code let me know and I can send it to them...its small...about 35k.
|
|
|
|
|
I just read somewhere that its bad to try to use a CSocket in a workerthread because of a lack of a message pump. could this possibly be my problem...theres nothing in there to handle the OnReceive?
|
|
|
|
|
I think it should be okay in a separate thread. I have written exactly the same code in the past, where I derived a class from CAsyncSocket and ran it in a separate thread without any problems. (For the thread, I derived a class from CWinThread)
At the risk of stating the obvious, you did do an AsyncSelect( FD_READ|.... ) at some point, to enable the ::OnReceive virtual function.
I can have a (quick, as I don't have much spare time) look at your code if you like.
Dharminder S. Birdi
|
|
|
|
|
hello -- i am trying to use both isalpha() or isdigit() in my code and they aren't working. I have the following code
next_state WhatIs( char chrSymb )
{
if (isdigit(chrSymb)) return digit;
if (isalpha(chrSymb)) return letter;
if (chrSymb == '_') return underscore;
else return not_char;
}
I continually get 'not_char' from this. I am afraid it is that I am sending a char into an int argument. Here is how I call the function.
input = WhatIs( MyString[i] ); where MyString is a string from the STL. When I try to step into this function I get a prompt to "Enter the path for _CTYPE.C" In my header I include:
#include <ctype.h>
Any ideas what I am doing wrong?
thanks,
tim
---------------------------------------
Tim Booher
|
|
|
|
|
Well, on most systems, a char is a signed number from -128 to 127. Considering that the characters you are trying to test are in range of 0-127, you shouldn't be having a problem.
As far as the prompt for _CTYPE.C, you must not have installed the CRT source when you installed the compiler (God I LOOOOOVE having the CRT source.)
What are you doing wrong? I don't know. What is the value of chrSymb when it is failing?
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Hi,
I'm working on a multi-view application and I'm trying to change the mouse cursor when it is moved over one of the views.
I've got the following code in the view:
BOOL CTheView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
::SetCursor(AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(m_mouseCursor)));
return TRUE; //Handled
}
I'm doing it this way since I've disabled the class cursor with:
::SetClassLong(this->GetSafeHwnd(), GCL_HCURSOR, NULL);
and initialised the m_mouseCursor attribute with the appropriate system cursor type. [This appears to work since a later attempt to GetClassLong(GCL_HCURSOR) returns NULL.]
However, when I drag the mouse over the view, I get the required cursor flickering with the standard mouse cursor. When the mouse stops moving, the standard mouse cursor is the one displayed. This eliminates the cause being an incorrect cursor id, since the correct cursor actually appears, but overwritten shortly after.
I suspect the problem to be due to the fact that I have a number of views in my application, but the cause is unfortunately not clear.
If anyone can shed any light on this, your help will be much appreciated.
|
|
|
|
|
My first guess is you're calling the global scope SetCursor function and you need to call the one that is a member of your window. Remove the :: and see what happens.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Thanks Christian,
It wasnt that. It turned out to be a silly error. Another place in the code was calling BeginWaitCursor() EndWaitCursor(). Turns out EndWaitCursor() simply resets the cursor to the standard arrow cursor, not to the previous cursor as would be logical.
|
|
|
|
|
I find the step through function useless in Visual C++ because it always takes you into the machine code -- I find this very cool, but I can't follow the execution of my program because it takes me through so many details. In visual basic I step through the code all the time, because I can watch what happens. Is there any way to set up my debugger so it just steps through _my_ code and doesn't go into all the library files?
I would be very happy if you can help me . . .
tim;)
---------------------------------------
Tim Booher
|
|
|
|
|
It steps into the library files where the source is not available ( such as API calls ), just use shift-F11 to step out again when it does that.
The excellent 'Debugging Windows' book by John Robbins covers enough asm to help you start finding the asm output useful. So they tell me, I never had time to make head nor tails of it
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Thanks -- that is a lot more helpful, but what do you mean by (the source is not available) if the source were not available -- then how could the debugger step into the the source.
cheers,
Tim
---------------------------------------
Tim Booher
|
|
|
|
|
The C++ source for, for example, ::EnumWindows is not given to us, so it steps into the actual compiler generated code, which is obviously going to be there, otherwise you couldn't run it. The source for MFC is installed with VC, which is why you can step into the operations of MFC classes.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I personally use F-10 to step over my code while watching variables in watch and heap or stack in memory view.
F-10 mostly avoids the whole assembly language dump which will only happen when you encounter functions with no associated debug info. You usually get Can't trace into system dll's if you try to "step in to" an API function like
::CreateWindow(). You can if you like step through the MFC wrapper classes and i believe crt. The visual C++ debugger is more complex than VB, but complexity means power!!!
Maybe your seeing assembly because you viewing your code in disassembly. Next time try closing the dissassembly window and click the yellow arrow to see what line your on...
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Thanks so much for all your help -- I learned a ton about debugging today and blew through a program that would have kept me up all night last week.
Now I reckon I'll have to find someone else's question and give them a hand. thanks,
tim
|
|
|
|
|
How to retrieve the name of the domain under which a NT process is running?
Chen Venkataraman
|
|
|
|
|
Seems like <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/ntlmapi2_07zj.asp">NetWkstaUserGetInfo</a> is what you're looking for.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks.
Chen Venkataraman
|
|
|
|
|
I'm working on a map editor for my game and I've ran into some problem. To give you an idea of what's it supposed to do, think of the old game mine-field. Now my program is supposed to put an unlimited number of those mine-objects manually. The number of the 'mines' could range between 0 and 384. The 'mine' is derived from a class.
I solved the problem by defining an array with the maximum of 384 mine-objects, each representing a place in the map. And when I want to actually put the mine I just "activate" it. It works, but it's a waste of a lot of memory because it's 384 mine-objects, 384 prize-objects etc etc. You get the idea.
How can I implement a better way to define new objects at run time? I figured memory allocation would help but how does it work with classes? I only used it for simple arrays not objects that contain various types of variables.
Thanks in advance,
Isaac Sasson,
Small time programmer - complainer at large.
Sonork ID 100.13704
|
|
|
|
|
You can use STL vector , which works pretty much like the arrays you're used to, with some extra capabilities, like the ability to grow on demand. If your mine objects are instances of a class called (for instance) CMine , then you declare your vector like this:
std::vector<CMine> vectorMines; Initially, a vector is empty. You can populate it with
vectorMines.push_back(CMine(...)); Elements of a vector are accessed in a way similar to a built-in array:
for(size_t i=0;i<vectorMines.size();++i)
{
vectorMines[i].draw();
} STL comes wiht other containers (list s, map s) offering different features and trade-offs (random access vs. random erasing, for instance). Look for some STL tutorial on the net and start enjoying this great library.
Regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Functionally, there is little difference between:
main ()
{
CMine theMines [384];
}
and
main ()
{
CMine *ptheMines = new CMine [theNumberINeed];
... do stuff ...
delete [] ptheMines;
}
Don't sweat creating an array of the specific number of mines you need after you determine the count.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
The problem is I don't know the number of "mines" nor does the user. It's desgined that way you just add mines whenever and wherever you like at run time, it doesn't ask you for the number of "mines" you're going to use.
I used your solution for the game itself when the number is set after reading the level data from a file.
The editor however is a bit different.
Thanks anyway.
Isaac Sasson,
Small time programmer - complainer at large.
Sonork ID 100.13704
|
|
|
|
|
Hello friends !
How are you ?
I need a small help . Please !
Well, I see that CFile::Open with CFile::modeCreate|CFile::modeWrite
When I want to write into the file if it exist and if not to create it works excellent in win98
but on win2000 and XP it success only to create the file if it was not ,and when the file (.dat) already exist it doesn't success to perform modeWrite and should have first to do : CFile::remove()
my question :
1. Why ?
2. How could to do it at the best and elegant way ?
3. Are there a function to know if a specific file exist or not ? which ?
thanks in advance
|
|
|
|