Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL registered ? 1

Status
Not open for further replies.

154868

Programmer
Dec 5, 2003
23
I want to check if a DDL is registered before
I call CREATEOBJECT(....).
How can I do that ?

Andreas
 

I want to check if a DDL is registered before

I assume you meant a DLL. Just trap the error that occurs when it is not registered.
Code:
On ERROR do myerror
o=Createobject("myDll")

PROCEDURE myError
  messagebox("DLL is not registered")
  On error
ENDPROC




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
You can also do a quick registry read for the dll. I believe there are registry read examples in the FAQ section. If it is not registered, you can register it by running regsvr32 in silent mode:

RUN /n regsvr32 myDLL.DLL /S

Jim Osieczonek
Delta Business Group, LLC
 
Thanks for the tip.
Sorry, I mean DLL.

But give it any way to check it
without create a Error ?

Andreas
 
How is a easy way to read registry for a DLL ?

Andreas
 
I looked in the FAQs and did not see a registry read program.

There is a registry program that comes with VFP, but I found it confusing. Therefore, I created my regread method as part of my base class. There are a couple of pieces to it.

I'll need to chop my class up and get the pieces you need. I don't have time right now, but should be able to get to it later this evening or tomorrow.




Jim Osieczonek
Delta Business Group, LLC
 
I'll put this together as an FAQ in the near future and it will be a bit more clear, but here it is to get you going.


This code assumes you have vfp 7.0 installed. If not, change the 7.0 to your version.

Just copy all this code in a prg and run it. It will return the product ID in a messagebox.

bCode Below Here:


PUBLIC goApp
goApp = CREATEOBJECT('capp')
MESSAGEBOX(goApp.ReadReg('HLM','Software\Microsoft\VisualFoxpro\7.0\Registration','ProductID'))

**************************************************
*
DEFINE CLASS capp AS container

*-- Reads the windows Registry.
PROCEDURE readreg
* Start of Code
LPARAMETERS tcKey,tcSubKey,tcValue
IF PCOUNT() = 2
tcValue = ""
ENDIF

* setup environment

LOCAL nKey, cSubKey, cValue, cValueRead

#DEFINE HKEY_USERS -2147483645
#DEFINE HKEY_LOCAL_MACHINE -2147483646
#DEFINE HKEY_CURRENT_USER -2147483647
#DEFINE HKEY_CLASSES_ROOT -2147483648

DO CASE
CASE m.tcKey == "HCR"
nKey = HKEY_CLASSES_ROOT
CASE m.tcKey == "HLM"
nKey = HKEY_LOCAL_MACHINE
CASE m.tcKey = "HCU"
nKey = HKEY_CURRENT_USER
CASE m.tcKey = "HCR"
nKey = HKEY_CLASSES_ROOT
OTHERWISE
nKey = m.tcKey
ENDCASE

cSubKey = m.tcSubKey
cValue = m.tcValue

* example 1
* nKey = HKEY_LOCAL_MACHINE
* cSubKey = "Software\VfpRegTest"
* cValue = "TestREG_SZ"

* example 2
* nKey = HKEY_CLASSES_ROOT
* cSubKey = "Spin.SpinButton\CLSID"
* cValue = ""


* here is where we will actually read the registry
cValueRead = THIS.ReadREG_SZ(nKey, cSubKey, cValue)

* testing only
IF (EMPTY(cValueRead)) THEN
* THIS.STOP("Function Not Successful.")
ELSE
* THIS.INFO("Function Successful. " + cValueRead)
ENDIF

RETURN cValueRead



ENDPROC


*-- API's used by the ReadReg method.
PROCEDURE readreg_sz
* This function reads a REG_SZ value from the registry. If successful,
* it will return the value read. If not successful, it will return an empty string.

PARAMETERS nKey, cSubKey, cValue
* nKey The root key to open. It can be any of the constants defined below.
* #DEFINE HKEY_CLASSES_ROOT -2147483648
* #DEFINE HKEY_CURRENT_USER -2147483647
* #DEFINE HKEY_LOCAL_MACHINE -2147483646
* #DEFINE HKEY_USERS -2147483645
* cSubKey The SubKey to open.
* cValue The value that is going to be read.

* Constants that are needed for Registry functions
#DEFINE REG_SZ 1

* WIN 32 API functions that are used
DECLARE Integer RegOpenKey IN Win32API ;
Integer nHKey, String @cSubKey, Integer @nResult
DECLARE Integer RegQueryValueEx IN Win32API ;
Integer nHKey, String lpszValueName, Integer dwReserved,;
Integer @lpdwType, String @lpbData, Integer @lpcbData
DECLARE Integer RegCloseKey IN Win32API Integer nHKey

* Local variables used
LOCAL nErrCode && Error Code returned from Registry functions
LOCAL nKeyHandle && Handle to Key that is opened in the Registry
LOCAL lpdwValueType && Type of Value that we are looking for
LOCAL lpbValue && The data stored in the value
LOCAL lpcbValueSize && Size of the variable
LOCAL lpdwReserved && Reserved Must be 0

* Initialize the variables
nKeyHandle = 0
lpdwReserved = 0
lpdwValueType = REG_SZ
lpbValue = ""

nErrCode = RegOpenKey(nKey, cSubKey, @nKeyHandle)
* If the error code isn't 0, then the key doesn't exist or can't be opened.
IF (nErrCode # 0) THEN
RETURN ""
ENDIF

lpcbValueSize = 1
* Get the size of the data in the value
nErrCode=RegQueryValueEx(nKeyHandle, cValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)

* Make the buffer big enough
lpbValue = SPACE(lpcbValueSize)
nErrCode=RegQueryValueEx(nKeyHandle, cValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)

=RegCloseKey(nKeyHandle)
IF (nErrCode # 0) THEN
RETURN ""
ENDIF

lpbValue = LEFT(lpbValue, lpcbValueSize - 1)
RETURN lpbValue
ENDPROC


ENDDEFINE
*
*-- EndDefine: capp
**************************************************


Jim Osieczonek
Delta Business Group, LLC
 
It works great !
Thank you for any help.

Andreas
 
Glad it help out. I chopped all this code a long time ago from the VFP registry.prg and made it a class. As I mentioned, I found the vfp registry program difficult to work with. Maybe it was just my pea brain at the time.

Anyway, it was a bit of work but it has certainly made my life easier.



Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top