Click to See Complete Forum and Search --> : Need spme help with NewShareAdd API.


cool_puns
January 20th, 2004, 05:20 PM
Hi

I was working on some stuff which requires me to read entries from the Windows Registry and then use them with the NewShareAdd API for creating a sharepoint.

I am able to get the registry entries, but am not able to use them properly with the API.

Please help!!!


Thanks in advance.

Puneet.

Mick
January 20th, 2004, 08:52 PM
You need to give more details, what is the error code from NetShareAdd(...), post the code you are using, what are you doing with the registry and how does that tie into adding a share?

cool_puns
January 21st, 2004, 09:39 AM
Hi Mike,

Actually the application is suppose to read the drive name, path, etc from the registry. After reading the necessary things from registry, i have to create a share-point on the same machine, and then map a drive to that share point.

path = "c:\program files\my dir\Dir_1";
ShareName = "WorkShare";
Drive = "X:";

using this data i'll share the "path" on my machine as the "ShareName", then i'll map the "drive" to it. The requirement is such that, i have to read from the registry, not from some file or other source. I am getting th edata properly from Registry, just facing problem with the NetShareAdd.

I get the error from GetLastError as :997, (Overlapped I/O operation is in progress. )

This is the code i am using:
-----------------------------------------------------
//i fetch all the data from the registry as CString data-type.
CString ShareNameForWorkDir ;//Its a private member of a class

bufSize = BUFF_SIZE ;//BUFF_SIZE = 100
ret = RegQueryValueEx (RegKeyHndl, "ShareName", NULL , &dwType, (LPBYTE)buffer, &bufSize);
if ( ret != ERROR_SUCCESS )
{
return ret;
}
ShareNameForWorkDir = CString(buffer);

//Making the share-point, before mapping the drive
netMsg = "Creating SharePoint For Working Directory: ";
NET_API_STATUS res;
SHARE_INFO_2 p;
DWORD parm_err = 0;

p.shi2_netname = (LPSTR)(LPCTSTR)ValuesFromReg.GiveMeShareNameForWorkDir() ;//Share name like "axyswork", this member function return the CString value of ShareNameForWorkDir
p.shi2_type = STYPE_DISKTREE; // disk drive
p.shi2_remark = TEXT("Working Directory");
p.shi2_permissions = 0;
p.shi2_max_uses = 5;
p.shi2_current_uses = 0;
p.shi2_path = (LPSTR)(LPCTSTR)ValuesFromReg.GiveMeLocalWorkDir();//Path which is to be shared. same as the "ShareName"
p.shi2_passwd = NULL; // no password

res = NetShareAdd ( "\\svrname", 2, (LPBYTE) &p, &parm_err);

if ( res == NERR_Success) {
netMsg += "Created Successfully a Sharepoint for the Directory";
} else {
printf "\nFailed");
return false;
}

Mick
January 21st, 2004, 01:23 PM
the Net functions expect a unicode strings in SHARE_INFO_2. Either create your project in UNICODE (which you should be doing anyways since NT->XP is written in UNICODE)

or convert your strings to unicode before passing them to the NetShareAdd...

cool_puns
January 21st, 2004, 01:58 PM
Mike, i am not sure if the application is in UNICODE or not.

But most probably it is not UNICODE, as i checked the VC++ generated makefiles, project settings and all the header files, nowhere UNICODE is defined. And as the project is at a crucial stage, I won't prefer to change to UNICODE now.

In such case what should i do. How do i typecast my strings to UNICODE? I guess i am stuck at that point only, the typecasting. I am using WinXP Professional. Can you please give me some help on this typecasting stuff.

Mick
January 21st, 2004, 03:35 PM
read the FAQ on strings...

http://www.codeguru.com/forum/showthread.php?s=&threadid=231055

cool_puns
January 21st, 2004, 05:08 PM
Thanks Mike, FAQ looks quite helpful. Will try out.