Thread: WSAInstallServiceClass()

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    WSAInstallServiceClass()

    Hey, I'm trying to figure out how to install/register a service class, but when I call WSAInstallServiceClass() it returns SOCKET_ERROR. Checking WSAGetLastError() for WSAEACCES and the other 'known' error codes gives no result; the value returned by WSAGetLastError() is 5, which I don't believe actually corresponds to any Winsock error code (they're all 100xxx or something like that). Does anybody know what 5 means?

    Looking the function up on MSDN, it says that for "server", you need Windows2003 Server or Windows2000 Server or WindowsNT 3.51 Server. Here, I'm running Windows 2000 (not sure which version)... does this mean that I need a special OS to use the function?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User
    Join Date
    Jan 2004
    Posts
    33
    WSAGetLastError() should not be returning five. All error codes are within the bounds of 10000 and above. On a side note, the function requires winsock2; make sure you're not using plain winsock. If none of this helps post the code.
    “Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. " -John Carmack

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I'm winsock2, including winsock2.h, linking ws2_32.lib.
    Code:
    	//(call WSAStartup(), etc.)
    	WSASERVICECLASSINFO sci;
    	WSANSCLASSINFO nsci[2];
    
    	DWORD port = 5632;
    	DWORD sapID = 5632;
    	DWORD dwValue = 1;
    
    	sci.dwCount = 2; //sizeof nsci
    	sci.lpClassInfos = nsci;
    	sci.lpServiceClassId = (LPGUID)&svcGUID;
    	sci.lpszServiceClassName = "RFTT Server";
    
    	nsci[0].dwNameSpace = NS_SAP;
    	nsci[0].lpszName = "ConnectionOriented";
    	nsci[0].dwValueType = REG_DWORD;
    	nsci[0].dwValueSize = sizeof(dwValue);
    	nsci[0].lpValue = &dwValue;
    
    	nsci[1].dwNameSpace = NS_SAP;
    	nsci[1].lpszName = SERVICE_TYPE_VALUE_SAPID;
    	nsci[1].dwValueType = REG_DWORD;
    	nsci[1].dwValueSize = sizeof(sapID);
    	nsci[1].lpValue = &sapID;
    
    	int res = WSAInstallServiceClass(&sci);
    	if(res == SOCKET_ERROR)
    	{
    		
    		res = WSAGetLastError();
    		char temp[128];
    		itoa(res, temp, 10);
    
    		if(res == WSAEACCES)
    			MessageBox(NULL, "Insufficient privileges to install service class.",
    			"Error", MB_OK | MB_ICONEXCLAMATION);
    		else
    			MessageBox(NULL, temp, "Error", MB_OK | MB_ICONEXCLAMATION);
    	}
    Actually, I just tested it on my home computer (WindowsXP Pro), and it apparently worked fine. The earlier error was at school. I checked res for WSAEACCES (since you can't modify the registry or anything on our accounts), WSAEINVAL, WSAEALREADY, and WSAENOTINITIALISED. The error testing in the code above is stripped-down, but should have the same effect. Always it skipped past the switch conditions, and the messagebox popped up with just '5'.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    See GetLastError()->System Error Codes in MSDN.

    No. 5 is the famous ERROR_ACCESS_DENIED. The function must require administrator priviliges.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Err, hmm. I thought it would be something along those lines, but since the only error codes WSAInstallServiceClass() were 'supposed' to generate were the WSAE ones, I thought it would be WSAEACCES. Thanks anonytmouse!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed