|
jdnx wrote:
but in other sites it will return some "." ".." dirs and lost some dirs.
Some OSs support the . and .. convention while others do not.
jdnx wrote:
...I called CInternetFile's GetLength Function but it can not return correct file length,also very strange...
Not all FTP software running on the server has implemented the "length" function.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
i have a error when i used function NetMessageBufferSend.These are "error LNK2001: unresolved external symbol _NetMessageBufferSend@20" and"fatal error LNK1120: 1 unresolved externals"
|
|
|
|
|
Hope you have not missed to link with Netapi32.lib
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
VC++2003: Question about "Pointers to member functions" ~~~ when the pointers are inside a struct data member of the class type.
I am using VC++ .NET 2003.
It is OK when the case as F1 in the sample code below. But it can not compile in the case as F2 in the thread in sample code below.
Any idea? Thanks!!
-----------------
class CMyLoopbackDlg : public CDialog
{
public:
afx_msg void OnBnClickedStart();
public:
void PutMsg(CString sTxt, bool bDbgOnly = false);
public:
CWinThread* m_pThTest;
void (CMyLoopbackDlg::*F1) (CString, bool);
struct InfoThTest
{
void (CMyLoopbackDlg::*F2) (CString, bool);
HANDLE hEvent_A;
HANDLE hEvent_B;
} m_InfoTest;
};
void CMyLoopbackDlg::OnBnClickedStart()
{
#define __CASE_STRUCT__ // The option switch here.
#ifndef __CASE_STRUCT__ // This case works well.
F1 = PutMsg;
(this->*F1) ("1: Using Ptr_to_member in Start().", false);
if(!m_pThTest) {
m_pThTest = AfxBeginThread(TestThreadProc, this);
}
#else
m_InfoTest.F2 = PutMsg;
(this->*m_InfoTest.F2) ("Struct: Using Ptr_to_member in Start().", false);
if(!m_pThTest) {
m_pThTest = AfxBeginThread(TestThreadProc, &m_InfoTest);
}
#endif // __CASE_STRUCT__
}
UINT TestThreadProc(LPVOID pParam)
{
#ifndef __CASE_STRUCT__
CMyLoopbackDlg& ref = *(CMyLoopbackDlg*)pParam;
ref.PutMsg("--> TestThreadProc ");
Sleep(5000);
ref.PutMsg("<-- TestThreadProc ");
#else
CMyLoopbackDlg::InfoThTest* pp = (CMyLoopbackDlg::InfoThTest*)pParam;
(pp->*F2) ("Test", false);
(*(pp->F2)) ("Test", false);
#endif // __CASE_STRUCT__
return 0;
}
Maxwell Chen
|
|
|
|
|
Hello,
Using heavy preprocessor switching like that greatly decreases code readability. It makes it very difficult to understand!
Anyway, I found your problem.
Take a deeper look at your following code section:
UINT TestThreadProc(LPVOID pParam)
{
#ifndef __CASE_STRUCT__
CMyLoopbackDlg& ref = *(CMyLoopbackDlg*)pParam;
ref.PutMsg("--> TestThreadProc ");
Sleep(5000);
ref.PutMsg("<-- TestThreadProc ");
#else
CMyLoopbackDlg::InfoThTest* pp = (CMyLoopbackDlg::InfoThTest*)pParam; (pp->*F2) ("Test", false);
(*(pp->F2)) ("Test", false);
#endif // __CASE_STRUCT__
return 0;
}
What do we see here?
<list>CMyLoopbackDlg& ref = *(CMyLoopbackDlg*)pParam; Here you cast the parameter to an object of type CMyLoopBackDlg This is OK, since you passed the this pointer to the function.
CMyLoopbackDlg::InfoThTest* pp = (CMyLoopbackDlg::InfoThTest*)pParam; Here you cast the parameter to an object of type InfoThTest* . This is OK, since you passed a pointer to the member variable.
In the first case you call a member function and you pass the this pointer implicitly.
In the second case, your error is that you call a member function without the implicit this pointer. The compiler has no object that it can use to call the member function with! There are two solutions to this problem.
1: Make the member function static so it doesn't need the this pointer
2: Pass the this pointer as a member of the struct and cast that to the dialog type:
struct InfoThTest
{
void (CMyLoopbackDlg::*F2) (CString, bool);
CMyLoopBackDlg* pThis;
HANDLE hEvent_A;
HANDLE hEvent_B;
} m_InfoTest;
See the C++ Faq Why can't I use member functions as callbacks?[^] for more information.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hello Bob, thanks for your reply!!
I live at Taipei (+8 timezone) and it is Saturday now. My PC at home does not have a VC++ at all. I will try your suggestions next Monday at office, and continue the discussion ...
Bob Stanneveld wrote:
Using heavy preprocessor switching like that greatly decreases code readability. It makes it very difficult to understand!
That preprocessor switch was just seen in this demo only, in order to put two different methods in one single function body ( OnBnClickedStart() ) to post question on the forum. Otherwise people who play around with this sample code would have to alter some //'s (or /* */) instead of only one single line at:
#define __CASE_STRUCT__ // The option switch here.
I don't use it in my actual code. Sorry about that!
I do not quite remember / am not sure enough about this way failed also:
UINT TestThreadProc(LPVOID pParam)
{
CMyLoopbackDlg* pThis = (CMyLoopbackDlg*)pParam;
(pThis->*F1) ("Hello 123...", false);
return 0;
} Anyway, I'll be back next Monday!
-----------------
class CMyLoopbackDlg : public CDialog
{
public:
afx_msg void OnBnClickedStart();
public:
void PutMsg(CString sTxt, bool bDbgOnly = false);
public:
CWinThread* m_pThTest;
void (CMyLoopbackDlg::*F1) (CString, bool);
struct InfoThTest
{
void (CMyLoopbackDlg::*F2) (CString, bool);
HANDLE hEvent_A;
HANDLE hEvent_B;
} m_InfoTest;
};
void CMyLoopbackDlg::OnBnClickedStart()
{
#define __CASE_STRUCT__ // The option switch here.
#ifndef __CASE_STRUCT__ // This case works well.
F1 = PutMsg;
(this->*F1) ("1: Using Ptr_to_member in Start().", false);
if(!m_pThTest) {
m_pThTest = AfxBeginThread(TestThreadProc, this);
}
#else
m_InfoTest.F2 = PutMsg;
(this->*m_InfoTest.F2) ("Struct: Using Ptr_to_member in Start().", false);
if(!m_pThTest) {
m_pThTest = AfxBeginThread(TestThreadProc, &m_InfoTest);
}
#endif // __CASE_STRUCT__
}
UINT TestThreadProc(LPVOID pParam)
{
#ifndef __CASE_STRUCT__
CMyLoopbackDlg& ref = *(CMyLoopbackDlg*)pParam;
ref.PutMsg("--> TestThreadProc ");
Sleep(5000);
ref.PutMsg("<-- TestThreadProc ");
#else
CMyLoopbackDlg::InfoThTest* pp = (CMyLoopbackDlg::InfoThTest*)pParam;
(pp->*F2) ("Test", false);
(*(pp->F2)) ("Test", false);
#endif // __CASE_STRUCT__
return 0;
}
Maxwell Chen
|
|
|
|
|
UINT TestThreadProc(LPVOID pParam)
{
CMyLoopbackDlg* pThis = (CMyLoopbackDlg*)pParam;
(pThis->*F1) ("Hello 123...", false);
return 0;
} This case (passing this pointer to callback) is not able to compile!!
------ Build started: Project: MyLoopback, Configuration: Release Win32 ------
Compiling...
ScrCtrl.cpp
MyLoopbackDlg.cpp
MyLoopbackDlg.cpp(304) : error C2065: 'F1' : undeclared identifier
MyLoopback.cpp
Generating Code...
Build log was saved at "file://d:\MyLoopback_Test_Ptr_to_MemFunc\Release\BuildLog.htm"
MyLoopback - 1 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
Maxwell Chen
|
|
|
|
|
Hello,
I think that it's illegal to call delegates from a non member function. Therefore you can assign values to F1 , but you canno't call the delegate. (Delegates are member function pointers.)
I created the following workaround:
The class
class CMyLoopbackDlg : public CDialog
{
public:
afx_msg void OnBnClickedStart();
void PutMsg(std::string sTxt, bool bDbgOnly = false);
typedef void (CMyLoopbackDlg::* Delegate)(CString, bool);
Delegate F1;
struct InfoThTest
{
CMyLoopbackDlg pThis;
Delegate F2;
HANDLE hEvent_A;
HANDLE hEvent_B;
}; m_InfoTest;
public:
void InvokeDelegate(Delegate pfn, CString sParam1, bool bParam2)
{
ASSERT( pfn );
Del = pfn;
(this->*Del)(sParam1, bParam2);
}
private:
Delegate Del;
};
The calling code:
unsigned TestThreadProc(void* pParam)
{
CMyLoopbackDlg* p = (CMyLoopbackDlg*)pParam;
p->InvokeDelegate(p->F1,
"Hellp 123...", false);
return 0;
}
You can use overloading of the InvokeDelegate function to call different member functions.
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hello,
My original intention was to hide / to prevent from passing the whole CMyLoopbackDlg interface (either in poiter or in reference form) into the thread callback. I just hoped that the member structure could carry some functions of CMyLoopbackDlg to the thread callback as well as the handles to events, (... since that single object of CMyLoopback is there, and the data mamber m_InfoTest is public. And I don't want static member function stuffs...)
AfxBeginThread(TestThreadProc, &m_InfoTest); The solution (InvokeDelegate) still requires the exposure of CMyLoopbackDlg. This would be far from my intention.
Maxwell Chen
|
|
|
|
|
Hello,
There is a solution for your problem, but I think that it is a little bit cumbersome. (Actually there are many solutions to the problem, but all have their pro's and con's.)
One solution:
You create another worker thread, that has access to your dialog and everything else. That worker thread waits for one or multiple events. You other thread sets one of those events and your extra "observer" thread takes appropriate actions.
Other solution:
You demote the functionality that your thread needs to a special base class. You can also create a pure interface for this (only abstract methods). Pass a pointer or reference to this interface and your problem is solved.
Example:
class YourBasicInterface
{
public:
virtual void SetYourEvent1() = 0;
virtual void SetYourEvent2() { ::SetEvent(hYourEvent2); }
private:
HANDLE hYourEvent2;
};
class YourDialogClass : public CDialog, public YourBasicInterface
{
};
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hello,
The solution 2 (class YourBasicInterface) is interesting. I will consider this. Thanks!!
Maxwell Chen
|
|
|
|
|
Can som1 explain me the method of how TA_TOP is calculated . ?Have any1 any idea abt it ...
Regards
|
|
|
|
|
Anonymous wrote:
Have any1 any idea abt it ...
I have no idea what you are talking about. Be a bit more elaborative.
Steve Mayfield: "Coding in VB is like riding a tricycle...once you figured out how to peddle, its really hard to fall off."
My Articles
|
|
|
|
|
Okay ... and Sorry ... thing is that I want to replicate wat I have drawn onmy Window with the help CDC Funcs in another lang. I am following the same source code. Now at point I am stuck becoz in the code there is a statement ....
pDC->SetTextAlign(TA_TOP);
How Do I calculate it ... What is exactly the bounded rectangle ... how i get its specs ???
Regards
|
|
|
|
|
Looks like you want to get the dimensions of text or its bounding rectangle according to the selected DC. You can use CDC::GetTextExtent function for this.
If you are confused about TA_TOP value, check it Here[^]
Steve Mayfield: "Coding in VB is like riding a tricycle...once you figured out how to peddle, its really hard to fall off."
My Articles
|
|
|
|
|
Hi,
The subject may be a little off, but anyways...
I wonder how I can make a CEdit behave "properly" in a CWnd. I want it to behave the way it does in a CDialog.
When I place a CEdit in my CWnd, I can't use delete on it, I can't use tab to jump between ctrls and I can't select the text in a CEdit(yes, I've tried using setsel(0,-1)).
So I wonder if anyone please can help make my CEdits behave like in a CDialog.
Regards
Markus
|
|
|
|
|
You need to implement the IsDialogMessage function in a PreTranslateMessage handler. See IsDialogMessage in the docs for more information.
onwards and upwards...
|
|
|
|
|
If I understood you right, I'm supposed to override the PreTranslateMessage handler in my CWnd, and call the IsDialogMessage from there, like this:
BOOL CMyWnd::PreTranslateMessage( msg )
{
if( IsDialogMessage( msg ) )
return TRUE;
else
return CWnd::PreTranslateMessage( msg );
}
Sadly it didn't work, I still can't use delete or tab in my CEdit. And the messages doesn't come to the function, at least not what I can see.
Did I misunderstood you, or have I done something wrong?
|
|
|
|
|
How can i find out what the current view mode (details, thumbnails, etc.) of a CFileDialog is?
I want to save the current mode so when i re-open the dialog i can open it using the same mode. I do know how to open a CFileDialog in a specific view mode but i don't know how to ask the dialog what its current view mode is.
Any help would be greatly appreciated.
Thomas
|
|
|
|
|
1.what is top-level window?
2.how to enumerates all top-level windows?
I love you not for whom you are, but who i am when I'm by your side
|
|
|
|
|
gohappy_1999 wrote:
1.what is top-level window?
A top-level window is any window that is not a child window. Top-level windows do not have the WS_CHILD style.
gohappy_1999 wrote:
2.how to enumerates all top-level windows?
You can do that by using EnumWindows API
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Thank you very much!
I love you not for whom you are, but who i am when I'm by your side
|
|
|
|
|
I have some problems to make a network component.
It is a "TIME_WAIT" state on client socket.
When the socket is in "TIME_WAIT" state, it cannot connect into any remote server.
How can I avoid "TIME_WAIT" state?
Or, is there any function that can check a socket in "TIME_WAIT" or not ?
I disconnect all sessions using "DisconnectEx" function for re-using socket.
And, all sockets are pre-binded.
There are no problem when I disconnect client from server.
But, client disconnects itself and then socket falls in "TIME_WAIT" state.
I tryed to remove that state, but I can't. (failed..all)
I applied handshaking routine, LINGER option and changing into blocking mode..
As you know, TIME_WAIT state's duration is so~~~~ long!!
So, I want to know, how to check it or avoid it. ( TIME_WAIT state )
NOVICE FOREVER!!!
|
|
|
|
|
I need information ( mathematical basics ) about JPEG and JPEG2000 file formats . How can I convert BMP file to JPEG one . I have the all information I need about BMP . But I can't find info about JPEG . Could You recommend me some articles in Internet , devoted to JPEG construction .
|
|
|
|
|
A good starting point is http://www.wotsit.org/
"An education isn't how much you have committed to memory, or even how much you know. It's being able to differentiate between what you do know and what you don't." - Anatole France
|
|
|
|