tags:

views:

144

answers:

2

Hi

My intension is to find the "Microsoft.SqlServer.Management.Sdk.Sfc.dll" is present in the system or not. And generally this will be came up with sqlserver2008 installation usually it is available in

C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies

or can u provide me atleast a way to find whther SQLSERVER2008 installed or not using c++

I am using LoadLibrary("Microsoft.SqlServer.Management.Sdk.Sfc.dll");

But it shows NULL even though it is available.

 HINSTANCE hDLL = LoadLibrary(TEXT("Microsoft.SqlServer.Management.Sdk.Sfc.dll"));
   if (hDLL == NULL)
  {
     printf("Could not load exe.0x%X\n",GetLastError());
     return;
  }
  else
   printf("DLL found\n");

it displays couldnot load exe 0x7E is the error code eventhough i given exct path.

A: 

Hi

One way is to check if the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion exists in the registry.

You might check this code http://www.daniweb.com/forums/thread12987.html# to ascertain whether a key exists or not.

cheers

Andriyev
A: 

Going by the comments in this answer we're looking to check if the file exists or not. The easiest way to do that is to use CreateFile rather than LoadLibrary. Here is some sample code:

HANDLE hFile = NULL;
// The flag OPEN_EXISTING will cause CreateFile to only return a valid
// handle value if the file exists. If it doesn't it returns INVALID_HANDLE_VALUE
// and sets the last error to ERROR_FILE_NOT_FOUND.
hFile = CreateFile(TEXT("path.to.dll"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
if (hFile == INVALID_HANDLE_VALUE) {
  DWORD dwError = GetLastError();
  if (dwError == ERROR_FILE_NOT_FOUND) {
    // the file wasn't found
  } else {
    // unknown error...
    _tprintf(TEXT("Error 0x%X\n"), dwError);
  }
} else {
  // the file was found, be sure to close the handle
  CloseHandle(hFile);
}


Well, LoadLibrary(lpFileName) uses the system default DLL Search Order (MSDN article on Dynamic-Link Library Search Order) and the path for the DLL is not in the default search path. You'll need to specify it directly.

You can get the installation path from the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\VerSpecificRootDir.

Also, if LoadLibrary fails, be sure to call GetLastError() so we can figure out what error is causing it to fail (Access Denied, File not Found, etc.).

Lastly, it looks like the Microsoft.SqlServer.Management.Sdk.Sfc.dll is a .net DLL, which may or may not have an entry point for standard c++.

Joshua
0x7E is the error code means specified module is not found is displayed
Cute
You're doing this to tell if the file exists on the system or not right (meaning you're not trying to load it to call its exported functions)?
Joshua
i am trying to find whether it is exist or not ?? if Handle to loadLibrary is null then the dll is avilable this is my idea?
Cute
@Cute, if all you want to do is check if the file exists, you can use CreateFile with the OPEN_EXISTING disposition. See my edited answer. :)
Joshua