CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Copy to clipboard

    Quote Originally Posted by a343 View Post
    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.

  2. #17
    Join Date
    Aug 2011
    Posts
    69

    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

  3. #18
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Copy to clipboard

    Quote Originally Posted by a343 View Post
    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?

  4. #19
    Join Date
    Aug 2011
    Posts
    69

    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

  5. #20
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Copy to clipboard

    Quote Originally Posted by a343 View Post
    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
    Why did you ignore what GCDEF wrote you:
    Quote Originally Posted by GCDEF View Post
    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

  6. #21
    Join Date
    May 2002
    Posts
    1,435

    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");

  7. #22
    Join Date
    Aug 2011
    Posts
    69

    Re: Copy to clipboard

    Quote Originally Posted by 0xC0000005 View Post
    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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured