-
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? :confused:
-
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.
-
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'.
-
See GetLastError()->System Error Codes in MSDN.
No. 5 is the famous ERROR_ACCESS_DENIED. The function must require administrator priviliges.
-
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!