Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I Retrieve Dir of my COM object?

3 views
Skip to first unread message

Peter Kaptein

unread,
Feb 24, 2004, 5:40:50 AM2/24/04
to
I am building websites using Databases and COM for 3tier apps.

Currently I have to tell my COM object where the database is located either
1) Hardcoded in the DLL
2) Via my ASP call

How do I retrieve the dir where my DLL is located?
In the VB6 runtime environment "CurDir" does it for the runtime-situation
Once I go "DLL" CurDir is retrieving the current active dir, that could be
anything.

Is a solution present by Microsoft?

== This is Where I want to go to:
I want to create/call something inside the DLL like "thisDLLpath" (read: any
VB instruction doing just that)

When the DLL is located in "c:\myDLLs\testDLL", the call "thisDLLpath"
within the DLL should return just that.
When I move the DLL to "D:\myDLLs\finalLocation" (on another server), the
call "thisDLLpath" within the DLL should return just that

== Why?
When building websites using 3tier, currently I need to set the full path
(or the ODBC name) to the database in either:
1) my ASP script
2) the ODBC manager

Just using the DLL with thisDLLpath enables me to cut away extra settings
and place the DB anywhere. It is less rigid (copy & paste DLL and DB into a
Dir, register the DLL and presto!) Working on two or three different servers
it is the most flexible way to go.


Richard T. Edwards@pwpsquared.net

unread,
Feb 24, 2004, 9:11:43 PM2/24/04
to
Global iret As Long
Global Filename As String
Global iret1 As Long
Global sValuename As String
Global lValuename As Long
Global pos As Long
Global lindex As Long
Global dwType As Long
Global lHandle As Long
Global lHandle1 As Long
Global lindex1 As Long
Global sValuename1 As String
Global lValuename1 As Long
Global sValuename2 As String
Global lValuename2 As Long
Global sValuename3 As String
Global lValuename3 As Long
Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_CONFIG = &H80000005
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_DYN_DATA = &H80000006
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_PERFORMANCE_DATA = &H80000004
Global Const HKEY_USERS = &H80000003
Global Const REG_BINARY = 3 ' Free form binary
Global Const REG_DWORD_BIG_ENDIAN = 5 ' 32-bit number
Global Const REG_DWORD = 4 ' 32-bit number
Global Const REG_EXPAND_SZ = 2 ' Unicode nul terminated
string
Global Const REG_SZ = 1 ' Unicode nul terminated
string

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal
ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValue Lib "advapi32.dll" Alias
"RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal
lpValue As String, lpcbValue As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
' Note that if you declare the lpData parameter as String, you must pass it
By Value.
Public Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA"
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal
lpData As String, ByVal cbData As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long)
As Long ' Note that if you declare the lpData parameter as String,
you must pass it By Value.
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias
"RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias
"RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Public Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA"
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal
cbName As Long) As Long
Public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias
"RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As
String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String,
lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Public Declare Function RegEnumValue Lib "advapi32.dll" Alias
"RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal
lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long,
lpType As Long, lpData As Byte, lpcbData As Long) As Long

First, find the clsid:

iret = RegOpenKey(HKEY_CLASSES_ROOT, Dllname.ClassName & "\CLSID", lHandle)
iret1 = RegQueryValueEx(lHandle, "", o&, 1, ByVal sValuename, lValuename)

Now, find the location:

Running Local:

iret = RegOpenKey(HKEY_CLASSES_ROOT, "CLSID\" & Left$(sValuename, 38) &
"\inprocserver32", lHandle)

DCOM server:

iret = RegOpenKey(HKEY_CLASSES_ROOT, "CLSID\" & Left$(sValuename, 38) &
"\_inprocserver32", lHandle)

sValuename1 = Space$(255)
lValuename1 = 255

iret1 = RegQueryValueEx(lHandle, "", o&, 1, ByVal sValuename1, lValuename1)

Pos = instr(sValuename1, Chr(0))

MyPath = Left$(sValuename1, pos-1)


"Peter Kaptein" <peterk...@hotmail.com> wrote in message
news:403b2a82$0$570$e4fe...@news.xs4all.nl...

Bob Butler

unread,
Feb 26, 2004, 10:17:20 AM2/26/04
to
"Richard T. Edw...@pwpsquared.net" <red...@pwpsquared.net> wrote in message news:<O2fFoS0#DHA....@TK2MSFTNGP11.phx.gbl>...

I think that's more global variables than in all the VB I've ever done combined.

Doesn't App.Path within the DLL return the path to the DLL?

Willy Van den Driessche

unread,
Feb 26, 2004, 2:47:30 PM2/26/04
to
app.path


"Peter Kaptein" <peterk...@hotmail.com> schreef in bericht
news:403b2a82$0$570$e4fe...@news.xs4all.nl...

Peter Kaptein

unread,
Mar 4, 2004, 6:11:26 PM3/4/04
to
Thanks for the feedback.

0 new messages