* Re: mkshortcut debugging problem
@ 2002-03-01 17:00 Joshua Daniel Franklin
2002-03-02 8:08 ` Jason Tishler
0 siblings, 1 reply; 11+ messages in thread
From: Joshua Daniel Franklin @ 2002-03-01 17:00 UTC (permalink / raw)
To: cygwin
> On Thu, Feb 28, 2002 at 04:03:34PM -0800, Joshua Daniel Franklin wrote:
> > The code that produces this error is:
> >
> > MultiByteToWideChar (CP_ACP, 0, lname, -1, widepath, MAX_PATH);
> > hres = pf->lpVtbl->Save (pf, widepath, TRUE);
> > if (!SUCCEEDED(hres))
> > {
> > fprintf(stderr, "%s: Save to persistant storage failed (Does the
> > directo
> > ry you are writing to exist?)\n", prog_name);
> > exit(3);
> > }
>
> Try the following before calling pf->lpVtbl->Save():
>
> GetCurrentDirectory(dir);
> pf->lpVtbl->SetRelativePath(dir);
>
> This is just basically as it should work. Look in MSDN for the
> exact usage.
>
> Corinna
>
Tried this, no difference:
/usr/src/cygutils-0.9.9/src-gpl$ ./mkshortcut -P http://www.cygwin.com #works
/usr/src/cygutils-0.9.9/src-gpl$ cp ./mkshortcut.exe /bin/
/usr/src/cygutils-0.9.9/src-gpl$ /bin/mkshortcut -P http://www.cygwin.com
mkshortcut: Save to persistant storage failed (Does the directory you are
writing to exist?)
Has anyone even seen something like this before?
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
2002-03-01 17:00 mkshortcut debugging problem Joshua Daniel Franklin
@ 2002-03-02 8:08 ` Jason Tishler
0 siblings, 0 replies; 11+ messages in thread
From: Jason Tishler @ 2002-03-02 8:08 UTC (permalink / raw)
To: Joshua Daniel Franklin; +Cc: cygwin
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Joshua,
On Fri, Mar 01, 2002 at 05:00:36PM -0800, Joshua Daniel Franklin wrote:
> Has anyone even seen something like this before?
No, but see attached for my version of mkshortcut -- mksc. Note that
mksc.cpp needs to be compiled with MS cl.exe, but hopefully perusing the
code will help you debug your problem.
Jason
[-- Attachment #2: mksc.cpp --]
[-- Type: text/plain, Size: 6705 bytes --]
/*
* Copyright (c) 2000, 2002, Jason Tishler.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* A copy of the GNU General Public License can be found at
* http://www.gnu.org/
*
* Written by Jason Tishler <jason@tishler.net>
*
* $Id: mksc.cpp,v 1.3 2002/03/02 16:12:11 jt Exp $
*/
#include <windows.h>
#include <iostream>
#include <string>
#include <shlguid.h>
#include <shlobj.h>
using namespace std;
DWORD MakeShortcut(
const string& aPath,
const string& anArguments,
const string& aWorkingDirectory,
const string& anIconLocation,
int anIconIndex,
const string& aShortcutPath);
void ParseArgs(
int argc,
char* argv[],
string& aPath,
string& anArguments,
string& aWorkingDirectory,
string& anIconLocation,
int& anIconIndex,
string& aShortcutPath);
void PrintUsage();
string CollapseBackslashes(const char* aString);
int
main(int argc, char* argv[])
{
string aPath;
string anArguments;
string aWorkingDirectory;
string anIconLocation;
int anIconIndex = 0;
string aShortcutPath;
// Parse command line arguments
ParseArgs(
argc,
argv,
aPath,
anArguments,
aWorkingDirectory,
anIconLocation,
anIconIndex,
aShortcutPath);
// Create shortcut
DWORD aStatus = MakeShortcut(
aPath,
anArguments,
aWorkingDirectory,
anIconLocation,
anIconIndex,
aShortcutPath);
if (aStatus != ERROR_SUCCESS)
{
cerr << "MakeShortcut failed with error = " << aStatus << endl;
}
return (aStatus == ERROR_SUCCESS) ? 0 : 2;
}
DWORD
MakeShortcut(
const string& aPath,
const string& anArguments,
const string& aWorkingDirectory,
const string& anIconLocation,
int anIconIndex,
const string& aShortcutPath)
{
// Variable definitions located here due to use of gotos
IShellLink *aShellLink = 0;
IPersistFile* aPersistFile = 0;
int aStatus2 = 0;
DWORD aReturnCode = ERROR_SUCCESS;
// Initialize COM
HRESULT aStatus = CoInitialize(0);
if (FAILED(aStatus))
{
aReturnCode = GetLastError();
cerr << "CoInitialize failed with error = " << aReturnCode << endl;
goto exit;
}
// Create shell link instance
aStatus = CoCreateInstance(
CLSID_ShellLink,
0,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void **) &aShellLink);
if (FAILED(aStatus))
{
aReturnCode = GetLastError();
cerr << "CoCreateInstance failed with error = " << aReturnCode << endl;
goto exit;
}
// Set the shell link's command path
aStatus = aShellLink->SetPath(aPath.c_str());
if (FAILED(aStatus))
{
aReturnCode = aStatus;
cerr << "IShellLink::SetPath failed with HRESULT = " << aStatus << endl;
goto exit;
}
// Set the shell link's command arguments
aStatus = aShellLink->SetArguments(anArguments.c_str());
if (FAILED(aStatus))
{
aReturnCode = aStatus;
cerr << "IShellLink::SetArguments failed with HRESULT = " << aStatus << endl;
goto exit;
}
// Set the shell link's working directory, if necessary
if (aWorkingDirectory.size() > 0)
{
aStatus = aShellLink->SetWorkingDirectory(aWorkingDirectory.c_str());
if (FAILED(aStatus))
{
aReturnCode = aStatus;
cerr << "IShellLink::SetWorkingDirectory failed with HRESULT = " << aStatus << endl;
goto exit;
}
}
// Set the shell link's icon, if necessary
if (anIconLocation.size() > 0)
{
aStatus = aShellLink->SetIconLocation(anIconLocation.c_str(), anIconIndex);
if (FAILED(aStatus))
{
aReturnCode = aStatus;
cerr << "IShellLink::SetIconLocation failed with HRESULT = " << aStatus << endl;
goto exit;
}
}
// Get the shell link's persist file interface
aStatus = aShellLink->QueryInterface(
IID_IPersistFile,
(void **) &aPersistFile);
if (FAILED(aStatus))
{
aReturnCode = GetLastError();
cerr << "IShellLink::QueryInterface failed with error = " << aReturnCode << endl;
goto exit;
}
// Convert the shortcut path to Unicode
WCHAR aWideShortcutPath[MAX_PATH];
aStatus2 = MultiByteToWideChar(
CP_ACP,
0,
aShortcutPath.c_str(),
-1,
aWideShortcutPath,
MAX_PATH);
if (aStatus2 == 0)
{
aReturnCode = GetLastError();
cerr << "MultiByteToWideChar failed with error = " << aReturnCode << endl;
goto exit;
}
// Save the shell link to the filesytem
aStatus = aPersistFile->Save(aWideShortcutPath, TRUE);
if (FAILED(aStatus))
{
aReturnCode = GetLastError();
cerr << "IPersistFile::Save failed with error = " << aReturnCode << endl;
goto exit;
}
exit:
// Clean up
if (aPersistFile)
aPersistFile->Release();
if (aShellLink)
aShellLink->Release();
CoUninitialize();
return aReturnCode;
}
void
ParseArgs(
int argc,
char* argv[],
string& aPath,
string& anArguments,
string& aWorkingDirectory,
string& anIconLocation,
int& anIconIndex,
string& aShortcutPath)
{
// Print usage, if appropriate
if (argc == 1)
{
PrintUsage();
exit(1);
}
// Process arguments
for (int i = 1; i < argc; i += 2)
{
if (i + 1 >= argc)
{
PrintUsage();
exit(1);
}
if (strcmp(argv[i], "--cmd") == 0)
{
aPath = CollapseBackslashes(argv[i + 1]);
}
else if (strcmp(argv[i], "--args") == 0)
{
anArguments = CollapseBackslashes(argv[i + 1]);
}
else if (strcmp(argv[i], "--dir") == 0)
{
aWorkingDirectory = CollapseBackslashes(argv[i + 1]);
}
else if (strcmp(argv[i], "--icon") == 0)
{
anIconLocation = CollapseBackslashes(argv[i + 1]);
}
else if (strcmp(argv[i], "--index") == 0)
{
anIconIndex = atoi(argv[i + 1]);
}
else if (strcmp(argv[i], "--shortcut") == 0)
{
aShortcutPath = CollapseBackslashes(argv[i + 1]);
}
else
{
PrintUsage();
exit(1);
}
}
// Check for mandatory arguments
if (aPath.size() == 0 || anArguments.size() == 0 || aShortcutPath.size() == 0)
{
PrintUsage();
exit(1);
}
}
void
PrintUsage()
{
cerr << "usage: mksc --cmd CommandPath --args CommandArguments" << endl;
cerr << " --shortcut ShortcutPath [--dir WorkingDirectory]" << endl;
cerr << " [--icon IconPath] [--index IconIndex]" << endl;
}
string
CollapseBackslashes(const char* aString)
{
const string theDoubleBackslashRe = "\\\\";
const string theSpaceRe = " ";
string aFixedString = aString;
// Determine if string does not contains any spaces, if so just return
if (string::size_type i = aFixedString.find(theSpaceRe) == string::npos)
return aFixedString;
// Collapse double backslashes into single
for (string::size_type i = aFixedString.find(theDoubleBackslashRe);
i != string::npos;
i = aFixedString.find(theDoubleBackslashRe, i))
{
i++;
aFixedString.erase(i, 1);
}
return aFixedString;
}
[-- Attachment #3: Type: text/plain, Size: 214 bytes --]
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
2002-03-12 23:33 ` Charles Wilson
@ 2002-03-13 6:37 ` Joshua Daniel Franklin
0 siblings, 0 replies; 11+ messages in thread
From: Joshua Daniel Franklin @ 2002-03-13 6:37 UTC (permalink / raw)
To: Charles Wilson; +Cc: cygwin
Let me know if you can't get the attachment, or need anything else.
http://cygwin.com/ml/cygwin/2002-03/msg00470.html
--- Charles Wilson <cwilson@ece.gatech.edu> wrote:
> Joshua Daniel Franklin wrote:
>
> > Thanks much, I'll take a look. Sure is easy to read...looks almost like
> > Python.
> >
>
>
> Any progress tracking down this bug? Joshua??
>
> --Chuck
> (wanting to release cygutils-1.0.0)
>
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
2002-03-02 19:49 Joshua Daniel Franklin
2002-03-04 4:50 ` Jason Tishler
@ 2002-03-12 23:33 ` Charles Wilson
2002-03-13 6:37 ` Joshua Daniel Franklin
1 sibling, 1 reply; 11+ messages in thread
From: Charles Wilson @ 2002-03-12 23:33 UTC (permalink / raw)
To: Joshua Daniel Franklin; +Cc: cygwin
Joshua Daniel Franklin wrote:
> Thanks much, I'll take a look. Sure is easy to read...looks almost like
> Python.
>
Any progress tracking down this bug? Joshua??
--Chuck
(wanting to release cygutils-1.0.0)
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
@ 2002-03-07 23:03 Joshua Daniel Franklin
0 siblings, 0 replies; 11+ messages in thread
From: Joshua Daniel Franklin @ 2002-03-07 23:03 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 869 bytes --]
Well, after going over hoards of MSDN documents and adjusting my
code, I realized what most developers' first guess might have been...
I followed the null pointer. Madness overtook me.
I corrected this (char *)problem and my util actually passed all my
tests, no matter which directory it was in. I also ran it through
GNU indent a few times (just to make sure :)
Features of this version include:
--Prettier code, thanks to indent
--Better error checking
--Works ;)
Because of the indent the patch is bigger than the actual file,
so here's the whole thing. (Chuck, this should be drop-in replacement
for the one in cygutils-0.9.9. I apologize for the inconvenience.)
Thanks again to Corinna and Jason for the help.
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
[-- Attachment #2: mkshortcut.c.bz2 --]
[-- Type: application/octet-stream, Size: 3491 bytes --]
[-- Attachment #3: Type: text/plain, Size: 214 bytes --]
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
2002-03-02 19:49 Joshua Daniel Franklin
@ 2002-03-04 4:50 ` Jason Tishler
2002-03-12 23:33 ` Charles Wilson
1 sibling, 0 replies; 11+ messages in thread
From: Jason Tishler @ 2002-03-04 4:50 UTC (permalink / raw)
To: Joshua Daniel Franklin; +Cc: cygwin
Joshua,
On Sat, Mar 02, 2002 at 07:49:11PM -0800, Joshua Daniel Franklin wrote:
> Thanks much, I'll take a look.
No problem.
Sorry for not directly trying to help debug your problem. And sorry
for not coming forward with (and/or contributing) my code sooner.
Jason
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
@ 2002-03-02 19:49 Joshua Daniel Franklin
2002-03-04 4:50 ` Jason Tishler
2002-03-12 23:33 ` Charles Wilson
0 siblings, 2 replies; 11+ messages in thread
From: Joshua Daniel Franklin @ 2002-03-02 19:49 UTC (permalink / raw)
To: Jason Tishler; +Cc: cygwin
Thanks much, I'll take a look. Sure is easy to read...looks almost like
Python.
:)
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
2002-02-28 17:33 Joshua Daniel Franklin
2002-02-28 19:30 ` Charles Wilson
@ 2002-03-01 5:00 ` Corinna Vinschen
1 sibling, 0 replies; 11+ messages in thread
From: Corinna Vinschen @ 2002-03-01 5:00 UTC (permalink / raw)
To: cygwin
On Thu, Feb 28, 2002 at 04:03:34PM -0800, Joshua Daniel Franklin wrote:
> The code that produces this error is:
>
> MultiByteToWideChar (CP_ACP, 0, lname, -1, widepath, MAX_PATH);
> hres = pf->lpVtbl->Save (pf, widepath, TRUE);
> if (!SUCCEEDED(hres))
> {
> fprintf(stderr, "%s: Save to persistant storage failed (Does the
> directo
> ry you are writing to exist?)\n", prog_name);
> exit(3);
> }
Try the following before calling pf->lpVtbl->Save():
GetCurrentDirectory(dir);
pf->lpVtbl->SetRelativePath(dir);
This is just basically as it should work. Look in MSDN for the
exact usage.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:cygwin@cygwin.com
Red Hat, Inc.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
@ 2002-02-28 22:50 Joshua Daniel Franklin
0 siblings, 0 replies; 11+ messages in thread
From: Joshua Daniel Franklin @ 2002-02-28 22:50 UTC (permalink / raw)
To: cygwin
>Permissions or ACLs on the two different directories? Try
>
>getfacl {dir1}
>getfacl {dir2}
>
>Same? Different?
Well, it's writing to the same directory in both cases, but the ACLs are:
$ getfacl.exe /c/Documents\ and\ Settings/All\ Users/Desktop/
# file: /c/Documents and Settings/All Users/Desktop/
# owner: Administrator
# group: None
user::rwx
group::rwx
group:Users:r-x
group:Power Users:rwx
mask::rwx
other::r-x
default:user::---
default:group::---
default:group:Users:---
default:group:Power Users:rwx
default:mask::---
default:other::---
Or did you mean the ACLs on /bin and /usr/src...? Those look identical.
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: mkshortcut debugging problem
2002-02-28 17:33 Joshua Daniel Franklin
@ 2002-02-28 19:30 ` Charles Wilson
2002-03-01 5:00 ` Corinna Vinschen
1 sibling, 0 replies; 11+ messages in thread
From: Charles Wilson @ 2002-02-28 19:30 UTC (permalink / raw)
To: Joshua Daniel Franklin; +Cc: cygwin
Joshua Daniel Franklin wrote:
>
> The code that produces this error is:
>
> MultiByteToWideChar (CP_ACP, 0, lname, -1, widepath, MAX_PATH);
> hres = pf->lpVtbl->Save (pf, widepath, TRUE);
> if (!SUCCEEDED(hres))
> {
> fprintf(stderr, "%s: Save to persistant storage failed (Does the
> directo
> ry you are writing to exist?)\n", prog_name);
> exit(3);
> }
>
> I'm afraid I have no idea how to debug this, and I've begun to make what
> seem like arbitrary changes. Why would it work from one directory and not
> another? (BTW, I tried printf'ing the lname string and it is identical in
> both cases.) Anyone have any suggestions?
Permissions or ACLs on the two different directories? Try
getfacl {dir1}
getfacl {dir2}
Same? Different?
--Chuck
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
* mkshortcut debugging problem
@ 2002-02-28 17:33 Joshua Daniel Franklin
2002-02-28 19:30 ` Charles Wilson
2002-03-01 5:00 ` Corinna Vinschen
0 siblings, 2 replies; 11+ messages in thread
From: Joshua Daniel Franklin @ 2002-02-28 17:33 UTC (permalink / raw)
To: cygwin
I updated to cygutils 0.9.9 yesterday which included the utility
'mkshortcut', which I wrote. I was horrified to find that it dumps
the stack when attempting to set the name for a shortcut (the -n
option). I *did* make sure it worked before sending Chuck the code,
after all. My first thought was that I accidentally sent an old
version, so I got the source and found that it did indeed crash
when built as I had been doing it. I freely acknowledge that the
code, especially string-handling, is a mess, and after making what
seem to be arbitary changes it again works...but only from the current
directory. When I copy the new version to /bin (or /usr/bin) this is
what happens:
/usr/src/cygutils-0.9.9/src-gpl$ /usr/src/cygutils-0.9.9/src-gpl/mkshortcut.exe
-DA /usr/local/bin/
[This works, producing bin.lnk in the All Users\Desktop\ dir]
/usr/src/cygutils-0.9.9/src-gpl$ rm /c/Documents\ and\ Settings/All\
Users/Desktop/bin.lnk
/usr/src/cygutils-0.9.9/src-gpl$ cp
/usr/src/cygutils-0.9.9/src-gpl/mkshortcut.exe /usr/bin/
/usr/src/cygutils-0.9.9/src-gpl$ mkshortcut.exe -DA /usr/local/bin/
mkshortcut.exe: Save to persistant storage failed (Does the directory you are
writing to exist?)
The code that produces this error is:
MultiByteToWideChar (CP_ACP, 0, lname, -1, widepath, MAX_PATH);
hres = pf->lpVtbl->Save (pf, widepath, TRUE);
if (!SUCCEEDED(hres))
{
fprintf(stderr, "%s: Save to persistant storage failed (Does the
directo
ry you are writing to exist?)\n", prog_name);
exit(3);
}
I'm afraid I have no idea how to debug this, and I've begun to make what
seem like arbitrary changes. Why would it work from one directory and not
another? (BTW, I tried printf'ing the lname string and it is identical in
both cases.) Anyone have any suggestions?
Thanks.
Joshua Daniel Franklin
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2002-03-13 14:08 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-01 17:00 mkshortcut debugging problem Joshua Daniel Franklin
2002-03-02 8:08 ` Jason Tishler
-- strict thread matches above, loose matches on Subject: below --
2002-03-07 23:03 Joshua Daniel Franklin
2002-03-02 19:49 Joshua Daniel Franklin
2002-03-04 4:50 ` Jason Tishler
2002-03-12 23:33 ` Charles Wilson
2002-03-13 6:37 ` Joshua Daniel Franklin
2002-02-28 22:50 Joshua Daniel Franklin
2002-02-28 17:33 Joshua Daniel Franklin
2002-02-28 19:30 ` Charles Wilson
2002-03-01 5:00 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).