Solved

Path problem running a child DOS process under NT

Posted on 1998-12-02
7
373 Views
Last Modified: 2013-12-03
I have a problem when using CreateProcess to start a 16 bit DOS program in my MFC app. I want to run the child file viewer app when the user views one of my data files.
I am calling CreateProcess with lpCommandLine set to the full path of the DOS application plus just the name of the data file, and have tried both passing the data file's directory in as the lpCurrentDirectory parameter, and alternatively, using ::SetCurrentDirectory to set the working dir. Neither method seems to work, with the standard error value returning "file not found".

Note that I want the application to run on both Win9x and NT. Passing the current directory into CreateProcess seems to work well on Win95, but neither method works on NT.

I also want to include spaces in my path if possible :)
0
Comment
Question by:jjoz
7 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1416633
I guess, that dos program is loaded but it can't find the file, cause the filename is passed in long file name convention.
Try using GetShortPathName to convert the data file path to short name convention.

Regards, Madshi.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1416634
I think Madshi is right, though i'm stunned to rear that NT doesn't do the conversion itself when calling 'CreateProcess()'...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1416635
Hi Jürgen,

win95 doesn't do the conversion. I didn't test it with winNT, but I guess it's the same...   :-(

Regards... Madshi.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 1

Author Comment

by:jjoz
ID: 1416636
The problem seems to be related to the length of the path in which the data file is stored. It is about 5 directories deeps, which makes the path quite long.

So far I have found the best method is to get the 'short' version of the data file, and just pass it and thein via the lpCommandLine, ie the lpCommand eventually equals

c:\nms\bin\replay.exe c:\nms\projec~1.prj\melbou~1.prj\testmt~1.MT1\981201.dta\15'36'33.log

This works well, until the length of this command exceeds 142 chars!? The CreateProcess then fails returning "The parameter is incorrect". I recall reading something about using fully qualified paths (ie "\\servername\sharename\path") with NT to overcome path limitations, but I can't seems to relocate it now.

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1416637
This text is from the CreateFile documentation. I don't know, but I guess, you can use the same syntax with CreateProcess. Of course you then have to use CreateProcessW instead of CreateProcessA.

"Windows NT: You can use paths longer than MAX_PATH characters by calling the wide (W) version of CreateFile and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing. This lets you use paths that are nearly 32,000 Unicode characters long. You must use fully-qualified paths with this technique. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\tom_1\hotstuff\coolapps" is seen as "\\tom_1\hotstuff\coolapps"."

Regards, Madshi.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1416638
16 bit programs are limited to 127 characters in the command line.
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1416639
If you need to get around this, then you will need to do what some compilers do. Create a temporary file in a short directory. The contents of the file contains anything you want. Pass the name of this temporary file to the 16 bit application, but with a special character preceding the name. Then in the 16-bit application check the command line argument to see if it contains this special character. If it does, then get the real parameter from the file. Otherwise, process the command line argument normally.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question