|
Is this code helpful
CMain* m_Main=(CMain*)GetParent();
m_Main->ControlsOnOtherClass
|
|
|
|
|
I have listview in the application. In that listview there are so many files I am using those files for encoding/protection process. But by the help of threading . so if a user can do the endcoding proccess as well as protection process and can add in between the running process if he can add more files in the list and also can start that files for the encoding/protection on then they can do.
how can i start the threading for that .
i have alread done the following things.
I have made one class Thread in that class I add the method beginthread.
that method call from the starting process of protection.
like .
void Therad(PVOID param)
{
Package pkg=(Package)param;
pkg.EncodeMediaContent(param1,param2 );
}
but i havent got the iead that how these paramter comes ?
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Do not launch threads by beginthread, instead use _beginthreadex. But if you are using MFC, then use AfxBeginThread global function. You should have struct with containing the parameters you want to pass the thread. Then you can pass the struct object and retrieve the parameters from there. See here[^] for more details.
--
=====
Arman
|
|
|
|
|
yes i am using win32.
Thanks for you help.
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
I faced proble with
_beginthread(functionname,0,argumentlist );
what does it mean ?
mean i have to write param1,param2,param3 or the argument list is simple integer number.
can any body explaine me detail.
it is better ,if possible with some code .
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
As I said in my previous post, only do use AfxBeginThread in MFC based apps. Otherwise use _beginthreadex and not what you are using now (_beginthread). And I guess you are using MFC because you mentioned about listview control...
Anyway, just to be answered;
I faced proble with
_beginthread(functionname,0,argumentlist);
The first param is the controlling function name which should have the following syntax;
DWORD MyThread(PVOID *pParam);
The second param is the stack size. Pass 0 for defaulting.
The third parameter is some address through which you want to pass arguments to MyThread;
struct INFO { // assume you want to pass 3 arguments
int param1;
char param2;
SomeClass *pObject;
};
INFO *pInfo = new INFO;
// initialize pInfo fields
AfxBeginThread(MyThread, 0, (PVOID ) pInfo); // start thread
// Then inside the controlling function
DWORD MyThread(PVOID pParam)
{
INFO *pInfo = (INFO *) pParam;
int p1 = pInfo->param1;
char p2 = pInfo->param2;
SomeClass *p = pInfo->pObject;
// do whatever ...
delete pInfo; // do a proper memory release
return 0;
}
--
=====
Arman
|
|
|
|
|
struct argument_list l;
l.pszInFile=wInFile;
l.pszOutFil=w_Output;
l._ProtectSet=_ProtectSet;
l.hList=hList;
l.Host=HOST;
l.hwndEncrypt=hwndEncrypt;
l.hWndinoutfiledir=hWndinoutfiledir;
l.hwndParent=hDlg;
l.InitPackageRequest=sINIT_PACKAGE_RESPONSE;
l.Port=PORT;
l.ScriptFile=COMMUNICATOR_SCRIPT_FILE_PATH;
l.UserID=UserID;
UINT Iselected=ListView_GetSelectedCount(hList);
for(int i;i<iselected;i++)
{=""
="" _beginthreadex(="" null,="" 0,="" &thread="" ,="" &l);
="" }
<pre="">
error C2664: '_beginthreadex' : cannot convert parameter 6 from 'argument_list *__w64 ' to 'unsigned int *'
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
UINT nThreadID; // might be useful later
_beginthreadex( NULL, 0, &Thread , &l, 0, &nThreadID);
--
=====
Arman
|
|
|
|
|
thanks arman now i got idea .
thanks again.
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Hi!,
Ya the application is now ok,But I need your help for continuous proccess how can it possible?
Suppose there are five files running in the protection stage. and two three more files are now added in the list and I again give the start command for protection then how these files work with the already running process.
I think you can understad the problem.
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Hi all,
How can i solve memory size problem while writing or Reading object into or from a file? what can i to do during the write operation and read operation? please help me.....
|
|
|
|
|
What is the "memory size problem" ?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Well
I wanna know how i within a function can know the number of arguments that have been passed to it.
void fun(int x,float y)<br />
{<br />
int z;<br />
<br />
printf("Arguments passed = %d",z);<br />
}
I tried using hardcore assembly tricks(_BP and _SP) and was able to do but is their any other standard way out?
Spread wat u Know!
|
|
|
|
|
Why this? Inside the function, you know [and you should know] that this function takes this or that number of arguments (in this case 2) arguments.
--
=====
Arman
|
|
|
|
|
Arman Z. Sahakyan wrote: Why this?
I wanna know how actually functions knows this.
Spread wat u Know!
|
|
|
|
|
Hi
In fact you should not define the function that way; instead you should use paramArray like in the following example:
<code>
using namespace System;
double average( ... array<Int32>^ arr ) {
int i = arr->GetLength(0);
double answer = 0.0;
for (int j = 0 ; j < i ; j++)
answer += arr[j];
return answer / i;
}
int main() {
Console::WriteLine("{0}", average( 1, 2, 3, 6 ));
}</code>
|
|
|
|
|
As far as I understand, his question is how the compiler learns the number of arguments. In other words, where they are stored and how thay are retrieved...
--
=====
Arman
|
|
|
|
|
For the first time i thought u people r goin 2 touch calling conventions but..........................
Can anybody give solution to the actual problem(code) i posted.
Hope i will get some help...
Spread wat u Know!
|
|
|
|
|
So Cmania, would you please explain your question more clearly?
Are you looking to see how the compiler knows the number of arguments or you want
to get the number of arguments that are passed to the function?
In the second case, I don't get what do you mean, because if user passes any number of
arguments rather than 2 in this case, the compiler would generate an error!!
|
|
|
|
|
I suspect that you can't. You can probably determine how many bytes are allocated on the stack using some (possibly compiler dependent) algorithm, but how many variables this corresponds to cannot be determined (although you may be able to deduce it from the code - e.g. how the variables are accessed). The size of the stack frame for
<br />
void function1(double x)<br />
and
<br />
void function2(float x, float y)<br />
would be the same.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Without using asm i would suggest adapting some stack tracing code to get the undecorated function name as a string and then parse the name. However, i'm pretty sure this will only work for C++ functions.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
You can look at the stack frame all you want, it won't help.
If there's 16 bytes, how do you know if there's 4 ints, 16 chars, etc.??
The compiler knows because it reads the source code. Unless the compiler supplies a method to
determine the number of arguments, you're not going to be able to do it at runtime.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi all,
I have generating a class SRecordset,....
/
/ SRecordset.h<br />
<br />
#pragma once<br />
#include "afx.h"<br />
#include <afxdb.h><br />
class SRecordset : public CObject<br />
{<br />
DECLARE_SERIAL(SRecordset)<br />
public:<br />
SRecordset(void);<br />
<br />
public:<br />
~SRecordset(void);<br />
<br />
public:<br />
int iNumFldCount;<br />
int iNumRec;<br />
int iTotalSize;<br />
int iRecCount;<br />
public:<br />
void SSDbConnector();<br />
void SSDataExtractor(CString sQuery);<br />
<br />
public:<br />
CDatabase dbFASP;<br />
CStringArray saDataContainer;<br />
<br />
CString sunami;
<br />
public:<br />
void SSGetFieldValue(int iIndex,CString &FldValue);<br />
<br />
};<br />
<br />
<br />
<br />
#include "StdAfx.h"<br />
#include "FASPRecordset.h"<br />
<br />
IMPLEMENT_SERIAL(SRecordset,CObject,VERSIONABLE_SCHEMA | 2)<br />
<br />
<br />
SRecordset::SRecordset(void)<br />
{<br />
sunami = "Sunami";<br />
<br />
}<br />
<br />
<br />
void SRecordset::SSDbConnector()<br />
{<br />
CString sIp,sDb,sPwd,sConn,sPort,sUn;<br />
sIp="192.168.2.17";<br />
sPort="5432";<br />
sPwd="fasp";<br />
<br />
try<br />
{ <br />
sConn = "DRIVER={PostgreSQL ANSI};SERVER=" + sIp + ";port=" + sPort + ";DATABASE=" + sPwd + ";UID=" + sPwd + ";PWD=" + sPwd + ";";<br />
dbFASP.OpenEx(sConn);<br />
AfxMessageBox("Success");<br />
}<br />
catch(CDBException *e)<br />
{<br />
MessageBox(0,"Database Connection Refused."+e->m_strError,"DataBase Connection Error",MB_OK|MB_ICONERROR);<br />
e->Delete();<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
void SRecordset::SSDataExtractor(CString sQuery)<br />
{<br />
CRecordset rsFASP(&dbFASP);<br />
CString sValue;<br />
<br />
rsFASP.Open(AFX_DB_USE_DEFAULT_TYPE,sQuery);<br />
<br />
iNumFldCount = rsFASP.GetODBCFieldCount();<br />
<br />
iNumRec = 0;<br />
<br />
<br />
while(!rsFASP.IsEOF())<br />
{<br />
rsFASP.MoveNext();<br />
iNumRec++;<br />
}<br />
<br />
iTotalSize = iNumFldCount * iNumRec;<br />
<br />
sunami.Format("%d",iTotalSize);<br />
AfxMessageBox(sunami);<br />
<br />
saDataContainer.SetSize(iTotalSize);<br />
<br />
rsFASP.MoveFirst();<br />
<br />
iRecCount = 0;<br />
<br />
while(!rsFASP.IsEOF())<br />
{<br />
for(int ic=0; ic < iNumFldCount; ic++)<br />
{<br />
sValue = "";<br />
rsFASP.GetFieldValue(ic,sValue);<br />
saDataContainer[iRecCount] = sValue;<br />
<br />
iRecCount++;<br />
<br />
<br />
}<br />
<br />
rsFASP.MoveNext();<br />
sunami = saDataContainer[1];<br />
<br />
}<br />
rsFASP.Close();<br />
dbFASP.Close();<br />
<br />
}<br />
<br />
void SRecordset::SSGetFieldValue(int iIndex, CString &FldValue)<br />
{<br />
FldValue = "";<br />
FldValue = saDataContainer[iIndex];<br />
<br />
}
i will create a object of above the class in my dialog box file and call database connection function, and call dataextract function which will provides set of data set with in CStringArray variable......
void CSerializeDbDataDlg::OnBnClickedConnect()<br />
{<br />
SRecordset *set = new SRecordset;<br />
set->SSDbConnector();<br />
set->SSDataExtractor("select name from master;");<br />
<br />
CFile file;<br />
file.Open("dragon.bin",CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);<br />
CArchive ar(&file,CArchive::store);<br />
<br />
if(ar.IsStoring())<br />
ar << set;
ar.Flush();<br />
ar.Close();<br />
file.Close();<br />
delete set;<br />
}
the file "dragon.bin" create successfully but i think it not contain all relevant data of that object
and i can't read no more data for that object. except the SRecordset Cstring variable "sunami" because i have defined it on constructor of SRecordset
void CSerializeDbDataDlg::OnBnClickedRead()<br />
{<br />
<br />
SRecordset *set1 = new SRecordset;<br />
<br />
CFile filee;<br />
filee.Open("dragon.bin", CFile::modeRead | CFile::typeBinary);<br />
CArchive arr(&filee,CArchive::load);<br />
<br />
if(arr.IsLoading())<br />
arr >> set1; <br />
<br />
AfxMessageBox(set1->sunami);<br />
<br />
for(int i=0;i<set1->iTotalSize;i++)<br />
AfxMessageBox(set2->saDataContainer[i]);<br />
<br />
arr.Flush();<br />
arr.Close();<br />
filee.Close();<br />
delete set1;<br />
}
the above code shows only a "Sunami" messagebox, it wouldn't show the CStringArray variable values because even iTotalSize is also going to be wrong............
Please don't get wrong with me, i don't know any other ways please help me...what can i do
thanks in advance
|
|
|
|
|
..and where is your overriden version of CObject::Serialize? Inside it, you should serialize (ar << XXX) and deserialize (ar >> XXX) all the data you think appropriate. Then inside the button handler, you might write like so;
// into the file
CFile file;
file.Open("dragon.bin", CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
CArchive ar(&file,CArchive::store);
set->Serialize(ar);
ar.Close();
file.Close();
--
=====
Arman
|
|
|
|
|
thank you i will try.......
|
|
|
|