Anyone have a working example for WNetGetUniversalName ?

Post your tools and samples or ask for them.
TerryP
Australia
Posts: 11
Joined: 06 Mar 2017, 22:41
Location: Australia

Anyone have a working example for WNetGetUniversalName ?

Post by TerryP » 09 Oct 2017, 23:39

Hi All,

I've been trying to implement a Windows API call to the WNetGetUniversalName function in MPR.DLL. I'm still working in TD 4.1, so am using the "A" version with the following external function definition:

Code: Select all

Function: WNetGetUniversalNameA
	Description:
	Export Ordinal: 0
	Returns
		Number: DWORD
	Parameters
		String: LPSTR
		Number: DWORD
		structPointer
			Receive String: LPSTR
		Receive Number: LPDWORD
based on the Windows/MSDN definition:

Code: Select all

DWORD WNetGetUniversalName(
  __in          LPCTSTR lpLocalPath,
  __in          DWORD dwInfoLevel,
  __out         LPVOID lpBuffer,
  __in_out      LPDWORD lpBufferSize
);
where "lpBuffer" points to a UNIVERSAL_NAME_INFO structure, which is defined as:

Code: Select all

typedef struct _UNIVERSAL_NAME_INFO {  LPTSTR lpUniversalName;
} UNIVERSAL_NAME_INFO;
I then call the function with the following code:

Code: Select all

Set nSize = 1000
Set sFile = dfsFileName
Call SalStrSetBufferLength( sUNC, nSize )
Set nReturn = WNetGetUniversalNameA( sFile, 1, sUNC, nSize )
Set dfsUNCName = sUNC
I can successfully call the function and return a sensible error code depending on the input string, but even when no error is returned, the receive string parameter doesn't contain any value. The lpBufferSize receive parameter doesn't change value either.

I expect the problem is in my definition of the structure for the output string. Any advice or assistance, or better a working example, would be much appreciated.

Thanks in advance,
Terry Phythian
Reprise Consulting

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 400
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Anyone have a working example for WNetGetUniversalName ?

Post by Dave Rabelink » 10 Oct 2017, 07:31

Hi Terry,

I just created a sample for you.
Download it from here:
WNetGetUniversalName_Sample.zip

WNetGetUniversalName_Sample.png

It uses the cstructex library, explained here:
viewtopic.php?f=27&t=45740

The sample is ANSI but works also on UNICODE TD versions.
First you need to change the version number of the cstructXX.dll to 41 (in your case).

Hope this helps.
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

TerryP
Australia
Posts: 11
Joined: 06 Mar 2017, 22:41
Location: Australia

Re: Anyone have a working example for WNetGetUniversalName ?

Post by TerryP » 10 Oct 2017, 22:57

Hi Dave,

Thanks for the example, it works fine (as expected)! Has anyone told you TODAY how magnificent you are? :D

Cheers,
Terry Phythian
Reprise Consulting

Return to “Tools & Samples”

Who is online

Users browsing this forum: Ccbot [Crawler] and 0 guests