|
I am looking for shared memory wrapper class that encrypts the shared memory. Does anyone know about this, or if there is any article on codeproject on this?
Thanks.
|
|
|
|
|
:(hi
I'm using in a MFC project thread by AfxBeginThread. I have a dialog window like a main window. Into this window I create a thread. Into this thread I create another dialog window. Into this dialog window I create a instance of a class and try to make a reference the second window. I don't know how to do it using standard functions so I pass a pointer as a parameter to constructor of this object. Example:
threadFunc(LPVOID pvParam){
.
.
.
CDlg* pDlg = new CDlg();
pDlg->DoModal();
}
now the in the second window:
BOOL CDlg::OnInitDialog(){
//here the address in the pointer "this" is 0x3322c9 like example
m_MyObject = new CMyObject(this);
}
in MyObject:
CMyObject::CMyObject(CWnd* pWnd){
//but here the address in "pWnd" is 0xdc3829 -.-"
m_pWnd = (CWnd*)pWnd;
}
Can someone to explain me what is happening?
Thanks for to spend time reading it =)
.Bispo
^_____^
[www.bispenho.com]
|
|
|
|
|
It's usually a mistake for one thread to access an object, especially a UI object, that belongs to another thread. If you must do this, consider using HWND instead of CWnd . A better solution is to post messages between threads.
bispenho wrote:
CDlg* pDlg = new CDlg();
pDlg->DoModal();
Calling the memory manager is not necessary. Why not do this instead:
CDlg dlg;
dlg.DoModal();
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
It isn't an UI object. So do I need to send message to another thread passing m_MyObject as parameter? If is correct how can I do that?
|
|
|
|
|
bispenho wrote: So do I need to send message to another thread passing m_MyObject as parameter?
Probably not, as long as the object is only accessed by one thread at a time.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Is it the same to pointers?
=^_______^=
[www.bispenho.com]
|
|
|
|
|
It's true for any object that is not thread-safe.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Because you are going to be doing complex things, you should consider using a user-interface thread. Just using a single thread function (threadFunc as you described) is considered a worker thread. I have recent experience with them, and here's what you need.
1. Derive a class from CWinThread that will be used
2. Add any pointer or whatever you want to the class definition
3. Override the OnIdle function (may be automatically overridden)
a. put all functionality in there
b. return a nonzero value if you need more CPU time, return 0 if the thread is finished
4. In your main function where the thread will start, the thread will be started like this:
CMyThread * thread = (CMyThread *) AfxBeginThread (RUNTIME_CLASS(CMyThread), THREAD_PRIORITY_IDLE, 0, CREATE_SUSPENDED, NULL);<br />
<transfer data to the thread to be used by the thread here><br />
thread->ResumeThread();
At this point, the thread will be running.
Note: you will not create your own instance of the thread, the AfxBeginThread does all the creation of the data you need. Also, put whatever data that you would normally put in the constructor and destructor, put them in InitInstance and ExitInstance respectively. The threads constructor and destructor
Note: the thread written above will be created but will not be started automatically, hence the CREATE_SUSPENDED option. This gives you a time to pass as much data to the thread as you need. Run ResumeThread() to start the thread. At this point, the InitInstance member function will be run and can do the work of the constructor. Then the OnIdle member function will continually be called repeatedly until there is either a message to handle, or you return 0 and tell the thread no more work is needed. Message passing is considered a vital but relatively uncommon task so it's given a high priority. Since message passing is uncommon, the thread will consume practically it's entire time doing your work but it still needs to occaisionally checked and dispatched messages if needed.
You can use AfxEndThread() to stop the thread inside the threads' functions, and ExitInstance will be run to do the work of the destructor.
I've used worker threads and unless you need pure work done and aren't concerned with any message passing or anything else besides pure work, then UI threads provide many benefits.
|
|
|
|
|
Thanks a lot LighthouseJ, I will test it when I get home. I'm at work and steeling a few time to resolve a private life problem. XD
=^_______^=
[www.bispenho.com]
|
|
|
|
|
I am using some object refrence and boolean variables, these are declared golbally. I know this isn't a good practice but, it is required.
I want to know Can i use nampespace to store these globals and is it of any importance.
Also I don't know how to create and use namespace.
Can you help me plz.
|
|
|
|
|
yes, you can put them in a namespace, and it's good style to do so.
to declare:
namespace myNameSpace
{
bool globalBool;
CMyObject globalObject;
...
};
...
to use:
myNameSpace::globalBool = false;
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
Just a little addition to previous replies , if you don't want to write
myNameSpace::SomeFunction() every time you call it, then you can add following line to your main() function :
using namespace myNameSpace;
And then you will be able to directly call SomeFunction() in main();
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
karmendra_js wrote:
Also I don't know how to create and use namespace.
Name Space[^]
"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
|
|
|
|
|
Hi,
Yes you can locate global variables in namespaces.
The importance of doing so depends on the specific case.
For example, if you are afraid your var's name could
conflict with another var's name, put yours in a namespace.
Another example, if you have many global variables (hope
you don't) you'd rather put them in a namespace in terms of
'well organization'.
Code:
namespace Globals
{
bool bVar1;
bool bVar2;
// any others...
} // namespace Globals
Now let's use it:
// method 1. (not preferred)
using namespace Globals;
void f()
{
bVar1 = false;
}
// method 2. (less preferred)
using Global::bVar1
void f()
{
bVar1 = false;
}
// method 3. (ok)
void f()
{
Globals::bVar1 = false;
}
|
|
|
|
|
Hi,
I want to disable multiple row select in a list control. It should select only one row at a time how can i do this.
Thanks
|
|
|
|
|
In design view select list control properties->styles->single selection
check this box , u r job is done !
Muthu Ramji.Al.V
Software developer(VC++)
Sify Limited
muthu_ramji@sifycorp.com
|
|
|
|
|
I want to do it programatically. It is in LVS_REPORT style.
What you are saying is for ListBoxCtrl.
Thanks
|
|
|
|
|
Dear friend,
if u have 2 do in code then try this,
1.
//-------- Start create a list control using dwstyle LVS_SINGLESEL
CListCtrl* pmyListCtrl=new CListCtrl;
pmyListCtrl->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_SINGLESEL ,CRect(10,10,300,200), this, 1);
//---------
2.same can be done with visual design mode as i said earlier. Both in list box & list control v have that check box. Kindly check in property dialog box
3.if u want i will help with a demo program
|
|
|
|
|
does somebody knows how to use this function
I know that it gets 7 param ,
but the weird thing is that theres is no other function to receive the File
something like ReceiveFile , there is no other function, sooo
how can I receive the transmited file ??????????????????
so how can I receive the file ??
I need to transfer one file through a sockte,,
the socket is working right , I can send and receive with functions
send () , and recv ()
but I want to know the ease way to transfer a file,,
can somebody help me ???
THANX
GOD BLESS YA
REU
|
|
|
|
|
I meet problem about read and write file
my email is fisheryj@gmail.com
----------------------------
Jerry yu
Chinese
programming fans
|
|
|
|
|
|
|
Jerry yu wrote: I meet problem about read and write file
And what exactly would that problem be?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I use vc++ just several times .I use Delphi before .
So I hope some one to help me .Because mfc is too difficult for me
thx
----------------------------
Jerry yu
Chinese
programming fans
|
|
|
|