|
It seems alright to me. I would do this in the same fasion.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
I second the above comment... I have done exactly this in the past but now I use a threadpool insead which will allow me to handle more than one background job. If you want more info on this I recommend this article: http://www.codeproject.com/threads/threadlibrary.asp
John
|
|
|
|
|
You can eliminate the eventThreadHasStopped event if you cause your main thread to wait on the thread handle instead. You get the thread handle when the thread is first created. So, after the main thread sets the eventThreadShouldStop it can wait on the thread handle instead of the eventThreadHasStopped. The thread does not need to do anything but exit cleanly, and then the main thread will unblock and continue running. The way you are doing it is fine too, if you do not have the thread handle. I have done what you did many times and it works fine.
|
|
|
|
|
That's interesting.
Should i ::DuplicateHandle on the handle first? I worry that if the thread exits between me setting the event that it should exit, and the main thread calling waitforsingleobject(), then i could end up with my main thread blocking forever.
Jon
using System.Beer;
|
|
|
|
|
Once you have the thread handle from the thread creation, even if the thread exits before your main thread has a chance to start waiting, the thread handle will still be signaled and your main thread will not block or wait on it, you will just see the WAIT_OBJECT_0 immediately.
Your only danger is if you wait on the thread handle and the thread fails to get created successfully. Provided the thread actually ran, the thread handle will become signaled when the thread exits, whether or not you had started to wait on it yet or not.
|
|
|
|
|
Blake,
Thankyou for your invaluable advice!
Jon
using System.Beer;
|
|
|
|
|
Hi,
I wanted to display images(*.bmp, *.jpg, t.tiff...) in a dialog box, I came across CxImage in one of the articles in the code project,But I do not know how to attach it to my project and how to use it. Can anyone please help. Or does anyone know...how to use GDI+ for displaying images.
Thanks
|
|
|
|
|
hi
If you already have bmp images, u can easily add to the Dialog using "Microsoft Forms 2.0 Image" .It is a activeX Control.
|
|
|
|
|
Who know, why Visual C++ generates other function name, but I use extern "C"
I use Visual C++ 2003 and try to export function from DLL. I declare function:
extern "C" __declspec(dllexport) char* __stdcall GetUserFromAdir(HWND ParentWindow);
When I view DLL by TDUMP (TDUMP is a utility from Borland Delphi), I see, my function GetUserFromAdir has other name (_GetUserFromAdir@4)
How shall I solve this problem?
|
|
|
|
|
Gasanov wrote:
How shall I solve this problem?
What problem? The "@4" indicates the size of the parameters (in bytes). Had your function used void , you would see "@0" instead.
I think if you use the __stdcall calling convention, it will decorate the name. Use the .def file like Blake suggests to undecorate the name.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I think he expects the completely undecorated name, so that GetProcAddress can work.
I usually do not add the 'dllexport' part and put the undecorated name into a DEF file. Always works for me.
|
|
|
|
|
Thank's.
When I exported, by using .DEF file, it work
|
|
|
|
|
Hello!
I am currently trying to make some dynamic menu, i.e. add menu items to the main menu at runtime. For the command IDs, I've registered a ON_COMMAND_RANGE handler in the message map, to intercept different commands from the menu items.
Now I wonder: is it better to use the command IDs starting from WM_USER+X or WM_APP+X ??
|
|
|
|
|
What I normally do when given such a requirement is to "block off" a set of contiguous command IDs within resource.h that accommodate for the maximum number of elements in the dynamic menu.
#define ID_DYNAMIC_MENU_START 200
#define ID_DYNAMIC_MENU_RESERVE1 200
#define ID_DYNAMIC_MENU_RESERVE2 201
#define ID_DYNAMIC_MENU_RESERVE3 202
#define ID_DYNAMIC_MENU_RESERVE4 203
#define ID_DYNAMIC_MENU_END 203
Notice I have the DYNAMIC_MENU_START and DYNAMIC_MENU_END pointing at the first and last dynamic menu item respectively. I fill in the ones in the middle as we do not want them used by other resources.
We can now set the menu range accordingly.
Add to the .h
afx_msg void OnDynamicMenu(UINT nID);
Add to the message map
ON_COMMAND_RANGE(ID_DYNAMIC_MENU_START, ID_DYNAMIC_MENU_END, OnDynamicMenu)
Add to the .cpp
void CMyClass::OnDynamicMenu(UINT nID)
{
}
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Can someone point out the error of my way for using Mutex's.
Currently I have create two named Mutexs for controlled access to two different areas of shared memory. (Scripting interface and a static library interface).
But when I test ::WaitForSingleObject(mutex,250) the return is sometimes 0x00000102 for the second mutex (g_hLibMutex), but not all the time. Sometimes its 0; which I assume is OK.
Am I using WAIT_OBJECT_0 correctly?
g_hMainMutex = ::CreateMutex( NULL,<br />
FALSE,<br />
"CSL_SharedMemLock" <br />
);<br />
<br />
g_hLibMutex = ::CreateMutex( NULL,<br />
FALSE,<br />
"Lib_SharedMemLock" <br />
);
The procedure that waits on the mutex is defined as follows:-
bool CMain_ExampleDlg::WaitForMutex(HANDLE mutex)<br />
{<br />
<br />
<br />
static HANDLE ssicMutex = NULL;<br />
bool returnValue = false;<br />
<br />
int waitReturn = ::WaitForSingleObject(mutex,250);<br />
if(mutex)<br />
{<br />
if (waitReturn == WAIT_OBJECT_0)<br />
{<br />
returnValue = true;
}<br />
else
{<br />
if(mutex == g_hSSICMutex)<br />
g_pMainMap->failedMutex++;<br />
else<br />
g_pLibMap->failedMutex++;<br />
returnValue = true;
}<br />
}<br />
::ReleaseMutex(mutex);<br />
return returnValue; <br />
}
|
|
|
|
|
All that has happened is that the WaitForSingleObject has timed out. You are only waiting 250 milliseconds for the mutex to be signalled. Sometimes this may not be long enough.
You can check for WAIT_TIMEOUT from waitReturn in the same way you are checking WAIT_OBJECT_0.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
hi all,
I want to get the Location of a exe.
suppose that a exe file in the Program file.Now I want to get the full path of that exe(C:\Program Files\...) using C++ with giving only the name of the exe
can any body please tell me the way to do it?
thanks in advance.
|
|
|
|
|
TCHAR pszBuffer[ MAX_PATH + 1 ];
::GetModuleFileName( NULL, pszBuffer, MAX_PATH );
CString strExePath = pszBuffer;
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
hi,
suppose that name of exe is "XYZ.exe"..Then how can I get the path of the exe using ur Method.?
Thanks in advance
|
|
|
|
|
the other method works only within a running program.
for you, use CFileFind or FindFirstFile and FindNextFile
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Sorry, I misunderstood you. If you have a name of an arbitrary .exe file and you have no idea where it is located, then the only way is (AFAIK) to scan the disk. You could use the MFC class CFileFind to find a file with a given name - you would have to supply in what folder to look, and you would have to recursively walk through all folders. Not a trivial task I believe...
If however the .exe in question is the .exe you are writing then you can use the code I showed you.
What exactly is your requirement, i.e. under what circumstances do you need to do this?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
hi,
I want to execute some exes programatically using C++.using WinExe() Method I can execute any exes..But I want to know about the Full path for exes. I know the names of exes only.If I know the full path of exe ,I can execute the exe.
like::
WinExe("C:\\data\\xyz.exe",-----)
Thanks in advance.
|
|
|
|
|
|
Hellow,
I need to paint a scroll bar. I need to resize the thumb according to the data. So I cant use Bitmaps to create the thumb. Can any one help me ?
shijuck
|
|
|
|
|
Hi All,
I'm in need of painting scroll bar control(all the part of the scroll bar including the tump, up/down buttons). Pls suggest any of good strategies for it.
Thanks in advance
Anurag Velekkattu
|
|
|
|