|
Code-o-mat wrote: CString's default constructor initializes it to an empty string anyways, so you don't have to do that explicitly.
Indeed!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
Can I write a windows service and create a UI thread in it which should be able to identify / receive windows messages and process them? Is a window / dialog needed for a UI thread so that it can handle windows messages?
Thanx
|
|
|
|
|
Well, window messages can only be sent to a window so you will actually need one to receive window messages. But you can run a message queue in a thread that has no windows in it and handle process/thread messages (which aren't directed towards any particular window).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
You can associate a hidden window with a service.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Hi
Is it possible to associate a hidden window with a service, moreover it is generally advised not to write interactive services (which have windows) and not use MFC support for windows services. So, how do I proceed?
Thanx
|
|
|
|
|
true... interactive services are become less viable in the newer versions of windows.
So, to have some sort of UI that controls your service, you'll could write a 2nd program which interacts with the service and serves as it's UI. You can use FindWindow to get the window to post messages to. There are other ways to communicate with a service that doesn't involve a window -- named pipes, tcp, mailslots, stuff like that.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Hi, I have a application and I would like to command lien pass parameters to it. But in other exe this command line parameter is null.
STARTUPINFO SI;
PROCESS_INFORMATION PI;
SI.cb = sizeof(STARTUPINFOW);
SI.lpReserved = NULL;
SI.lpDesktop = NULL;
SI.lpTitle = NULL;
SI.dwX = CW_USEDEFAULT;
SI.dwY = CW_USEDEFAULT;
SI.dwXSize = CW_USEDEFAULT;
SI.dwYSize = CW_USEDEFAULT;
SI.dwXCountChars = 0;
SI.dwYCountChars = 0;
SI.dwFillAttribute = 0;
SI.dwFlags = STARTF_USESHOWWINDOW;
SI.wShowWindow = SW_SHOWNORMAL;
SI.cbReserved2 = 0;
SI.lpReserved2 = NULL;
SI.hStdInput = 0;
SI.hStdOutput = 0;
SI.hStdError = 0;
CString sCmdLin = " UserID";
BOOL bRet = CreateProcess( m_sProductPath+"\\B.exe",
sCmdLin,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&SI,
&PI);
After changing sCmdLin parameter to sCmdLin = "UserID" OR sCmdLin = " /UserID". But still i m unable to get the command line parameter in process B.exe. Pls suggest.
Thanks
SNI
|
|
|
|
|
Possibly you've to pass "B.exe UserID" as second parameter.
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]
|
|
|
|
|
First, note that the CreateProcess() lpCommandLine parameter is an inout
parameter in the Unicode version, so whatever you pass a pointer to technically
needs to be writable (up to 32,768 characters). If that's not feasible, you should
instead append the commandline to the lpApplicationName parameter string and pass NULL
as the lpCommandLine parameter.
Second, if you're not getting the passed commandline parameter(s) in the spawned app,
try starting the commandline parameter string with whitespace.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
|
Read this[^].
It is quite similar to what I always do when developing solutions for serial communication.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I want to do two to three tasks at the same time at regular interval ,time is important so i m using multimedia timer .
problem is ....timer run the thread only once .code is below
when I click button thread is created and multimedia timer is set.
count is an integer initialized with 0
void CTimerDlg::Onbtnstart()
{
Thread=AfxBeginThread(ThreadDisplay, this, THREAD_PRIORITY_TIME_CRITICAL,0 ,CREATE_SUSPENDED);
handle=Thread->m_hThread;
Thread->m_bAutoDelete=false;
timeSetEvent(100, 0, TimeProcVideo, (DWORD)this, TIME_PERIODIC);
}
//thread analyzing data
UINT ThreadDisplay(LPVOID lParam)
{
CTimerDlg *obj=(CTimerDlg*) lParam;
obj->abc();
return 1;
}
void CTimerDlg::abc()
{
count++;
char a[20];
GetDlgItem(IDC_STATIC)->SetWindowText("");
CString s=itoa(count,a,10);
GetDlgItem(IDC_STATIC)->SetWindowText(s);
SuspendThread(handle);
}
void CALLBACK TimeProcVideo(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CTimerDlg* timer=(CTimerDlg*) dwUser;
timer->ControlThreads();
}
void CTimerDlg::ControlThreads()
{
ResumeThread(handle);
}
modified on Friday, November 28, 2008 11:18 PM
|
|
|
|
|
|
i want to show some icons or bitmaps on status bar, how can i do this?
thanks in advance.
|
|
|
|
|
This[^]might help
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
I want to enumerates ac3filter's preferred media types, I suppose this process should be very easy, but I can't get this work.
PLZ help!
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CLSID clsid;
::CLSIDFromString(_T("{A753A1EC-973E-4718-AF8E-A3F554D45C44}"), &clsid);
IBaseFilter* pFilter = NULL;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(IBaseFilter), (void **)&pFilter);
IEnumPins* pEnumPins = NULL;
hr = pFilter->EnumPins(&pEnumPins);
if (SUCCEEDED(hr))
{
IPin* pPin = NULL;
while (pEnumPins->Next(1, &pPin, NULL) == S_OK)
{
PIN_DIRECTION pinDir;
pPin->QueryDirection(&pinDir);
IEnumMediaTypes* pEnumMediaTypes = NULL;
HRESULT hr = pPin->EnumMediaTypes(&pEnumMediaTypes);
if (SUCCEEDED(hr))
{
AM_MEDIA_TYPE* pMediaType = NULL;
hr = pEnumMediaTypes->Next(1, &pMediaType, NULL);
pEnumMediaTypes->Release();
}
pPin->Release();
}
pEnumPins->Release();
}
return 0;
}
A Chinese VC++ programmer
|
|
|
|
|
I'm not an expert on Pins, but I'm sure you can give more information on your problem.
*What* didn;t work? Does it not compile?
Does CoCreateInstance even work?
Does it give success code, but no Pins?
Do you get enumerators, they just are empty?
Etc.
We're not going to visit you and sit at your computer and use the debugger. China is a long way from here!
Iain.
|
|
|
|
|
Thank you Iain.
As I commentted in the code, everything looks finely.The filter can be created; the pins can be enumerated; and the direction of the pins can be queried too, but when it comes to the media types of a given pin, IEnumMediaTypes::Next always returns S_FALSE.
So I can't numerates media types on a given pin.
A Chinese VC++ programmer
|
|
|
|
|
I am implementing multi-threaded application in C++ in which I have 2 functions i.e. 1. Read 2. Write and both are sharing one global variable.
There are 10 threads,1 thread will use write function and rest 9 will use read function.When writing is taking place, all thread should wait else remaining 9 threads should not wait to read.
Now my question is how to use the synchronization technique so that 9 threads should not wait if no writing is taking place.
Thanks
|
|
|
|
|
Use CSemaphore with CSingLock/CMultiLock. You can call a lock on the object/resource while writing is in progress
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
But Semaphore is use to limit the number of thread, where as my requirement is different.
I don't want to limit my number of read and write thread. Actually i want that if any writing there is in progress then other all thread ( read and write) must wait. where as any number of reading thread can run concurrently.
I believe that this can be archived by WaitForMultipleObject. but how to use it.
Any link for the same or any hint.
Thanks
|
|
|
|
|
Semaphore does allow you to access the resources when the threads are limited, and is not used to limit the number of threads.
MSDN - ***An object of class CSemaphore represents a "semaphore" — a synchronization object that allows a limited number of threads in one or more processes to access a resource
If you want to use WaitForMultipleObject than you can store the handles of the thread in an array and then pass this as a parameter to it.
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
In such scenario (one writer, multiple readers), you can avoid using critical section using guards 'around' your variable. Suppose you use two integers, m_iSeqId1 and m_iSeqId2 (both initialized to 0). Your writer thread will first increase m_iSeqId1, then update the new value, then increase m_iSeqId2 (so that it becomes equal to m_iSeqId1). Your reader threads first read m_iSeqId2 (yes m_iSeqId2 and not m_iSeqId1), read the value and then read m_iSeqId1. If both sequence Ids are the same, the value can be read and is not corrupted. If the Ids are different, the read should repeat the full operation until both Ids are the same.
But, this is only usefull when you are working with variables that cannot be set in one single instruction (e.g. an array, a string, an object, ...). Assignements of simple types (like int, char, ...) are atomic.
|
|
|
|