Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Enumerate OLEDB Providers
Message
From
13/12/2001 15:09:13
 
 
To
13/12/2001 14:57:46
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00593614
Message ID:
00594026
Views:
49
>I was thinking about adding comments and possibly a few more checks maybe on an Error event on a class. It would be nice to have your changes if you have added them already.
>
>Also, it wasn't clear that you wanted to create something like the data links dialog. If you want to pop-it up programmatically all you need to do is:
>
>
oDLink = CreateObject("Datalinks")
>oDLink.PromptNew()
>If you are able to test the connection succesfully you can get the return value from the function and it will be an ADO connection object. I have another download here that does this. It's called something like "Get parameters collection".

Actually, I do need to enumerate them for other purposes, but it's nice to know it's easy to access this dialog if necessary.

Here's my commented version:
*!*			 Module: EnumOLEDBProviders.PRG
*!*	Description: Creates an array containing the names of all installed
*!*							OLE DB Providers
*!*	 Parameters: taProviders - a variable passed by reference
*!*			Returns: taProviders, changed into an array and populated with provider names
*!*	Sample Call:
*!*		gaOLEDBProviders = ""
*!*		?EnumOLEDBProviders(@gaOLEDBProviders)

*!*	History:
*!*	2001.12.13 - J. Crescencio Flores - Original Version
*!*		Universal Thread message http://www.levelextreme.com/wconnect/wc.dll?FournierTransformation~?2,15,593911
*!*	2001.12.13 - Al Doman
*!*		Commented the code
*!*		Modified variable names to be more descriptive
*!*		Changed ASCAN() call to be EXACT and case-insensitive
	
#DEFINE HKEY_CLASSES_ROOT -2147483648  && BITSET(0,31) from registry.h

LPARAMETERS ;
	taProviders
	
LOCAL ;
	loReg, ;
	lnErr, ;
	lcValue, ;
	lnProviderCount, ;
	laKeys, ;
	laSubKeys, ;
	llIsProvider
	
DIMENSION ;
	taProviders[1]

lnProviderCount = 0

* Create a VFP FFC Registry object:
loReg = NEWOBJECT("Registry", HOME() + "FFC\Registry.VCX")

* Open HKEY_CLASSES_ROOT\CLSID:
loReg.OpenKey("CLSID", HKEY_CLASSES_ROOT)

* Enumerate all keys of HKEY_CLASSES_ROOT\CLSID into an array:
lnErr = loReg.EnumKeys(@laKeys)

IF lnErr <> 0
	RETURN lnErr
	
ENDIF

* Close the current key:
loReg.CloseKey()

* Scan each element of the array collection (i.e. all subkeys of
* HKEY_CLASSES_ROOT\CLSID):
FOR EACH arrElem IN laKeys
	laSubKeys = .F.
	llIsProvider = .F.
	
	* Open the collection key:
	lnErr = loReg.OpenKey("CLSID\" + arrElem, HKEY_CLASSES_ROOT)
	
	IF lnErr=0
		* Enumerate subkeys of this key into another array:
		lnErr = loReg.EnumKeys(@laSubKeys)
		
	ENDIF
	
	* Close the collection key:
	loReg.CloseKey()

	IF VARTYPE(laSubKeys) <> "L"
		* This collection key is an OLE DB Provider if one of its
		* subkeys is "OLE DB Provider":
		llIsProvider = (ASCAN(laSubKeys, "OLE DB Provider", -1, -1, 0, 7) <> 0)
		
	ENDIF

	IF llIsProvider
		* Get the string value of this key
		* Conveniently, it's the name of the provider:
		lnErr = loReg.GetRegKey("", ;
			@lcValue, ;
			"CLSID\" + arrElem + "\OLE DB Provider", ;
			HKEY_CLASSES_ROOT)
		
		IF lnErr=0
			* Increment the provider count only if we can get the string value:
			lnProviderCount = lnProviderCount + 1
			
			IF lnProviderCount > 1
				* Add a new output array element:
				DIMENSION taProviders[lnProviderCount]
				
			ENDIF
			
			* Write the provider name to the new output array element:
			taProviders[lnProviderCount] = lcValue
			
		ENDIF
		
	ENDIF
	
ENDFOR

RETURN 0
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform