views:

39

answers:

1

Hi

I have inherited a VB6 application from a friend of a family member, who wants to have some enhancements done to it. I haven’t developed in VB for more than 3 years (I’m currently developing in MS Dynamics Ax).
I’ve recently upgraded my hardware and am now running Win7. The last time I worked with the app (about a year and a half ago) was on a WinXP platform, and everything worked fine. Now when I run the app (through code) on Win7, I get an error when trying to read from the registry. Yes, I am running VB as administrator.

The code to read from the registry is: Public Function sReadRegistry(ByVal hKeyRoot As Long, _ ByVal sSubKey As String, _ ByVal sValueName As String) As String

Dim r As Long
Dim sData As String * 255
Dim lDataSize As Long
Dim sTempVal As String
Dim readValue As String

lDataSize = 255

'Get the Value Requested
lDataSize = 255
r = VRegReadString(hKeyRoot, sSubKey, sValueName, sData, lDataSize)
If r Then
    sTempVal = ""
Else
    sTempVal = Left$(sData, lDataSize - 1)
End If

sReadRegistry = sTempVal

End Function

The “VRegReadString “ is declared within a module; and is declared as follows:

Declare Function VRegReadString Lib "VREG" (ByVal hKeyRoot As Long, ByVal sSubKey As String, ByVal sValueName As String, ByVal sData As String, ByRef lDataSize As Long) As Long

It complains about the “VREG” library… The error I get is: “File not found: VREG”.

Is there a reference or component that I forgot to select? Can somebody please help with a solution?

Thanks in advance.

+1  A: 

Seeing that the function declaration is an import from an external library called "VREG", you are probably missing the actual library itself, i.e. VREG.DLL. Unfortunately, this doesn't seem to be a common library, so you'd have to come up with it yourself.

Good news is, though, accessing the registry is not really hard and can be done with just the bare Windows API, especially seeing that VREG.DLL does not really seem to add a good deal of abstraction to the regular API. Take a look at these functions:

Registry Functions

...which you can use to easily re-write registry access, provided you fail to procure the needed DLL from somewhere.

Jim Brissom
A ha, I do have that dll somewhere (not on this new machine though). Let the search begin... Thanks Jim!
Celeste
Oh, another thing: how do I register the DLL in Win7? What is the run comand for registering a file?
Celeste
You only need to register DLLs exposing COM objects. This is a regular DLL that simply exports functions, there is no need to register. Simply put it in a path where the application can find it. See: http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx
Jim Brissom