오후 1:29 2002-06-05
조경민 bro@shinbiro.com
========================================================
PRB: FindExecutable() Truncates Result at First Space in LFN

Q140724


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Win32 Software Development Kit (SDK)

--------------------------------------------------------------------------------


SYMPTOMS
The FindExecutable function is supposed to retrieve the fully qualified path to the executable (.exe) file associated with the specified file name. For example, the following call to FindExecutable() should return the path to Winword.exe:


FindExecutable ("C:\\README.DOC", NULL, szBuffer);
Assuming Winword.exe is currently in the C:\Msoffice\Winword directory, the function, upon return, should fill szBuffer with the string C:\Msoffice\Winword\Winword.Exe.

However, when you use FindExecutable() on a file whose associated application is in a directory that has a long file name (LFN) that includes a space, the function truncates the string up at the first space. Going back to the previous code example, if Winword.exe is located in the C:\Program Files\My Accessories directory, the function incorrectly returns the truncated string C:\Program instead of the following expected string:
C:\Program Files\My Accessories\Winword.Exe



CAUSE
File associations are stored in the registry under HKEY_CLASS_ROOT, where the executable name is actually stored under the key


   HKEY_CLASSES_ROOT\<file Type>\shell\open\command = <Name of Executable>
By design, long file names stored in the registry should be enclosed in quotation marks. Otherwise, the system is made to treat the rest of the characters following the space as arguments.

In the example, the path to WinWord.Exe should be stored in the registry as:

   HKEY_CLASSES_ROOT\Word.Document.6\shell\open\command =

    "C:\Program Files\My Accessories\Winword.Exe" /n
which does causes FindExecutable to return the expected string.

Note that this problem does not occur when the short path name is stored in the registry, instead of the long file name. Again, taking the same example to WinWord.exe, this should not be a problem if the short path name "C:\Progra~1\MYACCE~1\WINWORD.EXE" is stored in the registry instead of the LFN version.



RESOLUTION
In some situations, applications do not have control over what gets stored in the registry. It may be the associated application's setup program that wrote the incorrect LFN string (without quotation marks) to the registry. Any application that would then call FindExecutable() on this associated application will run into this problem.

One workaround to this problem might be to parse the string returned and replace the \0 character with a space. Stepping through a debugger, after FindExecutable() returns, you will quickly find that although the space has been replaced with the NULL character (\0), the rest of the string is left intact, so simply reverting the \0 character back to a space gives the expected string.



STATUS
This behavior is by design.

Additional query words: invalid wrong

Keywords : kbLib kbOSWinNT kbOSWin2000 kbSDKWin32 kbOSWin95 kbOSWin98 kbGrpDSShell
Issue type : kbprb
Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch


Last Reviewed: July 9, 2000
ⓒ 2001 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

'KB > MFC/Win32' 카테고리의 다른 글

IE 웹브라우저 마우스 아래 있는 아이템 얻기  (0) 2004.04.28
HICON을 ico로 저장  (0) 2004.04.28
[DB] 트리거 사용  (0) 2004.04.28
익스플로러 인터페이스 받기  (0) 2004.04.28
[펌] 실행파일 숨기기  (0) 2004.04.28

+ Recent posts