?
Solved

GetCurrentDirectory

Posted on 2003-03-25
4
Medium Priority
?
394 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
3 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

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
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.
Suggested Courses

600 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