|
I tried that and whenever it got a folder, and I tried to display the name of the folder, it was just a period. I'll give that another try though.
|
|
|
|
|
Yeah. Those functions could return periods, which indicate parent folder.
Kuphryn
|
|
|
|
|
Change the function you are using to scan through a folder to a recursive one. Whenever you encounter a folder, call that function again with the sub folder path. I have done this and it works.
|
|
|
|
|
Hi.
I have this class:
<br />
class CNetwork<br />
{<br />
public:<br />
void InitNetwork();<br />
DWORD WINAPI ListningForClients(LPVOID Arg1);<br />
void SendToClient(CLIENTS TheClient,char *Command);<br />
<br />
<br />
private:<br />
char ServerAddress[64];<br />
int ServerPort;<br />
struct hostent *ServerHost;<br />
int nReturn;<br />
<br />
SOCKET s; <br />
WSADATA wsda; <br />
SOCKET sListen, sClient;<br />
SOCKADDR_IN addr, RemoteAddress; <br />
};<br />
But I'm having some problems with the DWORD WINAPI ListingForClients call
DWORD WINAPI ListningForClients(LPVOID Arg1)<br />
{ <br />
......<br />
if (NumClientsConnected < MaxConnections)<br />
{<br />
CreateThread( NULL, 0, &ListningForClients, 0, 0, 0);<br />
}<br />
......<br />
}
This ofcourse calls itself, theirby creating a new thread..
But i'm getting this error when compiling.
CNetwork.cpp(42) : error C2276: '&' : illegal operation on bound member function expression
The function works when it's not incapsueled in a class!!
Thank for anyhelp.
|
|
|
|
|
Make ListningForClients static . For further info on callbacks over member functions, check Mike Dunn's C++ FAQ (top of this page), paragraph 6.1.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Okay I tried to make it static. but now i get some errors:
example: illegal reference to data member 'CNetwork::sListen' in a static member function
Might I ask, what does Static do?
|
|
|
|
|
Well, Mike's FAQ explains it all, but I'll try to clear the issue up myself. Non-static members have, so to say, a hidden parameter pointing to the object the member function applies to (the this parameter, if you want to see it like that). After changing ListningForClients to static , the member function is no longer bound to any particular object via this , hence the error. This is what static means when applies to member functions: general functions not associated to particular instances of the class.
The way out of this problem is to use a callback paramter CreateThread provides just for this sort of things. In this parameter you can store a pointer to the relevant object and then use it accordingly. Pseudocode follows:
class CNetwork
{
...
static DWORD WINAPI StaticListeningForClients(LPVOID Arg1)
{
CNetwork* object=(CNetwork*)(Arg1);
object->ListeningForClients();
}
void ListeningForClients()
{
}
...
CreateThread( NULL, 0, &ListeningForClients, this, 0, 0);
}; Hope you get the idea. Please read the FAQ for further clarification. Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The problem is that you do not need to pass the Address of the the function ListenForClients, because ListenForClients as a symbol is already an address.
Just get rid of the ampersand.
CreateThread( NULL, 0, ListeningForClients, this, 0, 0);
|
|
|
|
|
How can I open an .exe file to see the actual code?
Alex
|
|
|
|
|
Use Visual Studio. Open as binary.
|
|
|
|
|
You can't see the actual code, just the machine language binary
numbers put out by the compiler/assembler/linker.
To get a better understanding of what's inside an exe file,
see the following article by Matt Pietrek:
http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx
http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/default.aspx
|
|
|
|
|
I need to loop through each pixel in a "device context" in GDI+. In the old GDI I just did this:
if(pDC->GetPixel(point) == crLineTwoColor)
{
::SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZEWE ) );
}
but now with GDI+ I don't know how to check the "device context" pixel by pixel to check for a certain color. I check the documentation, but there is not function called GetPixel() in the Graphics class. I see there is a GetPixel() function in the Bitmap class, but I don't know how to put the contents of a device context into a Bitmap variable.
How do I check the "device context" pixel by pixel to check for a certain color using GDI+? or How do I put a copy of what is on my device context in a Bitmap variable so I can use the GetPixel() function?
P.S I know that it isn't called a device context anymore in the GDI+, but I don't know what else to call it.
Thanks in Advance!
Greg
|
|
|
|
|
Is there simple byte_swap function or does anyone know how to do it?
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
What do you mean by byte swapping? Can you give an example of what you're after?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am trying to read a legacy file format where data is written as follows:
snip--
Integers are 2-s complement, with high-order bytes first. Real numbers are in 32-bit IEEE 754 format with high-order bytes first.
im trying to figure out how to get the binary data into a float...
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
As for the integers, here's a small routine (beware, not tested):
int swap_int(int x)
{
int y;
char *p0=reinterpret_cast<char *>(&x);
char *p1=reinterpret_cast<char *>(&y);
p1[0]=p0[3];
p1[1]=p0[2];
p1[2]=p0[1];
p1[3]=p0[0];
return y;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
void ImageEncDec::ByteSwap(PWORD imptr, UINT length)
{
PWORD item;
PBYTE hi;
BYTE temp;
for( UINT i = 0; i < length; i++ ) {
item = &imptr[ i ];
hi = (PBYTE)item;
temp = hi[0];
hi[0] = hi[1];
hi[1] = temp;
}
}
John
|
|
|
|
|
template <class T> T ReverseBYTES (T &t)
{
int bytes = sizeof(T);
T rev;
BYTE *ptr1 = (BYTE *)&t;
BYTE *ptr2 = (BYTE *)&rev;
for (int x = 0; x < bytes; x++)
ptr2[x] = ptr1[bytes - x - 1];
return rev;
}
Works with data of any size.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
sweet! thanx.
I also found a fun little function tucked away in winsock2.h...
u_long ntohl (
u_long netlong
);
The ntohl function takes a 32-bit number in TCP/IP network byte order and returns a 32-bit number in host byte order.
in other words: byte swap. Who'd a thought.
Anyway, I like your approach better, it's more generic. Thanks again!
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Should be noted that the ntohl (and corresponding htonl) wont actually swap any bytes if your machine architecture is already in network order - but it will on x86 processors!
|
|
|
|
|
hmmm... So it will swap all the time on x86?
I'm not going cross-platform here, it's hardcore MFC7.1...
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
It sure would byte swap. But do you need to load winsock in order to use it? Also, I'd have to dock you 5 style points for misusing that function to perform byte swapping....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks
|
|
|
|
|
i try to use a c library which require me to pass a function pointer
as callback. hence, i build a static function inside a class .
however, i face a very strange problem while trying to access a member
function through that static function with the following trick.
i have the following classes:
CXFaceRecognitionDlg - main dialog class and with a static CPicture
control
CPicture - static control derived from CStatic
CFaceDetectionManager - generic class
in CXFaceRecognitionDlg.h
-------------------------
class CXFaceRecognitionDlg : public CDialog
{
public:
bool GetIsCaptureDetectedFace(){ return m_bIsCaptureDetectedFace; }
// Dialog Data
//{{AFX_DATA(CXFaceRecognitionDlg)
enum { IDD = IDD_XFACERECOGNITION_DIALOG };
CPicture m_Picture;
protected:
bool m_bIsCaptureDetectedFace;
-------------------------
in CXFaceRecognitionDlg.cpp
---------------------------
BOOL CXFaceRecognitionDlg::OnInitDialog()
{
//this callback will process every frame
cvcamSetProperty(0, CVCAM_PROP_CALLBACK, CPicture::callback);
m_bIsCaptureDetectedFace = true;
}
void CXFaceRecognitionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXFaceRecognitionDlg)
DDX_Control(pDX, IDC_PICTURE, m_Picture);
//}}AFX_DATA_MAP
}
---------------------------
in CPicture.h
-------------
class CPicture : public CStatic
{
// Construction
public:
static void callback(IplImage* image);
protected:
CFaceDetectionManager* m_pFaceDetectionManager;
static CFaceDetectionManager* m_spFaceDetectionManager;
-------------
in CPicture.cpp
---------------
CFaceDetectionManager* CPicture::m_spFaceDetectionManager = NULL;
CPicture::CPicture()
{
try
{
m_pFaceDetectionManager = new CFaceDetectionManager(this);
}
catch(const char* c)
{
MessageBox(c);
m_pFaceDetectionManager = NULL;
}
// I NEED THIS TO ENABLE ME TO ACCESS MEMBER FUNCTION THROUGH STATIC
FUNCTION
m_spFaceDetectionManager = m_pFaceDetectionManager;
}
void CPicture::callback(IplImage* image)
{
// THIS IS THE WAY I ACCESS MEMBER FUNCTION THROUGH STATIC FUNCTION
if(m_spFaceDetectionManager != NULL)
m_spFaceDetectionManager->DetectAndDrawFaces(video_image);
}
---------------
in CFaceDetectionManager.h
--------------------------
class CFaceDetectionManager
{
// Construction
public:
CFaceDetectionManager(CPicture* pParent, const char
*classifier_cascade_path = "<default_face_cascade>"); // standard
constructor
void DetectAndDrawFaces( IplImage* img );
protected:
CPicture* m_pParent;
--------------------------
in CFaceDetectionManager.cpp
----------------------------
CFaceDetectionManager::CFaceDetectionManager( CPicture* pParent, const
char *classifier_cascade_path)
{
m_pParent = pParent;
}
void CFaceDetectionManager::DetectAndDrawFaces( IplImage* img )
{ if(((CXFaceRecognitionDlg*)(m_pParent->GetParent()))->GetIsCaptureDetectedFace())
{
}
}
----------------------------
The strange problem occurs here. i realize that the line of code
if(((CXFaceRecognitionDlg*)(m_pParent->GetParent()))->GetIsCaptureDetectedFace())
isn't getting result "true", but it is getting result "false".
although, i oledi explicitly set m_bIsCaptureDetectedFace into "true"
during the initialize of dialog box.
can anyone tell me why this strange situation happen? this really
getting me crazy
thank you.
regards
yccheok
|
|
|
|
|
I would make sure the pointer returned from GetParent() is actually the type you think it is. Do something like:
ASSERT_KINDOF(CXFaceRecognitionDlg, m_pParent->GetParent())
|
|
|
|
|
i had ur advice and now roughly can get the root of evil but still have no idea how to solve it. here is the root of evil. (i simplify my previous problem)
----------------------------------------------------------
i try to use a c library which require me to pass a function poinger as callback. hence, i build
a static function inside a class .
however, i face a very strange problem while trying to access a member function through that
static function with the following trick.
i have the following classes:
CXFaceRecognitionDlg - main dialog class and with a CPicture control
CPicture - control derived from CStatic
in CXFaceRecognitionDlg.h
-------------------------
class CXFaceRecognitionDlg : public CDialog
{
public:
int GetDummy(){ return dummy; }
void ShowDummy();
// Dialog Data
//{{AFX_DATA(CXFaceRecognitionDlg)
enum { IDD = IDD_XFACERECOGNITION_DIALOG };
CPicture m_Picture;
protected:
int dummy;
-------------------------
in CXFaceRecognitionDlg.cpp
---------------------------
BOOL CXFaceRecognitionDlg::OnInitDialog()
{
// this is the c library
// this callback will process every seconds
cvcamSetProperty(0, CVCAM_PROP_CALLBACK, CPicture::callback);
// explicitly set to 108
dummy = 108;
}
void CXFaceRecognitionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXFaceRecognitionDlg)
DDX_Control(pDX, IDC_PICTURE, m_Picture);
//}}AFX_DATA_MAP
}
void CXFaceRecognitionDlg::ShowDummy()
{
CString s;
s.Format("%i", dummy);
MessageBox(s, s, MB_OK);
}
---------------------------
in CPicture.h
-------------
class CPicture : public CStatic
{
// Construction
public:
static void callback(IplImage* image);
protected:
static CPicture* m_pThis;
-------------
in CPicture.cpp
---------------
CFaceDetectionManager* CPicture::m_spFaceDetectionManager = NULL;
CPicture::CPicture()
{
// I NEED THIS TO ENABLE ME TO ACCESS MEMBER FUNCTION THROUGH STATIC FUNCTION
m_pThis = this;
}
void CPicture::OnLButtonDown(UINT nFlags, CPoint point)
{
// YAHOO! I GET 108 DISPLAY
((CXFaceRecognitionDlg*)GetParent())->ShowDummy();
}
// PLEASE NOTE THAT CALLBACK IS STATIC FUNCTION
void CPicture::callback(IplImage* image)
{
// WILL GET COMPILATION ERROR FOR THE FOLLOWING CODE
// 'CWnd::GetParent' : illegal call of non-static member function
//
// ((CXFaceRecognitionDlg*)GetParent())->ShowDummy();
//
// BUT VALUE 0 IS DISPLAYED
((CXFaceRecognitionDlg*)(m_pThis->GetParent()))->ShowDummy();
}
---------------
I try to debug the application by inserting
ASSERT_KINDOF(CXFaceRecognitionDlg, GetParent()); in CPicture::OnLButtonDown
ASSERT_KINDOF(CXFaceRecognitionDlg, m_pThis->GetParent() ); in CPicture::callback
note that ASSERT_KINDOF(CXFaceRecognitionDlg, m_pThis->GetParent() ); in CPicture::callback will
fail!!!
(1) why m_pThis->GetParent() is not class type of CXFaceRecognitionDlg but can have a access to
function ShowDummy?
(2) how can i avoid that failure at the same time mantaining callback as static and able to
access instance member variable?
thank you.
regards
yccheok
|
|
|
|