- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1)Iuse the string "Example 34' boat.txt" as the command lineargument in VS 2003 (MyprogProperty PageDebuggerCommand Line Argument). When I runMyprog.exe and put a break point in WinMain() I see that
the szCmdFile string looks like this: '''Example 34' boat.txt ".Why is there adbl quote anda single quoteat the beginning of the string (''')?
I was hoping to use the command line arg to simulate a dbl click on an associated file for debugging purposes, but the dbl quote and single quote prevent this.
2) If Iselect the file "C:Example 34' boat.txt" with theWin32 API fn. GetOpenFileName(OFN)it is shown in the Fortran character variable I assignthe path to as 'C:Example 34' boat.txt'. Note that there are 3 single quotes in the string, but this does not cause an error. Why no error?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
* VS debugger always displays strings enclosed in single quotes. Thus, those are "phony" ones. (You might not see the closing quote for long strings). To unconfuse yourself
* File names might or might not be passed with double quotes as command arguments, i.e. into WinMain->lpszCmdLine (that is, GETARG() ) with double quotes around. Double quotes are practically required for correct handling when the file path contains spaces. I'm not sure about exact rules who (Explorer? Cmd.exe? Yourapp.exe) should eventually strip those double quotes, but your application should be prepared to handle both quoted and unquoted arguments, along the following lines:
!XUnQuote removes leading and trailing quote from a string, also
!removing all the text before and after. If the string does not
!contain two quotes, does nothing.
FUNCTION XUnQuote(sString) RESULT(s)
CHARACTER(*), INTENT(IN):: sString
CHARACTER(LEN=PXUnquotedLen(sString)):: s
INTEGER:: iLen1, iLen2
iLen1 = INDEX(sString, '"')
iLen2 = INDEX(sString, '"', .TRUE.)
IF (iLen1.NE.iLen2) THEN
s = sString(iLen1+1 : iLen2-1)
ELSE
s = sString
END IF
END FUNCTION XUnQuote
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
JugoslavDujic, what is the most reliable way to determine if a command line arg exists forWinMain(...lpszCmdLine...)?
The method I have been usingsimply checks for the position of a nul character in the string pointed to by lpszCmdLine. If the position is .GT. 1 then I assume that a stringPath exists to a file that was dbl clicked by the user.This appears to work, but I am concerned about the reliability. Code snippet follows:
INTEGER :: iPos
CHARACTER(MAX_PATH+1):: szCmdFile
POINTER(pszCmdFile, szCmdFile)
! assign pointer, where lpszCmdLine is WinMain() dummy arg
pszCmdFile = lpszCmdLine
iPos = INDEX( szCmdFile, ACHAR(0) )
! if iPos ,GT, 1, assume that a fully qualified Path exists
if( iPos .GT. 1 ) then
!Path exists, remove quotes here, if any
end if
Or is it better to use NARGS() or IARGC() to check for a command line arg (Path to a dbl clicked data file)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Based on the info provide above, I created
two snippets of code for WinMain() that can
retrieve the path of a file clicked on in
Windows Explorer, if a file association in
the Registry exists.
These are preliminary codesnippets that worked
a couple of times on an XP home machine.
I modified JugoslavDujic's code slightly by
removing garbage dbl quotes, if any, after
the nul char before INDEX()ing for dbl Quotes.
I did have a problem with a garbage dbl quote.
*** code snippet 1 ****
INTEGER iPos1, iPos2
CHARACTER(MAX_PATH+1) gszFileName
CHARACTER(Max_Path+1) :: szCmdFile
POINTER(pszCmdFile, szCmdFile)
! lpszCmdLine is from WinMain( args )
pszCmdFile = lpszCmdLine
iPos1 = Index(szCmdFile, ACHAR(0))
if(iPos1 .GT. 1) then
iPos1 = INDEX(szCmdFile, ACHAR(0))
if(iPos1 > 0) then
! pad with blanks after nul char in case a
! garbage dbl quote (") is present
szCmdFile = szCmdFile(1 : iPos1)
end if
! strip dbl quotes
iPos1 = INDEX(szCmdFile, '"')
iPos2 = INDEX(szCmdFile, '"', BACK = .TRUE.)
if(iPos1 .NE. iPos2) then
gszFileName = szCmdFile(iPos1+1 : iPos2-1)//ACHAR(0)
else
gszFileName = ADJUSTL(szCmdFile)
end if
end if
***** code snippet 2, another method *****
INTEGER iPos1, iPos2
INTEGER icnt, iStatus
CHARACTER(MAX_PATH+1) gszFileName
! get number of command line args, 0 is the command,
icnt = COMMAND_ARGUMENT_COUNT()
! prog has 1 Cmd Ln arg, which is path to data file
if(icnt == 1) then
CALL GET_COMMAND_ARGUMENT(1, gszFileName, iStatus)
if(iStatus > 0) then
iPos1 = INDEX(gszFileName, ACHAR(0))
if(iPos1 .GT. 0) then
! pad with blanks after nul char in case a
! garbage dbl quote (") is present
gszFileName = gszFileName(1:iPos1)
end if
! strip dbl quotes
iPos1 = INDEX(gszFileName, '"')
iPos2 = INDEX(gszFileName, '"', BACK = .TRUE.)
if(iPos1 .NE. iPos2) then
gszFileName = gszFileName(iPos1+1 : iPos2-1)//ACHAR(0)
else
! leading space will cause error so ADJUSTL()
gszFileName = ADJUSTL(TRIM(gszFileName)//ACHAR(0))
end if
end if
end i
f
******
In code snippet 2 GET_COMMAND_ARGUMENT() appears to do
the following to the valuegszFileName returned:
1. removes the nul char
2. pads the nul char position and beyond
with blanks
3. removes dlg quotes (").
If GET_COMMAND_ARGUMENT() does these things consistantly
then snippet 2 can be simplified. However, not sure
that this is the case.
Thanks for any additional commentsinfo about
GET_COMMAND_ARGUMENT().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, appreciate thethe reply for items 1, 2, 1nd 3. Thanks.
An added note:code snippet 1 above isalso based oncode provided by JugoslavDujic in a post on 12/01/2005 in this Forum. The subj. of that post was "Win32/IVF Question".
Error correction in code snippet 2 above:
CALL GET_COMMAND_ARGUMENT(1, gszFileName, iStatus)
if(iStatus > 0) then
should actually be
CALL GET_COMMAND_ARGUMENT(1, gszFileName, iLen, iStatus)
if(iStatus== 0) then
needed to include all three optional args before iStatus returns 0 or success.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page