News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Relative Directories with MASM

Started by Sekkusu, March 19, 2006, 12:39:14 AM

Previous topic - Next topic

Sekkusu

I have an ASM EXE and DLL, and I'm trying to get it so that the EXE can load the DLL regardless of which directory they're both in, provided they're together in the same directory.

Right now I have:
    dllloc db "e:\resolve\resolve.dll", 0

and I load it using dllloc as the path. I tried setting dllloc to "resolve.dll" but it just didn't load then.

Is there an easy way to load the absolute path of a DLL into a string using the relative path?

Thank you very much, and if you have any questions feel free to ask me.

zooba

LoadLibrary checks specific places for the DLL specified. Check out MSDN. One of the places it checks is the directory the calling process was launched from, so there should be no problems there.

Sekkusu

Hm, well I must have been doing something wrong, it works now.

For educational purposes though (I was messing around and man I'm a failure, couldn't) is there an easy way to make absolute out of relative? Just the string anyways, I don't need to plug it into LoadLibrary anymore.

Thanks!

Mincho Georgiev


zooba

And PathCanonicalize, which goes through and removes '.\' and '..\' directories.

hutch--

GetModuleFileName() always supplies you the complete path of the exe it is called from so if you strip the file name off that full path and use the DLL name, you can always access the DLL no matter where the EXE is started from as long as the DLL is in the same directory as the calling EXE file.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

Here's a little play to path a module's INI file:


.data?
    SelfDir   db   MAX_PATH dup(?)
.code
    invoke GetModuleFileName,0,addr SelfDir,MAX_PATH    ; .\MyFile.exe
    mov ecx,offset SelfDir                          ; ecx = pointer
@@:
    mov al,byte ptr[ecx]                            ; find end
    inc ecx
    test al,al
    jnz @B
    mov dword ptr[ecx-4],00696E69h                  ; make extension "ini",0


Thanks to KetilO, because GetCurrentDirectory is NOT always accurate.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Sekkusu

Thanks everyone, especially Mark Jones. I was going to try that same idea out today!