I'm querying a service that is known to exist (such as
Eventlog).
On Win 2000 SP4 and Win 2003 server it fails with
GetLastError() returning 1783 (RPC_X_BAD_STUB_DATA, "the
stub received bad data").
Previous versions of Win 2000, and XP work fine.
I've got some very simple sample code that demonstrates
the problem, if anybody at Microsoft wants to try.
Thanks in advance
Alec
--
Ken Wickes [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
"Alec Dunn" <AD...@syssol.com.au> wrote in message
news:0c2901c3573c$d44ac4f0$a101...@phx.gbl...
// A program to test the QueryServiceConfig() function.
// This fails on Win 2000 SP 4, and on Win 2003 server,
// succeeds everywhere else.
//
// Alec Dunn, July 2003
// We need this to define CoInitializeEx
#define _WIN32_DCOM
#define UNICODE
#define _UNICODE
#include "windows.h"
#include "objbase.h" // for COINIT_MULTITHREADED
// Any service which is reliably present
#define SERVICENAME L"Eventlog"
// Display an error message box
static void msgBox(LPCTSTR caption)
{
TCHAR errString[40];
DWORD errCode = GetLastError();
wsprintf(errString, L"error = 0x%08x", errCode);
MessageBox(NULL, errString, caption, MB_OK);
}
// Simple test program
int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr))
{
SetLastError(hr);
msgBox(L"CoInitializeEx");
return 0;
}
SC_HANDLE hSCM = OpenSCManager(NULL, NULL,
STANDARD_RIGHTS_READ);
if (hSCM == NULL)
{
msgBox(L"OpenSCManager failed");
return 0;
}
SC_HANDLE hSvc = OpenService(hSCM, SERVICENAME,
SERVICE_QUERY_CONFIG);
if (hSvc == NULL)
msgBox(L"OpenService failed");
else
{
DWORD dw;
BYTE configData[10000];
LPQUERY_SERVICE_CONFIG psc = (LPQUERY_SERVICE_CONFIG)
configData;
if (!QueryServiceConfig(hSvc, psc, sizeof(configData),
&dw))
msgBox(L"QueryServiceConfig failed");
else
MessageBox(NULL, L"QueryServiceConfig succeeded",
L"Test", MB_OK);
CloseServiceHandle(hSvc);
}
CloseServiceHandle(hSCM);
CoUninitialize();
return 0;
}
>.
>
--
Ken Wickes [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
"Alec Dunn" <ad...@syssol.com.au> wrote in message
news:757101c3597b$7efdfd50$a001...@phx.gbl...
Here is a C function to work around the problem.
QUERY_SERVICE_CONFIG *queryServiceConfig(SC_HANDLE
hService)
{
// Find the required buffer size
DWORD dw;
QueryServiceConfig(hService, NULL, 0, &dw);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return NULL;
// Allocate the buffer and query the service
QUERY_SERVICE_CONFIG *pConfig = (LPQUERY_SERVICE_CONFIG)
LocalAlloc(LMEM_FIXED, dw);
if (pConfig == NULL)
return NULL;
if (!QueryServiceConfig(hService, pConfig, dw, &dw))
{
// Failed, so release the buffer and return NULL
dw = GetLastError();
LocalFree(pConfig);
SetLastError(dw);
return NULL;
}
// Successful
return pConfig;
}