|
You can use something like this:
BOOL DriveSupportsSMARTCommands(DWORD dwDrive)
{
HANDLE hDrive;
TCHAR szDrive[MAX_PATH];
_stprintf(szDrive,_T("\\\\.\\PhysicalDrive%d"), dwDrive);
hDrive = CreateFile(szDrive,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING, 0, NULL);
if(INVALID_HANDLE_VALUE != hDrive)
{
GETVERSIONINPARAMS gvp = {0};
DWORD dwRet = 0;
if(DeviceIoControl(hDrive, SMART_GET_VERSION,NULL,0,&gvp, sizeof (GETVERSIONINPARAMS),&dwRet, NULL))
{
return (gvp.fCapabilities & CAP_SMART_CMD);
}
}
return FALSE;
}
SMART_GET_VERSION[^]
GETVERSIONINPARAMS[^]
You will probably need Power User or Administrator access.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi folks!
To get to the point, here's some code:
...
dc.BeginPath();
dc.Ellipse(rectangle);
dc.EndPath();
CBrush Brush(color);
CBrush *OriginalBrush = dc.SelectObject(&Brush);
dc.FillPath();
dc.SelectObject(OriginalBrush);
int PointCount = dc.GetPath(NULL, NULL, 0);
dc is valid, rectangle is OK, the ellipse gets filled as it should but when i call GetPath to retrieve the points in the path it returns -1 and i get "Cannot complete this function" from GetLastError(). Any ideas what might cause this? Thanks in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Here's quoting from the documentation for FillPath:
MSDN wrote:
FillPath Function
Remarks
After its interior is filled, the path is discarded from the DC identified by the hdc parameter.
(http://msdn.microsoft.com/en-us/library/dd162718(VS.85).aspx[^])
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Thank you very much, i completely missed that, haven't worked with paths much yet.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I am using the following code snippet. This is the code which gets executed when I click on a Browse button.
Function call - BrowseDialog( GetParent()->GetSafeHwnd(), csTitle, lpszBuf );
Function Definition -
BrowseDialog(HWND hWndParent,CString pszPath,LPSTR csDialogTitle)
{
_tcsncpy(szInitialDir, pszPath, _MAX_PATH-1);
int nLen = _tcslen(szInitialDir);
if (szInitialDir[nLen-1] == '\\')
szInitialDir[nLen-1] = '\0';
BROWSEINFO bi;
memset((LPVOID)&bi, 0, sizeof(bi));
TCHAR szDisplayName[_MAX_PATH];
szDisplayName[0] = '\0';
bi.hwndOwner = hWndParent;
bi.pidlRoot = NULL;
bi.pszDisplayName = (LPSTR)szDisplayName;
bi.lpszTitle = csDialogTitle;
bi.lpfn = RecipeBrowseCallbackProc;
bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_VALIDATE|BIF_USENEWUI|BIF_STATUSTEXT;
LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);
BOOL bRet = ::SHGetPathFromIDList(pIIL, (char*)&szSelectedDir);
}
Some times I am getting crash when clicking on browse button and sometimes after opening the browse button and selecting another directory..
Can I know what is the fault in above code
|
|
|
|
|
Well, your code won't compile...
I can't see any definition for szInitialDir!
I can imagine it's a TCHAR array, MAX_PATH long... Make sure the last TCHAR is zero.
Beyond that, I'd have a look at the crash, and see that the debugger tells me. Also go line by line, and check the contents of bi. You also have a callback function - it is the right signature? If not, you could be getting stack corruption.
Does it work without the callback?
Go to boring and simple, get that working, then build up.
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
This is my call back function..
int CALLBACK RecipeBrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
BOOL bReturn;
UNREFERENCED_PARAMETER(lpData);
switch (uMsg)
{
case BFFM_VALIDATEFAILED:
// AfxMessageBox(GetString(107), MB_OK | MB_ICONEXCLAMATION);
bReturn = TRUE;
break;
case BFFM_INITIALIZED:
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szInitialDir);
bReturn = FALSE;
break;
case BFFM_SELCHANGED:
{
TCHAR szDir[MAX_PATH];
//don't allow the CSIDL_NETHOOD typically C:\Documents and Settings\username\NetHood
//as it contains folder shortcuts...
if (SHGetPathFromIDList((LPITEMIDLIST) lParam ,szDir))
{
LPITEMIDLIST pidl = NULL;
SHGetSpecialFolderLocation(NULL, CSIDL_NETHOOD, &pidl);
TCHAR szNethoodDir[_MAX_PATH];
BOOL bRet = ::SHGetPathFromIDList(pidl, (char*)&szNethoodDir);
LPTSTR lpsz = _tcsrchr(szDir, (_TUCHAR) '\\');
int nIndex = lpsz - szDir;
szDir[nIndex] = '\0';
if (_tcsicmp(szDir, szNethoodDir) == 0)
::SendMessage(hwnd,BFFM_ENABLEOK,0 ,0);
::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
}
bReturn = FALSE;
}
break;
}
return bReturn;
}
|
|
|
|
|
I'd have a good look at CPallini's suggestion - you are doing very strange things there.
But that would only crash when you leave the browse function, not while in it. I'd put a breakpoint in your RecipeBrowseCallbackProc, and check each line - especially the BFFM_SELCHANGED case, as you know it crashes in there...
Good luck,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
As has already been suggested, start with the basics and build upon them (e.g., remove the callback function, change ulFlags ). Don't try and debug a problem with so many "unknowns."
"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
|
|
|
|
|
Try This.
LPMALLOC pMalloc;
LPITEMIDLIST pidl;
TCHAR szPath [MAX_PATH];
BROWSEINFO bi = { GetSafeHwnd(), NULL, szPath,NULL,
BIF_VALIDATE|BIF_UAHINT|BIF_USENEWUI|BIF_RETURNONLYFSDIRS, NULL, NULL };
pidl = SHBrowseForFolder ( &bi );
if ( NULL != pidl )
{
if ( SHGetPathFromIDList ( pidl, szPath ) )
{
}
SHGetMalloc ( &pMalloc );
pMalloc->Free(pidl);
pMalloc->Release();
}
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Please use 'code block ' button for code snippets.
At first look your function call doesn't match well with function prototype.
VKupunaram wrote: BOOL bRet = ::SHGetPathFromIDList(pIIL, (char*)&szSelectedDir)
This line looks very suspiscious: how is szSelectedDir defined?
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]
|
|
|
|
|
Hello,
I have a created a map named mapList
std::map<string, std::vector<FileInfo*>> mapList;
and loading to key and value.
when i try to create a view of the file in the process address space (MapViewOfFile) which returns a pointer to the file view.
error C2440: '=' : cannot convert from 'std::map<_Kty,_Ty> *' to 'LPCTSTR' msg is thrown
I think there is an error in typecasting from 'std::map<_Kty,_Ty> *' to 'LPCTSTR' as i'm implementing in below manner.
pBuf = (std::map<string, FileInfo*> *)MapViewOfFile(hMapSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0);
Can anyone suggest me a solution.
Thanks in advance,
Regards,
Mayur M
modified on Tuesday, May 5, 2009 4:53 AM
|
|
|
|
|
Something went wrong in your code formatting, please try again.
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]
|
|
|
|
|
Wow, your code seems to be wrong on so many points
First thing, why are you trying to assign a pointer to a map into a LPCTSTR pointer (I guess that pBuf is LPCTSTR by lookking at your error). That doesn't make any sense to me.
Second, you can't put a full map this way in the shared memory. You will need to serialize in some way your array: write the number of elements and then write all the elements one by one in the shared memory. You will need to apply the same principle when you deserialize: read the number of elements, then the elements one by one and add them to a local map object.
|
|
|
|
|
Cedric Moonen wrote: Wow, your code seems to be wrong on so many points
My immediate reaction as well
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
There are so many things wrong with attempting what you are that it's difficult to know where to start...
However, the main point is that std::map , std::string and std::vector all rely on pointers to external data. You do not have control over those pointers, so you cannot guarantee that they will lie within the mapped area of memory (unless you use specialised allocators, as documented here[^]).
mmayur wrote: Can anyone suggest me a solution.
Your immediate problem here is a symptom of a bigger one. Tell us more about what you're trying to do and maybe we can suggest a solution to the bigger problem.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the reply.
sry for not providing proper information.
I'm facing a new problem of coping the contents from map to a map pointer.
pBuf = (std::map<string, FileInfo*> *)MapViewOfFile(hMapSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0);
std::map<string, FileInfo*> mapList;
I have to insert the mapList to pBuf.
Does insert or get_allocator resolve my problem.
Regards,
Mayur M
|
|
|
|
|
Thanks for the reply.
sry for not providing proper information.
I'm facing a new problem of coping the contents from map to a map pointer.
pBuf = (std::map<string, FileInfo*> *)MapViewOfFile(hMapSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0);
std::map<string, FileInfo*> mapList;
I have to insert the mapList to pBuf.
Does insert or get_allocator resolve my problem.
Regards,
Mayur M
|
|
|
|
|
As I said before...that's just not going to work. What problem are you trying to solve with this?
If you want to share/communicate a map between two or more processes using shared memory, look at Boost.Interprocess[^] - that has containers designed to be used in a shared memory area.
If you're just sending the map from one process to another, I'd serialize it - Boost.Serialization[^] is an option there.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
But right now i'm just looking for copying the contents of a map to map pointer. Nothing more than that
|
|
|
|
|
Are you seeing some relationship between the 'Map' in 'MapViewOfFile' and the 'map' in 'std::map'? Because if you are and that's why you're using std::map...well, there is no relationship between those two 'map's at all.
But that's the trouble - without telling us what you're trying to accomplish, we can't help you.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
Sorry for the improper title, which has created a lot of confusions.
I have a map of type
Std::map<string, FileInfo*> ActualMap;
Std::map<string, FileInfo*>::iterator mapIterator
Typedef std::pair <string, FileInfo*>;
The FileInfo is a class which contains the properties of the files.
I am inserting all the values properly into the ActualMap and then it has to be shared with another process in the same machine using the Named SharedMemory. So, I have implemented in following way
Std::map<string, fileinfo*=""> *pBuffer;
pBuffer = (std::map<string, fileinfo*=""> *)MapViewOfFile(hMapSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0);
once the above mapping of the view is done, I have inserted all the key-value from the ActualMap as
CopyMemory((PVOID) pBuf, &mapList, (mapList.size() * sizeof(std::map<string,FileInfo>)));
Now, in the client application i'm able to retireve only the size of the map but not the key-value pairs and their data.
So, please help in solving this problem.
Regards,
Mayur M
|
|
|
|
|
|
Is anybody know how to change default button (that will be activated by Enter) in PropertySheet/PropertyPage to some button on active page (not any of standart PropertySheet buttons - OK, Cancel or Apply)?
|
|
|
|
|
Hi,
Can someone tell me how to convert BOOL in to System::String* __gc
I'm really wired with this...
Thanks a lot.
I appreciate your help all the time...
CodingLover
|
|
|
|
|