The specified module could not be found

N

Nikolay Petrov

I get this error when calling NetShareGetInfo from NetApi32.dll

code:
public Declare Unicode Function NetShareGetInfo Lib "Netapi32.dll" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal ServerName As String, _
<MarshalAs(UnmanagedType.LPWStr)> ByVal ShareName As String, _
ByVal Level As Integer, _
ByVal pBuffer As System.IntPtr) _
As Integer

Private Sub Test
Dim pBuffer As IntPtr = IntPtr.Zero
NetShareGetInfo("Server", "Share", 502, pBuffer)
End Sub

Calling from XP Pro to Server 2000
 
H

Herfried K. Wagner [MVP]

Nikolay Petrov said:
I get this error when calling NetShareGetInfo from NetApi32.dll

code:
public Declare Unicode Function NetShareGetInfo Lib "Netapi32.dll" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal ServerName As String, _
<MarshalAs(UnmanagedType.LPWStr)> ByVal ShareName As String, _
ByVal Level As Integer, _
ByVal pBuffer As System.IntPtr) _
As Integer
[...]
Calling from XP Pro to Server 2000

| Client: Requires Windows XP, Windows 2000 Professional,
| Windows NT Workstation, Windows Me, Windows 98, or
| Windows 95.
| Server: Requires Windows Server 2003, Windows 2000 Server,
| or Windows NT Server.

Mhm...
 
N

Nikolay Petrov

I've allready red this.
So I am calling this function from XP, it is the client right?
And the server is Win2k Server.
Or I get it wrong?
 
H

Herfried K. Wagner [MVP]

Nikolay Petrov said:
I've allready red this.
So I am calling this function from XP, it is the client right?
And the server is Win2k Server.
Or I get it wrong?

Yeah, I wonder why you are receiving this error message too. Did you
already check if the DLL is available on your system?
 
J

Jay B. Harlow [MVP - Outlook]

Nikolay,
Have you looked at the sample at:

http://www.pinvoke.net/default.aspx/netapi32/NetShareGetInfo.html

The short of it is, you are not passing a buffer to pBuffer. According to
the help for NetShareGetInfo "bufptr [out] pointer to the buffer that
receives the data". You are passing a null pointer to this parameter,
Windows will not write to the null pointer, you need to point this to a
valid memory location...

--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net


|I get this error when calling NetShareGetInfo from NetApi32.dll
|
| code:
| public Declare Unicode Function NetShareGetInfo Lib "Netapi32.dll" ( _
| <MarshalAs(UnmanagedType.LPWStr)> ByVal ServerName As String, _
| <MarshalAs(UnmanagedType.LPWStr)> ByVal ShareName As String, _
| ByVal Level As Integer, _
| ByVal pBuffer As System.IntPtr) _
| As Integer
|
| Private Sub Test
| Dim pBuffer As IntPtr = IntPtr.Zero
| NetShareGetInfo("Server", "Share", 502, pBuffer)
| End Sub
|
| Calling from XP Pro to Server 2000
|
 
N

Nikolay Petrov

Thanks Jay,
This whole thing with ponters is buffers is new to me. Ok, it is
actually old ;-), but i've never programmed in other language,
different from VB .NET.
 
J

Jay B. Harlow [MVP - Outlook]

Did you try the example from
http://www.pinvoke.net/default.aspx/netapi32/NetShareGetInfo.html exactly as
shown? I will try it later today if I find time.

Did you use the declaration from the above site, exactly as shown?

Declare Unicode Function NetShareGetInfo Lib "netapi32.dll" _
(ByVal ServerName As String, _
ByVal ShareName As String, _
ByVal Level As Long, _
ByRef BufPtr As IntPtr) As Integer


NOTE: The example shows the BufPtr parameter as ByRef not ByVal!

Doh! Reading the help on NetShareGetInfo I see "Windows Me/98/95: The caller
must allocate and deallocate this buffer". Which makes sense considering
that BufPtr is a LPBYTE*. In other words my earlier advice was only
applicable to Windows Me/98/95... (NOTE: On other windows platforms you
still need to deallocate the buffer with a call to NetApiBufferFree.

Be certain to review both the P/Invoke site I gave above & MSDN:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stgmgmt/fs/netsharegetinfo.asp

--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net


| Just can't make it work.
| how to make thw pointer valid?
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top