w32 app that recognizes it´s own name

Miscellaneous Forums/Win32 Discussion/w32 app that recognizes it´s own name

Hello folks,

I need your advice in a project that I´m working on with BlitzPlus.
Is it possible, even with the support of C/C++/etc., to write a program that recognizes it´s own name, stores it in a string var 'xyz$', starts another app with a similar name (same name, actually, plus prefix "main_", the actual BlitzPlus app) and passes the string var 'xyz$' as a parameter on the command line?

The programm I need works as you might guess as a kind of wrapper for the main programm. It is necessary because the name of the B+ app is not known before it´s actual runtime, it is copied and renamed several times (renamed partly by random, partly by user input) - but when the app runs, it´s name is needed to be known.

Regards,
4pac


...the name of the B+ app is not known before it´s actual runtime, it is copied and randomly renamed several times...



that sounds somewhat suspecious... :/

what do you suspect? it´s a screensaver project... maybe you want to check out my website, I´m not working on any suspicious stuff. The question I asked is the last problem that keeps me from finishing my latest project, a screensaver generator.

At the present I can only have 1 screensaver at a time in the system dir, because the ini is allways named setting.ini. I want to name it after the executable (which is itself re-named by user input befor copying it into the user´s system directory), and the executable has to be able to recongnize it´s own name to find and read the same-named ini file. But please don´t think about others ways of organizing the file structure, the implementations are to complicated. I´d just be happy if you refer to my original question. Thanks a lot...

4pac

Try this...

Global GetModuleFileName (module_handle, fname:Byte Ptr, fname_size) "win32"

kernel32 = LoadLibraryA ("kernel32.dll")
If kernel32
	GetModuleFileName = GetProcAddress (kernel32, "GetModuleFileNameA")
EndIf

Function Exe$ ()
	MAX_PATH = 260
	Local filename:Byte [MAX_PATH]
	GetModuleFileName (Null, filename, MAX_PATH)
	Return String.FromCString (filename)
End Function

Notify Exe$ ()


EDIT: Oops, BlitzMax code... see next post!

Oops, meant to be for BlitzPlus (needs addition to userlibs -- see below if unsure)...

Function Exe$ ()
	MAX_PATH = 260
	name = CreateBank (MAX_PATH)
	length = GetModuleFileName (0, name, MAX_PATH)
	If length
		For byte = 0 To length - 1
			executable$ = executable$ + Chr (PeekByte (name, byte))
		Next
	EndIf
	FreeBank name
	Return executable$
End Function

Notify Exe$ ()

If the userlibs file ... BlitzPlus\userlibs\kernel32.decls already exists, just add this line to it (assuming GetModuleFileName isn't listed)...
GetModuleFileName% (module_handle, fname*, fname_size) : "GetModuleFileNameA"

If ... BlitzPlus\userlibs\kernel32.decls doesn't already exist, create it using Notepad or similar (save a plain text file with that name), and add this:
; .lib "kernel32.decls"
; GetModuleFileName% (module_handle, fname*, fname_size) : "GetModuleFileNameA"