This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Inconsistent behavior for Win32 executable: starting from bash vs. starting from cmd.exe


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. 

I tested with cygwin 1.5.10-3 (oldie) and 1.5.18-1 (newest). 

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

        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.

Bye,
Ljubo 

--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]