loadLibrary with relative path/ findFile with relative path

Posted on 2009-12-23
Last Modified: 2013-11-23
My C++ application will be compiled to DLL (name MYAPP.dll). Then I put this dll to another folder.
In my application, I need to load another dll, then I call like this
HMODULE m_Lib = LoadLibrary(_T("..\dll\ANOTHER.dll"));
The m_Lib is NULL.
The same thing as using findFile
CFileFind finder;
BOOL finding = finder.FindFile (CString("..\lib\*.jar"));
The result is always FALSE
My directory structure like this

Thanks for your help
Question by:ndhai
    LVL 43

    Expert Comment


    the .. moves one UP the directory path - into C:\\  lib and dll are not subdirectories of that.

    Author Comment

    You're right, but althought I modify to .\dll, \dll, and dll, it doesnt work.
    The problem is that, the current directory is not C:\Test, it is C:\Document and Setting\username, so the dll directory is not the sub directory of the current directory.
    Anyone has an idea?
    LVL 43

    Expert Comment

    Use the full path instead.


    Accepted Solution

    I found the a solution like that:
    //get the dll path, that will return CString
    LPTSTR  strDLLPath = new TCHAR[_MAX_PATH];
    GetModuleFileName((HINSTANCE)&__ImageBase, strDLLPath, _MAX_PATH);
    HMODULE m_Lib = LoadLibrary(strDLLPath + CString("/dl/ANOTHER.dlll"));

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now