This is a fairly typical MFC function to return information about a module or component.
The 1st argument "
LPWSTR lpszBuf
" is a string to which the function will return the requested information (the driver list).
The 2nd argument "
WORD cbBufMax
" is the length in characters of the first argument. It's used by the function to ensure it doesn't overflow the first argument when it's called. You must ensure the string you supply as the first argument is at least as long as the value you pass here.
The 3rd argument "
WORD *pcbBufOut
" is a pointer to a WORD variable. The function returns the number of characters it actually wrote to the buffer - including null terminators.
The function returns a boolean BOOL. True if the call is successful, False otherwise. If it returns False, the 1st and 3rd arguments will have no meaningful values. And you'll need to determine the cause of the error by calling another function (SQLInstallerError I think) - an internet search will show what and how to call. It is similar in nature to this function.
Once a successful call has been made you'll need to parse the result returned in the first argument. Since it is possible for more than one SQL driver to be installed on your computer this result may consist of 1 or more driver strings in your supplied character buffer. Each driver string will be separated in your buffer by a null terminator and the final driver will have an additional null terminator added.
For example: "
Driver 1\0Driver 2\0Driver 3\0\0
"
The bolded
\0 characters denote the null terminators between each driver string. You'll have to parse each driver string out one by one and examine it to determine if it's the driver you need.
WCHAR driverBuffer[1000];
WORD returnedCount;
BOOL isOK = SQLGetInstalledDriversW(driverBuffer, 1000, &returnedCount);
if (isOK)
{
}
else
{
}
The function you listed in your question (SQLGetInstalledDriversW) is the Multi-Byte Character Set (eg. unicode) version of the function (That's what the W signifies). I believe the character set is set by the MFC project configuration. If you're not configured for MBCS this function will give you some trouble when you compile (function not found, WCHAR undefined, etc.). If you are using MBCS you're fine. If not, use the version without the "W"(SQLGetInstalledDrivers). Then substitute char or TCHAR for WCHAR. If you use TCHAR then I believe the non-W function will work regardless as to whether or not you configure for MBCS.