|
Is there any Macro that can be used to know if the function that is running is called from a worker-thread or the main program? It is needed to know without use any addictional static global variable or addictional parameter to the function.
thanks
Russell
|
|
|
|
|
This looks the solution:
if( AfxGetMainWnd()==NULL ){
}else{
}
Any comment will be wellcome
Russell
|
|
|
|
|
May be you can use something like this...
DWORD dwMainThreadId = 0;
DWORD dwProcessId = 0;
dwMainThreadId = GetWindowThreadProcessId( hMainWnd, &dwProcessId);
if( dwMainThreadId == GetCurrentThreadId() )
{
//Main Thread
}
else
{
//Thread specialization code
}
I have not tested this snippet.
|
|
|
|
|
Yes! your solution looks work better then mine
inline BOOL IsThisAThread(){
return GetCurrentThreadId()==GetWindowThreadProcessId(AfxGetMainWnd()->GetSafeHwnd(), NULL);
}
thanks
Russell
|
|
|
|
|
*Edit* Never mind - that error doesn't occur
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Tuesday, September 23, 2008 4:56 PM
|
|
|
|
|
yes, you are right....but as you suggested it is better in this way, thanks
inline BOOL IsThisAThread(){
CWnd* pMainWnd=AfxGetMainWnd();
if(! pMainWnd) return TRUE;
return GetCurrentThreadId()!=GetWindowThreadProcessId(pMainWnd->GetSafeHwnd(), NULL);
}
Russell
|
|
|
|
|
Hi All,
I m new to MAPI, and m tryig to copy messages from one profile to another profile.
Created a dummy profile.
Configured a MSPST messages service and added a PST file to it.
And trying to copy data from My profile to this dummy profile.
I hav no idea how to do this?? IS there any way to do this??
Can I open two mapi sessions in a single thread?
Please help in this
|
|
|
|
|
Hello!
I am trying to write a program which involves getting the size of a pictures and videos from their paths, I have looked on msdn and I found the function GetFileSizeEx but I need to put there a handle to the file and I don't know how to do that.
How can I create a handle to the file from it's path? unless you have a better idea how to get the size of the file?
|
|
|
|
|
AlProb wrote: unless you have a better idea how to get the size of the file?
May not be a "better" idea, but this is just another way to do it (Just found off a search):
TCHAR* sFile = _T("D:\\Rajesh\\Cheers.htm");
struct _stat buff;
_tstat(sFile, &buff);
cout<<"The size of your file is "<<buff.st_size<<" Bytes"<<endl;
Please note that _tstat returns an int , so if the file size is larger than the maximum value of an int , then this method won't work right!
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
You may also want to try CFile::GetStatus[^], which stores the file size in an ULONGLONG (64 bit unsigned integer), which is a relief.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
thanks for your help, it realy is a relief since the size of the videos can be in GB, hope the ULONGLONG will hold it
|
|
|
|
|
with WinAPI it is very easy (and it is probably the fastest way):
LARGE_INTEGER n;
HANDLE hFile = CreateFile(FileName, GENERIC_READ,...OPEN_EXISTING...);
GetFileSizeEx(hFile, n);
CloseHandle(hFile);
just check MSDN for all options of CreateFile
|
|
|
|
|
Other option:
__int64 GetSize(CString cs_file)
{
WIN32_FIND_DATA fd;
__int64 iSize = -1;
HANDLE hFind = FindFirstFile((LPCTSTR)cs_file, &fd);
if (hFind != INVALID_HANDLE_VALUE)
iSize = (((__int64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
FindClose(hFind);
return iSize;
}
|
|
|
|
|
Very nice. A small suggestion that might double the ability of the method: The return type may be unsigned __int64 rather than being signed (the default size can be 0)
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
I know, I know. I used the signed __int64 because I convert the return value somewhere to double and VC6 doesn't support the conversion from unsigned __int64 to double ;-(
|
|
|
|
|
This works on VC6:
typedef unsigned __int64 UI64;
UI64 GetSize(CString cs_file)
{
WIN32_FIND_DATA fd;
UI64 iSize = 0;
HANDLE hFind = FindFirstFile((LPCTSTR)cs_file, &fd);
if (hFind != INVALID_HANDLE_VALUE)
iSize = (((UI64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
FindClose(hFind);
return iSize;
}
void CCPDlgDlg::OnButton3()
{
UI64 isize = GetSize(_T("D:\\Rajesh\\Cheers.htm"));
}
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Did you try to cast the return value to double?
|
|
|
|
|
If you hear a loud noise, it is me banging head against the table.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
|
Rajesh R Subramanian wrote: the default size can be 0
Actually, 0 bytes is still a valid length for a file. It would be better to use 0xFFFFFFFFFFFFFFFF as the default value in case the function fails (it's rather unlikely that a file would have that size )
|
|
|
|
|
Michael Schubert wrote: 0xFFFFFFFFFFFFFFFF ... (it's rather unlikely that a file would have that size)
Yes, but only until the next version of acrobat reader is released.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Dang, you might be right. I heard that they will release their next wave of crap products on Blue Ray discs because they don't fit on DVDs any more
|
|
|
|
|
Michael Schubert wrote: I heard that they will release their next wave of crap products on Blue Ray discs because they don't fit on DVDs any more
Yes, but the installer will be incredibly compressed so that it fits in just 2 such discs.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Michael Schubert wrote: Other option:
Use CFile::GetStatus if you are using MFC. Does the same work inside. Gives plenty more information.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
In the MFC version that ships with VC6, the m_size field in the CFileStatus structure is only LONG which limits the file size to 4 GB.
|
|
|
|