>I am trying to use WNetGetUser in vfp. I have declared the function before using it. But for some reason I get an error, 1726 'API Library not found'. One last note, the error does not occur till after the function has already ran and returns the correct value.
>
I think something other than this API call is at fault; the WNetGetUser code is close enough to what I use that it should run reliably (there are differences in what I do to the returned value to clean it up on a successful return, but they have no effect on how the API call is made.
I would make sure that you use the code as shown; if something is issuing a CLEAR DLLS or something similar, or redeclaring the API call somewhere else after where you thought you'd already declared it, you might be getting hurt by side-effects. It's safest to issue the DECLARE...DLL in the function that uses it.
>One last note, the dll hooked up is C:\Windows\System\MPR.DLL
That's not always true - WinNT and Win9x use different providers for the WNet family of API calls; as long as you're using the WIN32API catchall as shown, you should be covered.
If you run the code in the debugger, exactly what line does the
API Library not found occur on?
>
>
>Here is the function I am using:
>*==============================================================================
> * Method: GetDefaultUserName
> * Purpose: Gets the name of the user logged onto the machine at the * operating system level.
> * Author: F1 Technologies
> * Parameters:
> * Returns:
> *==============================================================================
> LOCAL ;
> lcNull, ;
> lcUserId, ;
> lnLen
>
> lcNull=""
> lcUserId=SPACE(255)
> lnLen=255
>
> * Use the WNetGetUser function in the Win32API to get the user id
> DECLARE INTEGER WNetGetUser IN WIN32API String @, String @, Integer @
> IF WNetGetUser(@lcNull,@lcUserId,@lnLen)=0
> lcUserId=UPPER(LEFT(lcUserId,AT(CHR(0),lcUserId)-1))
> ELSE
> lcUserId = ""
> ENDIF
>
> RETURN ALLTRIM(lcUserId)