How do I Retrieve Dir of my COM object?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Kaptein

    How do I Retrieve Dir of my COM object?

    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 "thisDLLpat h" (read: any
    VB instruction doing just that)

    When the DLL is located in "c:\myDLLs\test DLL", the call "thisDLLpat h"
    within the DLL should return just that.
    When I move the DLL to "D:\myDLLs\fina lLocation" (on another server), the
    call "thisDLLpat h" 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

    #2
    Re: How do I Retrieve Dir of my COM object?

    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_RO OT = &H80000000
    Global Const HKEY_CURRENT_CO NFIG = &H80000005
    Global Const HKEY_CURRENT_US ER = &H80000001
    Global Const HKEY_DYN_DATA = &H80000006
    Global Const HKEY_LOCAL_MACH INE = &H80000002
    Global Const HKEY_PERFORMANC E_DATA = &H80000004
    Global Const HKEY_USERS = &H80000003
    Global Const REG_BINARY = 3 ' Free form binary
    Global Const REG_DWORD_BIG_E NDIAN = 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.d ll" Alias "RegOpenKey A"
    (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Public Declare Function RegOpenKeyEx Lib "advapi32.d ll" Alias
    "RegOpenKey ExA" (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.d ll" 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.d ll" Alias
    "RegQueryValueE xA" (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.d ll" Alias "RegSetValu eA"
    (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.d ll" 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.d ll" Alias
    "RegDeleteValue A" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    Public Declare Function RegDeleteKey Lib "advapi32.d ll" Alias
    "RegDeleteK eyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Public Declare Function RegEnumKey Lib "advapi32.d ll" Alias "RegEnumKey A"
    (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal
    cbName As Long) As Long
    Public Declare Function RegEnumKeyEx Lib "advapi32.d ll" Alias
    "RegEnumKey ExA" (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, lpftLastWriteTi me As FILETIME) As Long
    Public Declare Function RegEnumValue Lib "advapi32.d ll" Alias
    "RegEnumVal ueA" (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.ClassNa me & "\CLSID", lHandle)
    iret1 = RegQueryValueEx (lHandle, "", o&, 1, ByVal sValuename, lValuename)

    Now, find the location:

    Running Local:

    iret = RegOpenKey(HKEY _CLASSES_ROOT, "CLSID\" & Left$(sValuenam e, 38) &
    "\inprocserver3 2", lHandle)

    DCOM server:

    iret = RegOpenKey(HKEY _CLASSES_ROOT, "CLSID\" & Left$(sValuenam e, 38) &
    "\_inprocserver 32", lHandle)

    sValuename1 = Space$(255)
    lValuename1 = 255

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

    Pos = instr(sValuenam e1, Chr(0))

    MyPath = Left$(sValuenam e1, pos-1)


    "Peter Kaptein" <peterkaptein@h otmail.com> wrote in message
    news:403b2a82$0 $570$e4fe514c@n ews.xs4all.nl.. .[color=blue]
    > I am building websites using Databases and COM for 3tier apps.
    >
    > Currently I have to tell my COM object where the database is located[/color]
    either[color=blue]
    > 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 "thisDLLpat h" (read:[/color]
    any[color=blue]
    > VB instruction doing just that)
    >
    > When the DLL is located in "c:\myDLLs\test DLL", the call "thisDLLpat h"
    > within the DLL should return just that.
    > When I move the DLL to "D:\myDLLs\fina lLocation" (on another server), the
    > call "thisDLLpat h" 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[/color]
    a[color=blue]
    > Dir, register the DLL and presto!) Working on two or three different[/color]
    servers[color=blue]
    > it is the most flexible way to go.
    >
    >[/color]


    Comment

    • Bob Butler

      #3
      Re: How do I Retrieve Dir of my COM object?

      "Richard T. Edwards@pwpsqua red.net" <redwar@pwpsqua red.net> wrote in message news:<O2fFoS0#D HA.2432@TK2MSFT NGP11.phx.gbl>. ..[color=blue]
      > 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_RO OT = &H80000000
      > Global Const HKEY_CURRENT_CO NFIG = &H80000005
      > Global Const HKEY_CURRENT_US ER = &H80000001
      > Global Const HKEY_DYN_DATA = &H80000006
      > Global Const HKEY_LOCAL_MACH INE = &H80000002
      > Global Const HKEY_PERFORMANC E_DATA = &H80000004
      > Global Const HKEY_USERS = &H80000003
      > Global Const REG_BINARY = 3 ' Free form binary
      > Global Const REG_DWORD_BIG_E NDIAN = 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[/color]

      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?

      Comment

      • Willy Van den Driessche

        #4
        Re: How do I Retrieve Dir of my COM object?

        app.path


        "Peter Kaptein" <peterkaptein@h otmail.com> schreef in bericht
        news:403b2a82$0 $570$e4fe514c@n ews.xs4all.nl.. .[color=blue]
        > I am building websites using Databases and COM for 3tier apps.
        >
        > Currently I have to tell my COM object where the database is located[/color]
        either[color=blue]
        > 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 "thisDLLpat h" (read:[/color]
        any[color=blue]
        > VB instruction doing just that)
        >
        > When the DLL is located in "c:\myDLLs\test DLL", the call "thisDLLpat h"
        > within the DLL should return just that.
        > When I move the DLL to "D:\myDLLs\fina lLocation" (on another server), the
        > call "thisDLLpat h" 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[/color]
        a[color=blue]
        > Dir, register the DLL and presto!) Working on two or three different[/color]
        servers[color=blue]
        > it is the most flexible way to go.
        >
        >[/color]


        Comment

        • Peter Kaptein

          #5
          Re: How do I Retrieve Dir of my COM object?

          Thanks for the feedback.



          Comment

          Working...