|
Could you clarify your question?
What do you mean by saying but then it use the same paramters for all the thread ?
--
=====
Arman
|
|
|
|
|
well I say you heartly.
I have been waiting for your answer. if i will write the post with your name then it is not good but i think what i need is what i get.(i mean answer from arman).
ok,
as you know previously about my code the loop is runing and thread created and i have made the array of threads. right.
But now all thread running but the structure variable(structur pointer actually which send the parameter to the Thread function for further process using the same values for all created thread.
e.g
for(int i=0;i<2;i++)
{
struct argument_list *l;
l=(argument_list *)malloc(sizeof(argument_list));
l->pszInFile=bufferwithpath;
l->pszOutFil=w_Output;
l->_ProtectSet=_ProtectSet;
l->hList=hList;
strcpy(l->Host,HOST);
l->hwndEncrypt=hwndEncrypt;
l->hWndinoutfiledir=hWndinoutfiledir;
l->hwndParent=hDlg;
strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str());
l->Port=PORT;
strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH);
strcpy(l->UserID,UserID.c_str());
hThread[i]=(HANDLE)_beginthread(&Thread ,0 ,<big><code>l</code></big>);
}
WaitForMultipleObjects(2, hThread, FALSE, INFINITE);
//The value of l remains same for all the created.
means ,The values show correct when the loop is going on.
But when thread call the Thread function below in that case.
hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt);
all parameter values shown same for all threads .why??? it must be different according to the thread created with.
suppose
for thread one l could be
Lparam->pszInFile ="a.wmv"
Lparam->pszOutFil="DRMa.wmv"
....
.....
.....
.....
for thread 2
Lparam->pszInFile ="b.wmv"
Lparam->pszOutFil="DRMb.wmv"
....
.....
.....
.....
i need this way for consucative thread calls
========
but it shown every time first thread's values for all other thread.
values l for first thread.
Lparam->pszInFile ="a.wmv"
Lparam->pszOutFil="DRMa.wmv"
....
.....
.....
.....
I think now you might got is it ?
void Thread(void* pArguments )
{
if( pArguments == NULL )
{
MessageBox( NULL , _T("Problem in thread") , NULL , IDOK ) ;
}
HRESULT hr=NULL;
<big><code>struct argument_list *Lparam= (argument_list *)pArguments ;</code></big> Package pkg;
static int threadID;
threadID++;
{
<big>
<big><code>hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt);</code></big> }
if(hr==S_OK)
{
MessageBox(0,L"thread gone finished" ,L"therad",0);
_endthreadex( 0 );
}
threadID--;
}
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
I think now you might got is it ?
Ok, wait a little, I will reply soon.
--
=====
Arman
|
|
|
|
|
Well. Your code has lots of things to recorrect. Though the abnormal behavior you described I could hardly connect to them. Let's start from general issues.
1) Are you using C and not C++?
2) Never use _beginthread! Use _beginthreadex instead. The first one is problematic and may cause hard-to-recognize errors! Your call should be;
<br />
unsigned int tid;
hHandle[j] = (HANDLE ) _beginthreadex(NULL, 0, &Thread, l, 0, &tid);
3) Never use _endthreadex (nor use _endthread). These functions are mainly for urgent termination situations which are not inherent [normal] in a well designed architecture. Instead do 'return 0;'.
4) You should change the declaration form of Thread function; unsigned int should be returned to indicate the exit code. Now it should be;
UINT Thread(void *pArgs)
5) Are you sure your values are different inside the thread creation 'for' loop? Anyway, going on..
6) If your in C++, use new rather than malloc [but I thing you are in C].
7) Strings are erroneous! Remember that in a multithreaded application YOU SHOULD BE VERY VERY CAREFUL WHEN PASSING STRINGS INTO DIFFERENT THREADS!
So your code is wrong. YOU SHOULD CREATE SEPARATE STRING BUFFERS PER THREAD. That is;
for(int i=0;i<2;i++)
{
struct argument_list *l = (argument_list *) malloc(sizeof(argument_list));
...
l->Host = (LPTSTR)malloc(MAX_PATH);
strcpy(l->Host, HOST);
...
8) To have a solid test inside Thread function also pass the j (loop index) to them; I mean add an extra int field to argument_list and observe its value from each thread function. They all should be different.
9) And one thing about Thread again. Never do such things;
//WaitForSingleObject(GetCurrentThread(),5000);
This makes no sense.
Finally, see what you can get from these notes. Take into consideretion each of them. Then I think you will overcome your problem.
You could tell me when you do smth.
--
=====
Arman
|
|
|
|
|
Thank you very much for your nice guideline.
and please Look at the structure once.
struct argument_list
{
WCHAR *pszInFile;
WCHAR *pszOutFil;
HWND hwndParent;
char Host[MAX_PATH];
char UserID[MAX_PATH];
char InitPackageRequest[500000];
char ScriptFile[MAX_PATH];
INTERNET_PORT Port;
HWND hList;
TagEditor *_ProtectSet;
HWND hWndinoutfiledir;
HWND hwndEncrypt;
};
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Oho, this is important. I do not know why you are using UNICODE strings though [I'm not saying this is bad ].
Try the following inside the 'for' loop instead of these two lines;
// l->pszInFile = bufferwithpath;
// l->pszOutFil = w_Output;
l->pszInFile = (LPWSTR) malloc( 2 * wcslen(bufferwithpath) );
wcscpy(l->pszInFile, bufferwithpath);
l->pszOutFile = (LPWSTR) malloc( 2 * wcslen(w_Output) );
wcscpy(l->pszInFile, bufferwithpath);
--
=====
Arman
|
|
|
|
|
l->pszInFile = (LPWSTR) malloc( 2 * wcslen(bufferwithpath) );
wcscpy(l->pszInFile, bufferwithpath);
l->pszOutFile = (LPWSTR) malloc( 2 * wcslen(w_Output) );
wcscpy(l->pszOutFile , w_Output);
--
=====
Arman
|
|
|
|
|
|
Arman Z. Sahakyan wrote: // l->pszInFile = bufferwithpath;
// l->pszOutFil = w_Output;
l->pszInFile = (LPWSTR) malloc( 2 * wcslen(bufferwithpath) );wcscpy(l->pszInFile, bufferwithpath);l->pszOutFile = (LPWSTR) malloc( 2 * wcslen(w_Output) );wcscpy(l->pszInFile, bufferwithpath);
HI !
arman when can we need to allocate the memory to the variable? In the above case
I have just try to assign that i know its wrong but , the basic question is when
can we should allocate memory?
I know that array already occupay memory at compile time , and I also konw that
we can allocate memory runtime by malloc/calloc or new in c++, but where and in which condition we have to use it.
please regret me about my spells and english.
can you kindly explain me?
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
amitmistry_petlad wrote: well now all threads are working and running but then it use the same paramters for all the thread. I confuse here why ???
thats just LPVOID.. you can typecast anything into it!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Given a MFC process and a .NET service, how does the MFC process communicate with the .NET service?
Which IPC should I use?
Thanks.
|
|
|
|
|
|
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
talihsu wrote: how does the MFC process communicate with the .NET service?
Is it your service or a 3rd party service?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
It's my service. So the MFC process does.
|
|
|
|
|
Here's a few options...
You should be able to use any of the regular methods listed here: Interprocess Communications[^]
You can also use .NET Remoting[^] but that'll require managed code on the MFC side.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
talihsu wrote:
It's my service. So the MFC process does.
com will help in this case!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I have a dropdown combo that I am populating dynamically based each character (I trap CBN_EDITCHANGE) that the user types in the edit box portion. I'd like to be able to highlight the first entry in the dropdown (so the user could arrow down if they want) WITHOUT losing the data in my editbox. (I've already subclassed the listbox so I can get rid of the "hover cursor selection") Any thoughts on how to do this? Any help would be appreciated.
|
|
|
|
|
Hi All,
In an effort to keep my mind active, I've decided to attempt to learn Unmanaged C/C++ - ideally C first and ++ later - however given the range of books and tools available, I wondered if anyone had any recommendations they could share?
In terms of tools, I have VS2005 Pro but every time I fire it up and open a MFC project i quickly get lost (and I think I'm right in thinking that a lot of what you can do in VS2005 is tied to MS platforms?), so if anyone can recommend a equally good (but hopefully more streamlined!) IDE for C, I'd be glad to hear it!
TVM,
Martin.
|
|
|
|
|
There is a free IDE called 'Dev C++' (Google for it's URL). You can do both C and C++. For a free IDE, it's pretty good. If you want to use VC++ as your IDE, try creating your applications as: Win32 Console Application or Win32 Application.
Learn C first before jumping stright into C++. Read about object-oriented programming before tackling C++, and learn about 'event-driven' programming before you step into using MFC. One book that I used when learning MFC (and I'm by no means an expert) was 'MFC Programming' by Ivor Horton. Hopefully, there is an updated version which covers the latest MFC IDEs.
Good luck, and don't get frustrated. It will take you probably 6 months after starting to use C++ before you feel comfortable with it.
John P.
|
|
|
|
|
jparken wrote: Learn C first before jumping stright into C++.
My advice would be the opposite.
Steve
|
|
|
|
|
Stephen Hewitt wrote: My advice would be the opposite.
So is this how you would say it in an opposite way?...
Learn C++ first before jumping straight into C. Read about C++ before tackling object-oriented programming, and learn about MFC before you step into using 'event-driven' programming . One book that I would never recommend when learning MFC (and I'm an expert) is 'MFC Programming' by Ivor Horton. Hopefully, there is not an updated version which covers the latest MFC IDEs.
|
|
|
|
|
Once you know C++, learning C is simply a matter of learning what's missing (for the most part). Learning C++ teaches you better coding habits however. That's how I was taught it at uni. The lecturers tried it both ways and found this way the best (or so I was told).
Steve
|
|
|
|
|
Structured programming is much easier for a first semester in programming.
We actually started with Pascal in High school and college and C was offered next in the progression with Pascal as a prerequisite.
|
|
|
|
|
I disagree. Object oriented programming is very intuitive because it lines up with the way people naturally think. That's why it was invented: to help manage the ever increasing complexity of software development by making it easier to understand. I don’t think of a door as a set of states and disconnected functions for manipulating and interrogating the state but rather as a single object. It’s often harder for people who have learnt structured programming first because they have to change their mind set, but that’s not the point under discussion.
Steve
|
|
|
|