|
my profile is not correct.Maybe i should make it right.
|
|
|
|
|
class CMainframe:: public CFrameWnd
{
cmainframe()
{
XOBJ* m_xobj= new XOBJ;
}
~cmainframe()
{
del m_xobj;
}
void xfunction()
{
ParaForThread =&m_xobj;
HANDLE handle = CreateThread(NULL, 0,ThreadProc, ParaForThread,0,NULL);
closehandle(handle );
}
XOBJ* m_xobj;
};
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
XOBJ* obj = (XOBJ*)lpParameter;
for(int i;i<1000;i++)
{
obj->somefunction;
}
}
my assumed simple sample,pls help;
|
|
|
|
|
you know about the code which is relevant to the problems you have.
This signature was proudly tested on animals.
|
|
|
|
|
tyr2000 wrote: relevant code? can you give me some more details about the relevant code ?
Relevant code.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thank for english teaching
|
|
|
|
|
You need to synchronize the main thread (that's the one the CMainWnd is running in) with the other thread. In addition, have you at any point told the other thread to exit? If not, it won't, until the application exits.
Without seeing code, it's difficult to say much more.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i think your answer lighten me up. after creating main thread creating the thread ,i used closehandle();do you me if i hold the handle of the thread, the problem will not hanppen? aslo there is no more synchronize work needed?
|
|
|
|
|
No, there's more to it than that. Typically, a program using an auxiliary thread will probably have one of two patterns:
A thread that does one thing then exits its thread function
The auxiliary thread exits of its own volition. The main thread can then check that the thread has exitted using the GetExitCodeThread[^] function (the functions shows a thread exit code of STILL_ACTIVE if the thread hasn't terminated), or can wait for the thread to exit using the WaitForSingleObject[^] function, using the thread handle as the handle to wait for (a thread's handle is set when the thread exits).A thread that does many things in a loop
In this case, you need some way of telling the thread that it's time to exit. In general, you could use a boolean flag that the thread can check each time round the loop (use InterlockedExchange[^] to set the flag from the main thread) or you could use an event[^] - the main thread would set the event to indicate that the other thread should exit, the other thread use WaitForSingleObject to see if the event's been set). In either case, the main thread would notify the other thread that it's time to exit, then wait for the thread to exit using WaitForSingleObject.
Use the appropriate pattern (I suspect it's the second from what you've said) when the thing that created the thread (your cmainwnd?) is destroyed.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hi to all,
i have the following problem, when the SDI-Application starts, the window is disabled i can not write anything in it, any help to solve this problem will be appriciated.
I am using Visual Studio 2005
Thanks
|
|
|
|
|
You will have to choose CEditView instead of CView for the Application to support editing by default. Either create a new project and from "Generated Class" option, choose CEditView or CRichEditView instead of CView or manually rename CView References in your project to CEditView then it should work fine.
If your question is something else, please mention it clearly.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks a lot it i did as you said and it works fine.
|
|
|
|
|
hey again i have a main frame divided to 2 parts in the upper part i should be able to give a sql request to the databse like , select and updte for example
in the lower part i shoul be able to display the reults from the sql request.
where should i implement the neccessary code for that?
and how i could get the input from the upper part? i need 2 objects from CEditView one for the input from the upper part and the second for the output and then with something like GetWindowText i read the input is this correct?
any help to solve this will be appricated,
I am using visual studio 2005 / MFC
thanks
|
|
|
|
|
Check this sample[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
hey is this the answer for my second question? i downloaded the zip file and tried to bulid it but it did not rebuild??
|
|
|
|
|
I Down Loaded the PopUpdemo project/Solution from the site after resolving a few compile errors re: the ON_COMMAND macro
(by pointing VS to the MFC includes )
I got the following Linker errors for MFC objects
I there any Special .lib I have to point to
Thankx
>Linking...
1>PopupDemo.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CWinApp::messageMap" (?messageMap@CWinApp@@1UAFX_MSGMAP@@B)
1>PopupDemoDlg.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CDialog::messageMap" (?messageMap@CDialog@@1UAFX_MSGMAP@@B)
1>PopupDemoDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall CString::~CString(void)" (??1CString@@QAE@XZ) referenced in function "protected: virtual int __thiscall CPopupDemoDlg::OnInitDialog(void)" (?OnInitDialog@CPopupDemoDlg@@MAEHXZ)
1>PopupDemoDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall CString::operator char const *(void)const " (??BCString@@QBEPBDXZ) referenced in function "protected: virtual int __thiscall CPopupDemoDlg::OnInitDialog(void)" (?OnInitDialog@CPopupDemoDlg@@MAEHXZ)
1>PopupDemoDlg.obj : error LNK2019: unresolved external symbol "public: int __thiscall CString::IsEmpty(void)const " (?IsEmpty@CString@@QBEHXZ) referenced in function "protected: virtual int __thiscall CPopupDemoDlg::OnInitDialog(void)" (?OnInitDialog@CPopupDemoDlg@@MAEHXZ)
1>PopupDemoDlg.obj : error LNK2019: unresolved external symbol "public: int __thiscall CString::LoadStringA(unsigned int)" (?LoadStringA@CString@@QAEHI@Z) referenced in function "protected: virtual int __thiscall CPopupDemoDlg::OnInitDialog(void)" (?OnInitDialog@CPopupDemoDlg@@MAEHXZ)
1>PopupDemoDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall CString::CString(void)" (??0CString@@QAE@XZ) referenced in function "protected: virtual int __thiscall CPopupDemoDlg::OnInitDialog(void)" (?OnInitDialog@CPopupDemoDlg@@MAEHXZ)
1>PopupDemoDlg.obj : error LNK2019: unresolved external symbol "public: long __thiscall CWnd::SendMessageA(unsigned int,unsigned int,long)" (?SendMessageA@CWnd@@QAEJIIJ@Z) referenced in function "protected: void __thiscall CPopupDemoDlg::OnPaint(void)" (?OnPaint@CPopupDemoDlg@@IAEXXZ)
1>.\Debug/PopupDemo.exe : fatal error LNK1120: 8 unresolved externals
1>Build log was saved at "file://j:\PopupDemo\PopupDemo\Debug\BuildLog.htm"
|
|
|
|
|
If the application has to support MFC choose either "MFC in a Shared DLL" or "Use MFC in a static library" from project properties.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I thin I did but I'll check when I back home
|
|
|
|
|
I'm doing a project. It's working fine until it tries to open a file with a Chinese character in its path.
CFileDialog ImportDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,_T("text Files (*.txt)|*.txt||"));
int iResult=ImportDlg.DoModal();
CString str=ImportDlg.GetPathName();
I think it works if I set the character set to Unicode set. I'm just wondering why it gives me question mark for the Chinese when I switch to MBCS set?
|
|
|
|
|
I guess you a haven't installed support for Asian languages in your OS.
Switching to Unicode should show you the same question marks.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Actually I do installed support for Asian languages, and it does show this Chinese in Unicode set. That's why I'm wondering.
|
|
|
|
|
Ok. In that case you could try to dump the data into a text file and open the text file.
It could be that the characters are not showable by the viewer.
Make sure you write these 3 hex. characters at the begining of the file.
EF BB BF
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Check the thread addressing the similar problem [^]
Since this is a non-Unicode application, you need to make sure that your "Language for non-Unicode programs" is set to Chinese (Simplified) and reboot. It then should work. (If you are on an English os and running a language pack, changing to the language pack does not automatically change the "Language for non-Unicode programs". This is done manually).
To make this change on Vista, see:
http:
IMO, it's better to stick with UNICODE for this kind of complex languages like Japanese and Chinese.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I have an 3 rd party API that will a fill a buffer of type LPSTR,
This buffer is actually in picture format, i have to convert make this appear in a CStatic control.
what i have:
BYTE pBuffer;
HDC hDC; //HDC handle for the CSttaic Control
API will fill this pBuffer
(LPSTR)pBuffer
I have to make this pBuffer to appear in picture format in CStatic control.
Would apprecaite any help.
|
|
|
|
|
What do you mean with 'in picture format ' ?
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]
|
|
|
|
|
This "pBuffer" i can save it as a Bitmap format like this.....
But i want to draw this pBuffer into a CStatic without converting to Bitmap...
CFile file;
CString strTemp;
char szTemp[MAX_PATH];
char *pDot;
GetModuleFileName(AfxGetInstanceHandle(),szTemp,sizeof(szTemp));
pDot = strrchr(szTemp,'.');
*(pDot+1) = 'B';
*(pDot+2) = 'M';
*(pDot+3) = 'P';
strTemp.Format(szTemp,GetTickCount());
file.Open(strTemp,CFile::modeCreate | CFile::modeWrite);
file.Write(pBuffer,dwSize);
file.Close();
|
|
|
|