?
Solved

GetCurrentDirectory

Posted on 2003-03-25
4
Medium Priority
?
391 Views
Last Modified: 2012-06-27
I have a process (exe) that calls the Dll. I am using GetCurrentDirectory(size, char*) function to get
the current directory of the process.This function does not work for the dll, can you please suggest why?
Is the process missing any lib?

0
Comment
Question by:pbavishi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Expert Comment

by:gj62
ID: 8204783
What do you mean it doesn't work for the DLL.  Does it crash?  What value is returned?  Which version of the compiler are you using?
0
 
LVL 3

Accepted Solution

by:
TascoDLX earned 80 total points
ID: 8208764
If you want the directory in which the DLL or EXE resides, you should use GetModuleFileName() and strip the filename off of the result.

Here's a sample:

This function works for DLLs and EXEs and compiles in both ANSI and UNICODE.

Required headers:

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

GetModuleDirectory takes an HMODULE (or an HINSTANCE [same]) hModule and writes that module's directory to string szPath of character size nSize.

  void GetModuleDirectory(HMODULE hModule, TCHAR *szPath, int nSize)
  {
    TCHAR *pchEnd = szPath;

    if (GetModuleFileName(hModule, szPath, nSize) != 0)
    {
      if ((pchEnd = _tcsrchr(szPath, _T('\\'))) == NULL)
         pchEnd = szPath;
      else
         pchEnd = _tcsinc(pchEnd);
    }
    *pchEnd = _T('\0');
  }

Enjoy!
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10194560
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by TascoDLX.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

752 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