delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/07/11/11:26:06

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Mon, 11 Jul 2005 11:25:34 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Ljubomir Milanovic <ljubomir DOT milanovic AT philips DOT com>
cc: cygwin AT cygwin DOT com
Subject: Re: Inconsistent behavior for Win32 executable: starting from bash vs. starting from cmd.exe
In-Reply-To: <OFB51C2DEA.52C28B35-ONC125703B.004CF0CB-C125703B.004E69EF@philips.com>
Message-ID: <Pine.GSO.4.61.0507111118450.7597@slinky.cs.nyu.edu>
References: <OFB51C2DEA DOT 52C28B35-ONC125703B DOT 004CF0CB-C125703B DOT 004E69EF AT philips DOT com>
MIME-Version: 1.0

On Mon, 11 Jul 2005, Ljubomir Milanovic wrote:

> Hi,
>
> I have a problem that same executable has different behavior depending
> on parent shell (bash vs. cmd.exe). Executable is compiled with MS Visual
> Studio and it is a console application. Source code can be found below.
>
> In a nutshell, program converts a "drive" path to UNC path by using
> WNetGetUniversalName function. If started from bash the function returns
> error 487 = ERROR_INVALID_ADDRESS = "Attempt to access invalid address."
> It seems that szBuff buffer address (see source below) is invalid if exe
> is started from bash?! If the same exe is started from cmd.exe no error
> occurs. I play also with PATH environment variable and set the PATH to
> c:/winnt and c:/winnt/system32, but the error remains. Also attaching to
> the process started from bash and debugging with MS Visual Studio does
> not bring any new info.

First thing I'd do is prepend 'c:\cygwin\bin' to the PATH in cmd.exe and
see if that reproduces the problem in cmd.exe.

> Program source code:
>
> /**************************************************************************************************************/
> #include <windows.h>
> #include <iostream>
>
> int main( int argc, char *argv[] )
> {
>         const char *file = "E:\\";      // a network directory or file name with an drive letter in front
>
>         DWORD cbBuff = 2048;    // Size of Buffer
>         TCHAR szBuff[2048];     // Buffer to receive information
>
>         UNIVERSAL_NAME_INFO *puni = (UNIVERSAL_NAME_INFO *)&szBuff;     // Pointers to head of buffer

Would

UNIVERSAL_NAME_INFO szBuff;
UNIVERSAL_NAME_INFO *puni = &szBuff;

work better?  I'm not familiar with UNIVERSAL_NAME_INFO, but the above
assumes it's no larger than 2k in size.

>
>         DWORD res;
>         if((res = WNetGetUniversalName((LPTSTR)file, UNIVERSAL_NAME_INFO_LEVEL, (LPVOID)&szBuff, &cbBuff))==NO_ERROR)
>         {
>                 std::cout << file << " --- " << puni->lpUniversalName << std::endl;
>         }
>         else
>         {
>                 std::cout << file << " Error: " << res << std::endl;
>         }
>         return 0;
> }
> /**************************************************************************************************************/
>
> Thanks for any hints.

HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019