Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GetWindowsDir is blank?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00197369
Message ID:
00197372
Views:
19
>Can anyone tell me what is wrong with this call? I get an error 87, 'Invalid parameter' when I try this. I'm not sure why that would happen.
>
>------
>
>LOCAL lcWindowsPath, ;
> lcSystemPath, ;
> lcTempPath, ;
> lnPathLen, ;
> lnResult
>
>* Declare the API functions we will call. These were found in
>* /Common/Tools/WinAPI/Win32API.Txt, which
>* installs with Visual Studio 6. Had to tweak the syntax from
>* VB to VFP, using HELP DECLARE - DLL.
>DECLARE LONG GetWindowsDirectory IN KERNEL32 ;
> STRING @lcWindowsPath, ;
> LONG @lnPathLen
>
>DECLARE LONG GetSystemDirectory IN KERNEL32 ;
> STRING @lcSystemPath, ;
> LONG @lnPathLen
>
>DECLARE LONG GetTempPath IN KERNEL32 ;
> LONG @lnPathLen, ;
> STRING @lcTempPath
>
>DECLARE INTEGER GetLastError IN KERNEL32
>
>
>* Set up buffers to pass to functions by value.
>lcWindowsPath = SPACE ( 256 )
>lcSystemPath = SPACE ( 256 )
>lcTempPath = SPACE ( 256 )
>lnPathLen = 0
>lnError = 0
>
>* Get and report the Windows folder path.
>set step on
>lnResult = GetWindowsDirectory( @lcWindowsPath, @lnPathLen)

You have to pass the size of the buffer as the second parameter so that Windows knows the maximum length that it can return. You need to examine the value after the API call completes to know the length of the buffer to use as the path. Windows won't return a value if the size of the buffer passed is too small.

This is well documented in the MSDN description of the API call; if you don't own a copy of the MSDN library, you can access the information from MSDN Online (http://msdn.microsoft.com/developer). The call has been around and unchanged for quite a while, so if you have the WIN32API help file from VFP 3, it's documented there as well.

There have also been a number of threads in the past two months that included working API implementation code for the GetWindowsDir and GetSystremDir calls, so you could do a search for threads here on UT, too.

>if lnResult = 0
> lnError = int(getLastError())
>else
> MESSAGEBOX ( 'Windows Path: ' + lcWindowsPath )
>endif
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform