How to Help Your Business Become an AI Early Adopter
One problem of using NetShareAdd & NetShareDel (and other LAN Manager functions) in Windows applications lies in "Differences in Win32 API Implementations Among Windows Operating Systems" as Noel Nyman explain in MSDN Visual Studio 6.0\ Backgrounders\Windows Platform\Guidelines\Differences in Win32 API Implementations Among Windows Operating Systems. Article Q125700 from Microsoft Knowledge Base " Windows 95 Support for Net Function Calls" make the information more exact: Windows 95 support for these functions differs from Windows NT in two ways. First, because Windows 95 doesn't support Unicode, these functions require ANSI strings. Second, Windows 95 exports the Net functions from SVRAPI.DLL instead of NETAPI32.DLL. That source give more explanation:
To handle these differences, applications targeted to both Windows NT and Windows 95 should do the following:
- Avoid importing Net functions from NETAPI32.DLL at link time. Instead, applications should do a run time version check and dynamically link to NETAPI32.DLL for Windows NT or SVRAPI.DLL for Windows 95.
- 2. Make sure the application doesn't depend on the presence of unsupported API's.
- 3. When calling Net functions, pass strings using a character set appropriate for the host operating system. Use Unicode strings for Windows NT and ANSI strings for Windows 95.
The project have two main files: CWiCNet.h and CWiCNet.cpp (interface of the class and realization of it accordingly). You may compile it under Win98 or Win2k and it must work on both platforms. File CWiCNet.cpp does not use precompiled header.
So if you want to make some local resource shared you must create an object of CWiCNet class and call its public function
NetShareAdd( const char* dir_path, // path to disk resource you want // to be shared const char* net_name, // desired net name const char* comment = NULL, // comment on the resource bool bReadOnly = true, // set to false if you want to // give full access to resource const char* password = NULL ); // you may set password // for access to resource
If you want to delete a shared resource (I mean close access to the resource) you are able to do this by calling a NetShareDel public member function of object of class CWiCNet. This function requires only one parameter - resource name:
bool NetShareDel( const char* net_name // name of resource to be // deleted from sharing );
Additionally I include example project CWiCNetExample which explain the use of CWiCNet class. Just one remark: if you want use "Share Del" menu item - you must select local resource, only in this case the menu item will be enabled. Another one note: The data in the network structure (in tree) is not updated automatically after an add or del share, so you must "Enumerate resources" again if you want to see changes. And: just be patient when resources enumerates, even if you see message "EnumerateFunc returned FALSE"
Network resources enumeration code was given from MSDN Visual Studio 6.0\ Platform SDK\Networking and Distributed Servises\Windows Networking (WNet)\ Using Windows Networking\Enumerating Network Resources.
Code for Browsing shell namespace by Selom Ofori (a.k.a SubRosa).
Get hostname and ip address of local computer by Jeff Lundgren & Jaroslav Pisk.