Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 12th, 2005, 6:38 PM   #1
dc2000
Newbie
 
Join Date: Jun 2005
Location: Portland, OR
Posts: 12
Rep Power: 0 dc2000 is on a distinguished road
GetModuleFileName() with console app?

Hi everyone:


It seems to be very easy but somehow I'm stuck in the middle of it. The GetModuleFileName(hModule, pFileName, nSz) returns NULL if hModule refers to console app (and probably 16bit app too). There's absolutely no way around it as I need to get file path from the window handle.

Any suggestions?
dc2000 is offline   Reply With Quote
Old Jun 12th, 2005, 6:52 PM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4 Ancient Dragon is on a distinguished road
works ok for me (VC++ 6.0 compiler and XP). win32 api functions can't be called from 16-bit programs.

#include <windows.h>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	char buf[_MAX_PATH];
	if( GetModuleFileName(NULL,buf,sizeof(buf)) )
		cout << buf << endl;
	else
		cout << "GetModuleFileName() failed" << endl;
	cin.ignore();
	return 0;
}
Ancient Dragon is offline   Reply With Quote
Old Jun 12th, 2005, 8:09 PM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Why not look at argv[0]? If it is non-null, it is usually the name of your program.
grumpy is offline   Reply With Quote
Old Jun 13th, 2005, 2:38 AM   #4
dc2000
Newbie
 
Join Date: Jun 2005
Location: Portland, OR
Posts: 12
Rep Power: 0 dc2000 is on a distinguished road
Sorry guys I didn't put it clear. I need to run GetModuleFileName() for HMODULE in another process. Basically what happens, I have HWND that I receive from WindowFromPoint(), then I get HMODULE off of it, and the goal is to get module path. I run it from GUI app on Windows XP. It works fine with exception of console windows and 16bit apps.
dc2000 is offline   Reply With Quote
Old Jun 13th, 2005, 4:14 AM   #5
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by dc2000
Sorry guys I didn't put it clear. I need to run GetModuleFileName() for HMODULE in another process. Basically what happens, I have HWND that I receive from WindowFromPoint(), then I get HMODULE off of it, and the goal is to get module path. I run it from GUI app on Windows XP. It works fine with exception of console windows and 16bit apps.
With 16 bit apps, you're definitely out of luck. With console apps, you may be but I'm not 100% certain.

Under windows windows NT/2000/XP ....

16 bit apps run within the DOS emulator (an executable named NTVDM.EXE), and that does not provide a means of identifying the applications being run in the DOS virtual machine. At best, you will be able to get NTVDM.EXE as the module name.

My memory suggests console applications run within an environment set up by the command line processor (CMD.EXE), and that also does not provide a means of identifying individual applications running within it. I'm less certain on that, so you may wish to check further .......

Under windows 95/98/Me ..... the story may be different.
grumpy is offline   Reply With Quote
Old Jun 13th, 2005, 10:51 PM   #6
dc2000
Newbie
 
Join Date: Jun 2005
Location: Portland, OR
Posts: 12
Rep Power: 0 dc2000 is on a distinguished road
Thanks! Doesn't sound simple though
dc2000 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC