|
Thank you. I will try it out.
|
|
|
|
|
You have an array of pointers to char s called ‘stk’. As far as I can see these pointers are not initialized, so they point at some random location. You push values on the stack like this:
*stk[stkIndex++] = i;
Let’s break this up (underlined part being considered):
*stk[stkIndex++] = i
This statement evaluates to a reference to one of the elements of the ‘stk’ array. Remember these elements are uninitialized pointers.
*stk[stkIndex++] = i
This dereferences the pointer which result in a reference to some RANDOM area of memory which we interpret as a char .
*stk[stkIndex++] = i
This writes the integer truncated to a char (which is another issue with your code) to the some RANDOM area of memory. Crash!
Steve
|
|
|
|
|
|
Unless you making your own stack for learning purposes you're better off using the standard STL one:
----------------------------
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stack>
int main(int arvc, char* argv[])
{
using namespace std;
// A stack of 'int's.
stack<int> ints;
// Fill the stack.
for (int i=0; i<10; ++i)
{
ints.push(i);
}
// Now empty the stack and print the results.
while ( !ints.empty() )
{
cout << ints.top() << endl;
ints.pop();
}
return 0;
}
Steve
|
|
|
|
|
Hi all, I use IVMRWindowlessControl::GetNativeVideoSize function to read the width and height of a film. It works well if the film is in wmv format, but when the film is in MPG format, the height is negative (in my case it is -1060)
A strange thing is that if I change the extension of the file from mpg to wmv. It's OK
Is there another way to read the width and height of a film?
I'm looking forward to your answers. Thanks
|
|
|
|
|
See this[^] site is helpfuls for you
|
|
|
|
|
I tried IVideoBasic anh it's OK now. Thanks a lot!
|
|
|
|
|
Is there a way for an application with Admin privileges to discover the paths to each user's Local Settings directory?
I am writing an updater for an application that stores data for the user within the user's Local settings tree.
But the application updater needs to be able to manipulate the user data for every user on the system.
I am able to call SHGetFolderPath to get the correct path for the current user, but what about the other users?
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
hi !
dear all!
well now all threads are working and running but then it use the same paramters for all the thread. I confuse here why ??? .
I need somebody's urgent help.
Thanks in advance
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
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
|
|
|
|