|
-
August 31st, 2011, 01:48 PM
#16
Re: Copy to clipboard
 Originally Posted by a343
Please read the code of the function, it copies informations to clipboard.
Victor, you are right. But my aplication will run in several computer, and I need some way to put the path in general way not only my path
But the problem is you can't open a file. It has nothing to do with the clipboard.
-
August 31st, 2011, 04:17 PM
#17
Re: Copy to clipboard
Please, don't disturb, if you have some answer, tell me, but if not, please, don't change the subject.
Thank you
-
August 31st, 2011, 09:11 PM
#18
Re: Copy to clipboard
 Originally Posted by a343
Please, don't disturb, if you have some answer, tell me, but if not, please, don't change the subject.
Thank you
I'm trying to help you get information. If you're looking for information on how to open a file and you post a subject about the clipboard that has nothing to do with your question, people that may know about files but not the clipboard may skip your thread.
I showed you MSDN's information on how to find a detailed error message. Did you try it yet?
-
September 1st, 2011, 03:28 AM
#19
Re: Copy to clipboard
Yes, I did. I used this funtion
http://cplusplus.com/forum/windows/2068/
And the result was:
It can't open the file failed with error 0: The operation was complete rightly
-
September 1st, 2011, 04:31 AM
#20
Re: Copy to clipboard
 Originally Posted by a343
Why did you ignore what GCDEF wrote you:
 Originally Posted by GCDEF
How would we know?? From MSDN "Always check the return value to see if the pointer is NULL before performing any further operations on the file. If an error occurs, the global variableerrno is set and may be used to get specific error information. For further information, see errno."
Why did you ignore what MSDN claims in fopen, _wfopen article:
Return Value
Each of these functions returns a pointer to the open file. A null pointer value indicates an error. If filename or mode is NULL or an empty string, these functions trigger the invalid parameter handler, which is described in Parameter Validation. If execution is allowed to continue, these functions return NULL and set errno to EINVAL.
For more information, see errno, _doserrno, _sys_errlist, and _sys_nerr.
Victor Nijegorodov
-
September 1st, 2011, 05:55 AM
#21
Re: Copy to clipboard
You can't simply use a file name if you expect to find a file in the virtual store folder. This assumes that your current directory is already set to the virtual store folder which is probably not a good assumption. An effective solution might use the ::SHGetSpecialFolderPath() API function like this:
Code:
CString VirtualStoreFilePath(LPCTSTR fileName)
{
CString path;
LPTSTR buffer = path.GetBuffer(MAX_PATH);
if(::SHGetSpecialFolderPath(0, buffer, CSIDL_LOCAL_APPDATA, FALSE))
{
VERIFY(::PathAppend(buffer, _T("VirtualStore")));
VERIFY(::PathAppend(buffer, fileName));
}
path.ReleaseBuffer();
return path;
}
Now, to find the full path of a file called "temporal.dat" you would do this:
Code:
CString fullPath = VirtualStoreFilePath(_T("temporal.dat"));
fichero= fopen(fullPath,"wb");
This should work on any computer / Windows OS that implements the VirtualStore folder. However, the function I have shown is very basic and does only minimal error checking. A real program would only use this as a starting point to build a more reliable application. You should note that this function may return an empty string so you would need to determine why.
Also, note that this function will return the full path of a file assumed to be located in the virtual store but it absolutely does not guarantee that the file exists. In fact, the virtual store root folder typically does not contain individual files but instead subfolders named after applications that use it. With that in mind, you may have to use the function like this:
Code:
CString fullPath = VirtualStoreFilePath(_T("MyAppName\\temporal.dat"));
fichero= fopen(fullPath,"wb");
-
September 1st, 2011, 11:19 AM
#22
Re: Copy to clipboard
 Originally Posted by 0xC0000005
You can't simply use a file name if you expect to find a file in the virtual store folder. This assumes that your current directory is already set to the virtual store folder which is probably not a good assumption. An effective solution might use the ::SHGetSpecialFolderPath() API function like this:
Code:
CString VirtualStoreFilePath(LPCTSTR fileName)
{
CString path;
LPTSTR buffer = path.GetBuffer(MAX_PATH);
if(::SHGetSpecialFolderPath(0, buffer, CSIDL_LOCAL_APPDATA, FALSE))
{
VERIFY(::PathAppend(buffer, _T("VirtualStore")));
VERIFY(::PathAppend(buffer, fileName));
}
path.ReleaseBuffer();
return path;
}
Now, to find the full path of a file called "temporal.dat" you would do this:
Code:
CString fullPath = VirtualStoreFilePath(_T("temporal.dat"));
fichero= fopen(fullPath,"wb");
This should work on any computer / Windows OS that implements the VirtualStore folder. However, the function I have shown is very basic and does only minimal error checking. A real program would only use this as a starting point to build a more reliable application. You should note that this function may return an empty string so you would need to determine why.
Also, note that this function will return the full path of a file assumed to be located in the virtual store but it absolutely does not guarantee that the file exists. In fact, the virtual store root folder typically does not contain individual files but instead subfolders named after applications that use it. With that in mind, you may have to use the function like this:
Code:
CString fullPath = VirtualStoreFilePath(_T("MyAppName\\temporal.dat"));
fichero= fopen(fullPath,"wb");
Thank you so much, I used the first option becouse I didnt understand very good the second and everything run perfectly.
In the second option, MyAppName is the name of my aplication, I suposse, but I wrote
CString fullPath = VirtualStoreFilePath(_T("Adest\\temporal.dat"));
fichero= fopen(fullPath,"wb");
and it couldn't open the file
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|