Solved

Find actual path of program (EXE)

Posted on 1998-11-29
8
224 Views
Last Modified: 2010-04-15
I am trying to determine the path that the exe file was called from, i.e. the compiled C program may be in a directory different from the current one.
How do I find the EXE's true path? (sounds like enlightment for programs :)
Compiler is BC++ 3.1 for DOS.
0
Comment
Question by:idek1
  • 4
  • 2
  • 2
8 Comments
 

Author Comment

by:idek1
ID: 1254723
Edited text of question
0
 
LVL 8

Accepted Solution

by:
shlomoy earned 70 total points
ID: 1254724
Here is an answer I've seen on a newsgroup regarding...
I hope this helps you. if you're stuck - tell me - I'll explain.
So, here is the question (just as yours) and the proposed ansewr:


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

>I am having problems in getting the full path of the application
>executable when the application comes up.
>
>m_pszExeName of the CWinApp contains only the name of the executable,
>without extention or the full path.
>
>How can i get the above with the full executable name, or atleast the
>full path the directory which contains the executable.

You'll need to use the Windows API for this one...

    HMODULE hModule = ::GetModuleHandle(NULL);
    if (hModule == 0)
    {
      // error, couldn't get module handle, call ::GetLastError
    }
    else
    {
      char szExeFileName[_MAX_PATH];
      DWORD result = ::GetModuleFileName(hModule, szExeFileName, _MAX_PATH);
      if (result == 0)
      {
        // error retrieving name, call ::GetLastError
      }
    }

At this point, if you're using MFC, it's easy enough to convert the
character buffer into a CString, if that's what you want.
----------------------------------------------------------------------------------------------------------------------

0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1254725
You can also get the full path from __argv[0].
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
LVL 8

Expert Comment

by:shlomoy
ID: 1254726
also try:

char path[MAX_PATH];
        int len=GetModuleFileName(AfxGetInstanceHandle(),path,sizeof(path)-1);
        m_AppDir=CString(path, len);



0
 
LVL 11

Expert Comment

by:alexo
ID: 1254727
>> Compiler is BC++ 3.1 for DOS.
argv[0] holds full program name.
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1254728
I did mention argv[0], on one of my comments.
I supplied several ways to get the result needed.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1254729
try the following:

    #include <stdio.h>
    void main(int argc, char* argv[])
    {
        puts(argv[0]);
    }

0
 

Author Comment

by:idek1
ID: 1254730
THank you for your help. ARGV[0] is what I required. THe windows code is irrelevant in this case, as I am compiling for DOS only, and the program needs to run in DOS mode without any windows support.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

809 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