Announcement

Collapse
No announcement yet.

Full path of my DLL in runtime?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Edwin Knoppert
    replied
    Semen,
    What do you mean?

    I assume windows largest pathname can be 260 chars? not 259?
    ASCIIZ + 1 = 261 wich can contain 260 chars...

    ??


    ------------------

    Leave a comment:


  • Wayne Diamond
    replied
    thanks everyone, Semen your code did the trick perfectly (as usual!) - thanks


    [This message has been edited by Wayne Diamond (edited March 12, 2001).]

    Leave a comment:


  • Kev Peel
    replied

    Yeah, Edwin, You're right!

    I forgot that the original question was about getting the path of the DLL.
    You may notice that since the DLL is mapped into the calling EXE code, you will need the handle of the DLL, which is passed in LIBMAIN().

    GetModuleHandle("") will return the EXE module handle!

    Regards,

    ------------------
    Kev G Peel
    KGP Software, Bridgwater, UK.
    http://www.kgpsoftware.com

    Leave a comment:


  • Semen Matusovski
    replied
    Edwin --
    I never saw a code in MSDN, which uses %MAX_PATH + 1 as third parameter.
    Meanwhile the third parameter includes NUL and if to use, for example, 10, OS returns maximum 9 chars (+NUL)

    Simple sample:
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "WIN32API.INC"
       
       Function PbMain
          Dim TmpAsciiz As Asciiz * %MAX_PATH, ll As Long
          GetModuleFileName 0, TmpAsciiz, SizeOf (TmpAsciiz)
          ll = Len(TmpAsciiz): MsgBox TmpAsciiz,, Str$(ll)
          GetModuleFileName 0, TmpAsciiz, ll
          ll = Len(TmpAsciiz): MsgBox TmpAsciiz,, Str$(ll)
       End Function
    [This message has been edited by Semen Matusovski (edited March 12, 2001).]

    Leave a comment:


  • Edwin Knoppert
    replied
    This will return the name of the exe calling!

    Btw it's %MAX_PATH + 1 (!!)

    As described above, use the instance handle IN libmain.


    ------------------

    Leave a comment:


  • Scott Turchin
    replied
    Will this do it?

    Code:
    Function ApplicationPath() As String
    Local zTmp As Asciiz * 256
    Local LenExeName As Long
    LenExeName = GetModuleFileName(ByVal %NULL, zTmp, SizeOf(zTmp))
    If LenExeName Then
       LenExeName = Min&(LenExeName, SizeOf(zTmp))
       zTmp = Left$(zTmp, LenExeName)
    End If
    Function = Left$(zTmp,Instr(-1,zTmp,"\") -1 ) '-1 Removes trailing Backslash
    End Function

    ------------------
    Scott

    Leave a comment:


  • Kev Peel
    replied
    Wayne, a couple of things...

    A. Use "Dim ZString As Asciiz * %MAX_PATH", instead of 255 to be safe.
    B. Calling GetModuleHandle with an empty string will return the current module.

    Regards,


    ------------------
    Kev G Peel
    KGP Software, Bridgwater, UK.
    http://www.kgpsoftware.com

    Leave a comment:


  • Fred Oxenby
    replied
    *

    [This message has been edited by Fred Oxenby (edited March 12, 2001).]

    Leave a comment:


  • Semen Matusovski
    replied
    Wayne --
    Use hInstance parameter inside LibMain

    Exe:
    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "Win32Api.Inc"
    
       Declare Function DllPath Lib "Pb.Dll" As String
    
       Function PbMain()
          MsgBox DllPath
       End Function
    Dll
    Code:
       #Compile Dll "Pb.Dll"
       #Register None
       #Dim All
       #Include "WIN32API.INC"
       
       Global hInstDll As Long
       Function LibMain(ByVal hInstance   As Long, ByVal fwdReason   As Long, _
                        ByVal lpvReserved As Long) Export As Long
          If fwdReason = %DLL_PROCESS_ATTACH Then hInstDll = hInstance
          LibMain = 1
       End Function
       
       Function DllPath Export As String
          Dim TmpAsciiz As Asciiz * %MAX_PATH
          If GetModuleFileName (hInstDll, TmpAsciiz, SizeOf (TmpAsciiz)) Then Function = TmpAsciiz
       End Function
    [This message has been edited by Semen Matusovski (edited March 12, 2001).]

    Leave a comment:


  • Wayne Diamond
    started a topic Full path of my DLL in runtime?

    Full path of my DLL in runtime?

    I want to create a DLL for other programmers, and make it friendly enough so that people can rename my DLL without causing any hiccups.
    The only problem is that because my DLL needs to do a CRC check on itself first, it needs to know the full path location and filename of itself

    Peter Lameijn kindly posted the following example, but it assumes that you know the actual filename of your DLL - I need to find the full path of my DLL when it is loaded regardless of what the filename is. Can anybody help?
    Code:
    Function ReturnPath () Export As String
      Dim ZString As Asciiz * 256
      GetModuleFileName GetModuleHandle("mydll.dll"), ZString,SizeOf (ZString)
      Function = ZString
    End Function


    ------------------
Working...
X