Application exe name and path?

    How can I get application path + .exe name? Example:

CString cAppName = theApp->ExeName;
//cAppName == "c:\projects\my_app.exe"

Thank you.


0
Oliver
11/18/2003 1:18:50 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
1501 Views

Similar Articles

[PageSpeed] 45

"Oliver Young" <none> wrote:

>
>    How can I get application path + .exe name? 

Look up GetModuleFileName()

-- 
Tim Slattery
MS MVP(DTS)
Slattery_T@bls.gov
0
Slattery_T (112)
11/18/2003 1:36:26 PM
Actually, I think the answer you were looking for is to 
look up AfxGetAppName().

GetModuleFileName() requires a module handle, and is aimed 
at DLL support (I've never even used it for EXEs, and have 
no idea if it would even work).

>-----Original Message-----
>"Oliver Young" <none> wrote:
>
>>
>>    How can I get application path + .exe name? 
>
>Look up GetModuleFileName()
>
>-- 
>Tim Slattery
>MS MVP(DTS)
>Slattery_T@bls.gov
>.
>
0
anonymous (74722)
11/18/2003 2:11:40 PM
    AfxGetAppName() will not return you the application path. It just
returns you the name of your application.

    GetModuleFileName() will work fine for EXE's also. Pass NULL as the
module handle.

-- 
Cheers
Check Abdoul [VC++ MVP]
-----------------------------------

"Huw" <anonymous@discussions.microsoft.com> wrote in message
news:06f001c3addd$e2f858d0$a401280a@phx.gbl...
> Actually, I think the answer you were looking for is to
> look up AfxGetAppName().
>
> GetModuleFileName() requires a module handle, and is aimed
> at DLL support (I've never even used it for EXEs, and have
> no idea if it would even work).
>
> >-----Original Message-----
> >"Oliver Young" <none> wrote:
> >
> >>
> >>    How can I get application path + .exe name?
> >
> >Look up GetModuleFileName()
> >
> >-- 
> >Tim Slattery
> >MS MVP(DTS)
> >Slattery_T@bls.gov
> >.
> >


0
CheckAbdoul
11/18/2003 2:41:21 PM
"Huw" <anonymous@discussions.microsoft.com> wrote in news:06f001c3addd
$e2f858d0$a401280a@phx.gbl:

> GetModuleFileName() requires a module handle, and is aimed 
> at DLL support (I've never even used it for EXEs, and have 
> no idea if it would even work).

You can certainly pass NULL for the handle.  

I use this method because I get the full path. 
Then I can do a split path to get all of the different 
pieces of the puzzle.  

After you get the full path lookup _splitpath on MSDN
which has a great example of splitting up the path. 
IMO once you try split and make path you'll never want 
to go back to path hacking. 

-- 
Mike Pulice
http://www.puliceworx.com
0
badvox (5)
11/18/2003 3:20:46 PM
    Thank you all for your response. I tried something like this:

CString GetAppPath()
{
 LPTSTR name = new LPTSTR[999]
 GetModuleFileName(NULL, &name, 999);
 CString result = name;
 delete[] name;
 return result;
}

    but, got error:

cannot convert from 'char ** ' to 'char *'


0
Oliver
11/18/2003 4:41:43 PM
This should be

        GetModuleFileName(NULL, name, 999);

An easier way would be...


    CString GetAppPath()
    {
        CString result, sPath;

        ::GetModuleFileName(NULL, result.GetBuffer(MAX_PATH), MAX_PATH);
        result.ReleaseBuffer();

        int nOffset = result.ReverseFind( TEXT('\\') );
        if ( nOffset != -1 )
            sPath = result.Left( nOffset+1 );    // Trim the file name
       else
            sPath  = result;

        return sPath;
    }


-- 
Cheers
Check Abdoul [VC++ MVP]
-----------------------------------


"Oliver Young" <none> wrote in message
news:ucoHULfrDHA.1656@tk2msftngp13.phx.gbl...
>
>     Thank you all for your response. I tried something like this:
>
> CString GetAppPath()
> {
>  LPTSTR name = new LPTSTR[999]
>  GetModuleFileName(NULL, &name, 999);
>  CString result = name;
>  delete[] name;
>  return result;
> }
>
>     but, got error:
>
> cannot convert from 'char ** ' to 'char *'
>
>


0
CheckAbdoul
11/18/2003 5:05:10 PM
Reply:

Similar Artilces:

Clicking one application's buttons from another application
Hello, I'd like to write an application that can click the buttons of another application running on the same machine. All my application knows about the target application is its name, the name of the window containing the buttons, and the name of the buttons. Can someone further my education in this matter in some way. Thanks, Ray Mitchell This is tricky, but possible. I actually do it in a little utility I wrote to move Outlook filters down, since the "Move Down" button doesn't autorepeat and when you have 850 anti-spam filters it becomes a bit unwieldy. What yo...

Need file name
What is the name of the file that shows if the e-mails are actually leaving my desktop. Last month someone told me to turn that on so we could track the e-mails and I forgot to change it back. I thought I had saved all the messages but of course they are gone. Thanks for any help you can give me. -- Shirley Shirley wrote: || What is the name of the file that shows if the e-mails are actually || leaving my desktop. Last month someone told me to turn that on so || we could track the e-mails and I forgot to change it back. I || thought I had saved all the messages but of course they are...

running another application from my application
Hello, I have an MDI application that on a specific case runs a 3rd party application. I use PeekMessage so my application will be drawn corretly while working on the 3rd party app. I want to prevent the user from doing anything in my application while te 3rd party app is running, until the user closes the 3rd party application. Also I want my application to be shown correctly (handle WM_PAINT, WM_DRAW etc.). Currently my application is displayed very well, but the user may do things in my application while the 3rd party app is running. I use the following code (pseuo): BOOL bRetVal = CreateP...

Application exiting with return Code 3 and ExitInstance not called neither destructors
Hey Friends It seems that i have done something very mysterious as my Application is exiting with return Code 3 and ExitInstance is not not called neither destructors. Plz Help "Vikrant_kpr" <bhatia.manish@netsity.com> wrote in message news:f62362ec.0307170549.7af528cf@posting.google.com... > Hey Friends > It seems that i have done something very mysterious as my Application > is exiting with return Code 3 and ExitInstance is not not called > neither access violation? Dear Antonio Mazzeo I have corrected the problem,it was causing due to Splash Screen Compone...

SHBrowseForFolder mapped drives names
Hello, I spotted a strange problem when using SHBrowseForFolder dialog. For mapped drives it always displays appropiate contents, but the name is not always up-to-date. If my program is running and I change the mapped directory to point to some other location and give it a new name but use one of previously defined drive letters, the name in SHBrowseForFolder for this drive letter remains unchanged until I close the program and run it once again. Does anybody know how to refresh the dialog so that it contains appropiate drive names? Thx JarekZPl P.S. I use visual c++ 6 and windows xp ...

Ideas for a Dept Level Application Support
We have an IT group that supports 50 applications and they wish to capture support time by application during course of the year. During the course of a week, any application or combination of applications can have support requests, so it is different week to week and not predictable. Essentially we are looking to park the time with appropriate application after the work is complete. We are using Project Server 2007 and have investigated the following: 1. Created a Annual Support workplan with a task per application in Project Pro with the IT group added as Enterprise resourc...

Error: "Duplicate Record A record of this type with this name already exists"
I have a strange error that started today. (I am Using V1.2) When I try to convert a lead to an account AND a contact I get the following msg: "Duplicate Record A record of this type with this name already exists. Please choose a different name and try again" At the end of the process the program is crating an Account record but not a contact record. If I try to convert the same lead again to a Contact I get the same msg. Converting a lead to an Account or Contact ONLY will work fine. The following is error is registered on the server Application log: Event Type: Error Event Sou...

Help in creating dialog based application
Hi, I am creating a dialog based application which has a main dialog with 3 buttons. 1. Address Book 2. Student List 3. Course List with which i can go to any one of the screens(which is again the dialog). when i click address book button my main dialog should be hidden/closed and i should open the address book dialog which has again some button to navigate back to main dialog/student list/course list. same kind of functionality for other two dialogs(student/course list). i thought of creating all the 3 dialogs as modeless and main dialog as parent but how i will inform the parent window to ...

DLLs being loaded for all applications
I get the following warning at system startup: "Custom dynamic link libraries are being loaded for every application. The system administrator should review the list of libraries to ensure they are related to trusted applications." How do I review the list of libraries and how do I eliminate any that should be removed? ...

Converting Console Application to win32 application
I have created an MFC console application. When I run it from Windows Explorer it opens a dos box and closes the box when it terminates it logic. Is it possible to convert it so it won't open the dos box - just run without any display? If positive, please help me regarding the steps. Thanks Kalish I am not sure if you can compile MFC with a standard win32 application, but if you can, then you can simply change your main to a WinMain, and you will have the result you want. Create a Win32 Project using the Wizard, and selection Windows Application, to see an example. Remove everthing ...

is there a hotel management excel application?
The subject says is all... TIA Martyn Hi Martyn, See response to your thread in Programming. --- Regards, Norman "Cheker" <zoomer@gmail.com> wrote in message news:eNJLsRRqEHA.348@TK2MSFTNGP15.phx.gbl... > The subject says is all... > TIA > Martyn > > > ...

Create Named Range for each unique value
Hi! All help is welcome here... Am really stuck. What I have is a list of room numbers. Many appear multiple times i column A, but it will always be sorted. What I need is a way to easily create Named Ranges for each group of rooms. (ie all rows with value 1 becomes one named range, rows with value 5 becomes one named range and so on) Range Name should prefereable be same a room name. Would like the code to go through column A and create ranges for each unique value. (could also have a "supporting" sheet with uniqe values if necessary) Any takers? If the valu...

MSMQ ... authenticating application
A number of application stores messages in MSMQ. One of the server application needs to read messages that was created/stored by specific applications not to read all the messages in MSMQ. Is there any workarounds? Thank you Regards Raj "Raj" <Raj@discussions.microsoft.com> wrote in message news:6917708E-88B1-497B-A888-5038ACEA17CE@microsoft.com... >A number of application stores messages in MSMQ. One of the server > application needs to read messages that was created/stored by specific > applications not to read all the messages in MSMQ. > ...

DLL
Is there any way to detect when an application that is calling my dll is about to be destroyed? I need to close several files if the calling application has not done so, therefore I need to detect when the calling application is about to be destroyed and clean up the files and variables I have used in the dll. You need to implement DllMain, the handle your cleanup tasks when you receive a PROCESS_DETACH notification. Check out: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_initialize_non.2d.mfc_dlls.asp "Joe Estock" <jestock@NOSPAMnutexto...

MFC applications and Visual C++'s newer editions
Hello. When it comes to Win32, Visual Studio .NET 2005 Express Edition Beta 2 only allows the creation of console-based applications. What if one wanted to create MFC-based applications and, at the same time, be able to take advantage of the powerful and conforming C++ compiler that comes with the package? I hope that resorting to Visual C++ 6.0 is not the only option. Thank you, -- Ney Andr� de Mello Zunino "Ney Andr� de Mello Zunino" <zunino@inf.ufsc.br> wrote in message news:%23FuRyAcXFHA.584@TK2MSFTNGP15.phx.gbl... > Hello. > > When it comes to Win32, Vi...

Excell error BRSTSWND.exe
DWhat is this? I get it when i open an Excell spreadsheet I don't know what it is, but Chip Pearson has some techniques for diagnosing startup problems at: http://www.cpearson.com/excel/StartupErrors.htm David in Virginia wrote: > > DWhat is this? I get it when i open an Excell spreadsheet -- Dave Peterson ec35720@msn.com ...

Telnet application
Greets, Quick question.... If I was to write a VB6 app for configuring an IP device using Telnet, would it be more advantageous to use the Winsock control, or the INet control for the telnet session ? The device has the telnet server, I just need to write a GUI that uses telnet as a client to communicate with the device, and then present the configuration info in a typical GUI way. TIA, DanS "DanS" <t.h.i.s.n.t.h.a.t@r.o.a.d.r.u.n.n.e.r.c.o.m> wrote in message news:Xns9CEA5E17494CEthisnthatroadrunnern@216.196.97.131... > Greets, > > Quick...

copy address information from one sheet to another if customer name matches vendor name
I am preparing my customer and vendor list to be imported into a new database application. I have a workbook with page 1 containint my vendors and page 2 containing my customers. I want to automatically pull the address infromation from the vendor sheet to the customer sheet is the names are an exact match. Can anyone shed some light on this for me? You can use the VLOOKUP function Let's assume SHEET1 contains the name of vendors SHEET2 contains the name of customers Then your formula in the cell B1 of SHEET2 would be(where the name of the customer is cell A1) =VLOOKUP(A1,Sheet1!A1:...

email name lookup
How can I edit out names that I no longer require from the auto name lookup list. The names are no longer in my contact file but they are still looked up after I type a few characters. Thanks Use arrow keys to highlight, then Delete key "chuck" <anonymous@discussions.microsoft.com> wrote in message news:2e8d01c48eba$2e9451f0$a301280a@phx.gbl... > How can I edit out names that I no longer require from the > auto name lookup list. The names are no longer in my > contact file but they are still looked up after I type a > few characters. > > Thanks ...

Name Display is Wrong
When I enter the full name Mr. John Smith Doe for a new contact the display for Full Name comes up Mr. Doe Smith John. When I click send a letter to (using word), the name is displayed as Mr. Doe Smith John. I am using Outlook 2002(XP) and Windows ME. Any suggestions?? Thanks so much for your response. Tried your suggestion and it made no change at all. JOHN >-----Original Message----- >Try adjusting your display name settings found at Tools | Options | >Preferences tab | Contact Options. > >"John" <jeichorn@mindspring.com> wrote in message >news:...

Underscore in Computer name
Hi, hope somebody can help. It looks like some companies are logging email from my company as SPAM. I think it is because the email message look like they have malformed header information due to the fact that my exchange server has a computer name with an underscore in it... I changed the DNS hostname in network settings to reflect a dash instead of an underscore, but the exchange server still appends the underscored name in the message header in the received by section...which causes a bunch of garbage in the header... What are my options, outside of changing my computer name and...

Change Legend Entry label of "Total" to actual name of field.
I have two pivot charts. One has multiple criteria and when I create a pivot chart, each series field breaks out properly using the names provided in the multiple criteria given. Now, the issue is when I have a single (one) field name, the chart automatically has the legend entry of "Total" since I am using the 'sum of' option. I've manually changed the name of the field in the pivot table, but the label on the chart remains the same. I've go so far as to read several tips on going to the source data to change this but of course when working with pivot tables, you ca...

Using MABLE logic engine with existing .NET applications.
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web services. � MABLE utilizes SOAP 1.2 protocol. � MABLE uses AXIS 1.4 as a web service transport. � MABLE support state-full conversations by implementing a conversation session. In this small article we will create a client application that use the MABLE 'Store' application MABLE Web Service client has to maintain a state-full conversation with the MABLE engine. The best way to handle this is...

Hiding application
Hello, How can I hide my application from the user? I don't want him to see it in Task Manager, Task Bar, etc. Regards, Vladimir. "Vladimir" <genisoft@ufacom.ru> wrote in message news:ueUr72idDHA.736@TK2MSFTNGP09.phx.gbl... > Hello, > > How can I hide my application from the user? I don't want him to see it > in > Task Manager, Task Bar, etc. Make it a service. -- -GJC -Software Consultant (Embedded systems and Real Time Controls) -gchanson@mvps.org -Abolish public schools It'll be still visibled, and killable by administrator - li...

Change 1 dialog application to 2 dialogs applications?
Hi, I have made a mfc dialog based application. Now I want to change it to 2 dialogs, one wizzard and one classic, and i want the 2 dialog can call each other. So I change the codes in App::InitInstance() { ..... while (CGlobal::Get()->m_eView!=CGlobal::Quit) { WizzardDlg dlg0; CClassicDialog dlg1; CDialog *pdlg=0; if (CGlobal::Get()->m_eView==CGlobal::Wizzard) { pdlg = &dlg0; } else if (CGlobal::Get()->m_eView==CGlobal::Classic) { pdlg = &dlg1; } m_pMainWnd = pdlg; int nResponse = pdlg->DoModal(); } I found DoModal() only launch the dialog s...