|
Thank you so much!!
It works now! didn't know the solution is this simple!
|
|
|
|
|
Hi,
I just want to know how concurrent threads communicate to each other.
For example, there are 100 threads: thread1, thread2, thread3....thread100. AND thread1 acts as the server and all others are clients. (actually this point is not very important) All these threads are created by AfxBeginThread(...) and format liked:
UINT ThreadProc( LPVOID lpParam )
Now, thread2 sends an request to thread1 (server) for some services. (request will be sent to a global array that thread1 checks it very frequently) At this time, thread2 will suspend itself, and let thread1 to resume thread2 (ResumeThread())when thread1 thinks that it is OK to let thread2 continue. However, it is possible that thread1 will not resume thread2 very shortly due to some reasons, and it causes thread2 to wait for a long time. So, i want to add a time-out feature for thread2 here.
It is not very hard to keep track the waiting time in thread1 by using QueryPerformanceCounter(). However, how can thread1 send the time-out message telling thread2 to abort.
The main problem is TIME-OUT checking.........
*********************************************************************************
Someone told me the solution before, but i found error message when i using it:
"error C2664: 'PostThreadMessageA' : cannot convert parameter 1 from 'void *' to 'unsigned int'"
"error C2664: 'PostThreadMessageA' : cannot convert parameter 3 from 'void *' to 'unsigned int'"
Thanks Machel helping me, here is the code:
while (GetMessage(&msg, 0, 0, 0))
{
switch (msg.message)
{
case WM_USER:
HANDLE hEvent = (HANDLE)msg.wParam;
//.... Do some work.
::SetEvent(hEvent); // this tells client thread to resume.
break;
}
}
The code above is part of the thread1's message pump. Now the client thead:
HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
::PostThreadMessage(dwThread1ID, WM_USER, (HANDLE)hEvent, 0);
DWORD dwWaitResult = ::WaitForSingleObject(hEvent, dwMyTimeOutInMillisecond);
if (WAIT_OBJECT_0)
{ // I didn't timeout.
}
else
{
// I did timeout
}
**************************************************************
I think the problem is I'm using another type of thread (mine is created by AfxBeginThread) Can anyone help me?????? With example please..........
Thanks!!!! especially those helped me before..........
|
|
|
|
|
ChiYung wrote:
::PostThreadMessage(dwThread1ID, WM_USER, (HANDLE)hEvent, 0);
The 3rd parameter should be cast to WPARAM and not to HANDLE
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
oops, sorry for the mistake
Michel
If I am wrong or said something stupid, I apologize in advance ![Wink | ;)](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_wink.gif)
|
|
|
|
|
Michel Prévost wrote:
oops, sorry for the mistake
Huh???
I thought it was ChiYung
Or was it you who gave him the wrong cast???
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
The code snippet in the post is from me. And I wanted to cast the HANDLE to WPARAM .
Michel
If I am wrong or said something stupid, I apologize in advance ![Wink | ;)](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_wink.gif)
|
|
|
|
|
That's ok..........
Thanks all..............
![Big Grin | :-D](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
There is only one type of thread. Concetrate on the error message. You are passing a parameter as a HANDLE where an unsigned int is called for. Try passing an unsigned int.
|
|
|
|
|
Hi,
How can I pass an HGlobal structure from my client App to my COM server ( I´m using TLB's) ?
Thanks, Bye !
Braulio
Ps.: Is legal to pass that HGlobal if there are in different process spaces ?
|
|
|
|
|
Yes you can pass the HGLOBAL to a different process. Just make sure that the HGLOBAL is delcared with GMEM_MOVABLE flag, and then when you want to use the pointer call GlobalLock on the HGLOBAL and cast the return value to your pointer type.
As far as passing the handle to a different process, you could simply pass the handle through a member function of you COM object, however if you want your object to be very robust, I would look into the IDataObject interface.
|
|
|
|
|
Hi Kilowatt,
I´m trying to pass that HGlobal as a parameter stored in a variant ( VT_I4 ( long)), but it didn´t work , I´m using something wrong ? Maybe another type ?
I'm using TLBS so I need to use the standard types. Did you have any good link about how to use the IDataObject thing ? ( I tried to look for something and it was quite confusing).
Thanks a lot, Bye !
Braulio
|
|
|
|
|
I my app I require users to login. Each user may have different privileges
in it. But I don't want to force users to logging twice : 1st to NT then to my app. What can I do? I think I want these settings for user privileges in my app to be manageable in NT somewhere. Like an extension to local security policy or something. It also would be nice to be able to set it for a user once on a domain. Does anybody know what's the best way to do this? Where and what to look for? Thanks a lot.
|
|
|
|
|
Maybe you should just check if current user is member of some given group? Like 'false_vapor_users'?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yeah. But how can I setup privs. for user and/or group for specific operations in my app. Like one user can use this and this tab but can not this. And other can use all of them. Stuff like that.
|
|
|
|
|
This scenario assumes that 'user has a privillege to perform X' equals to 'user belongs to NT group named groupX'.
So you have to chose and hardcode some group names, and later assign your users to these groups. For example, if your app does two things - stirr and shake - you'll have two groups: coolAppGroup_stirrers and collApp_shakers. If user Bob is going to perform stirring, he has to be assigned to coolAppGroup_stirrers.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
All this means that the app should store somewhere the list of users from NT whichh I want to avoid. Because each time there is a new user in the NT list I have to add new user in my app.
|
|
|
|
|
Sorry, you're not getting it (yet). There's no list of users in your app. When your app is about to perform stirring, you're checking if current NT user is a member of NT group named coolApp_Group_stirrers.
So one more time (slowly): there... is... no... list... of... users...
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!
I see! That's interesting. Kinda cool too! Thanks!
![Laugh | :laugh:](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_laugh.gif)
|
|
|
|
|
On the other hand if I have like 158 privs. - that's a lot of groups.
|
|
|
|
|
inner wrote:
On the other hand if I have like 158 privs. - that's a lot of groups.
Yes. But do you really have 158 privs?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
if you relay on NT authentication just call GetUserName and assign privileges according the output..
|
|
|
|
|
I can get user name, but how do I know what this user is allowed to do in my app and what not?
|
|
|
|
|
I am trying to use the shell commands to put a shortcut on my desktop. I want this to work for Nt and ... for all users. How would I do this? NT and Win98 for example has different places and also it is possible that it is not C: but D: directory. Is there an easy way?
I need a "C://..." or whatever to state where this desktop directory is.
THanks.
|
|
|
|
|
char szDesktopPath[MAX_PATH]="";
if(!CoInitialize(0)){
LPMALLOC pMalloc;
if(SUCCEEDED(SHGetMalloc(&pMalloc))){
LPITEMIDLIST pidl;
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOP,&pidl))){
SHGetPathFromIDList(pidl,szDesktopPath);
pMalloc->Free(pidl);
}
pMalloc->Release();
}
CoUninitialize();
}
Admittedly, a little convoluted
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Check the following files "test.h" and "test.cpp".
When using the following code, Class View does not identify the constructor correctly,
and displays it as Global() and not as test().
If Global is defined in the same file ( test.cpp ), the bug does not occur.
Does anybody know of a solution to this bug?
test.h
-----
#define Global __declspec(dllexport )
test.cpp
------
#include "test.h"
class test {
Global test();
};
Shai Gutner
shai.gutner@schema.com
|
|
|
|