Always private
DuckDuckGo never tracks your searches.
Learn More
You can hide this reminder in Search Settings
All regions
Argentina
Australia
Austria
Belgium (fr)
Belgium (nl)
Brazil
Bulgaria
Canada (en)
Canada (fr)
Catalonia
Chile
China
Colombia
Croatia
Czech Republic
Denmark
Estonia
Finland
France
Germany
Greece
Hong Kong
Hungary
Iceland
India (en)
Indonesia (en)
Ireland
Israel (en)
Italy
Japan
Korea
Latvia
Lithuania
Malaysia (en)
Mexico
Netherlands
New Zealand
Norway
Pakistan (en)
Peru
Philippines (en)
Poland
Portugal
Romania
Russia
Saudi Arabia
Singapore
Slovakia
Slovenia
South Africa
Spain (ca)
Spain (es)
Sweden
Switzerland (de)
Switzerland (fr)
Taiwan
Thailand (en)
Turkey
Ukraine
United Kingdom
US (English)
US (Spanish)
Vietnam (en)
Safe search: moderate
Strict
Moderate
Off
Any time
Any time
Past day
Past week
Past month
Past year
  1. learn.microsoft.com

    Feb 8, 2023The libloaderapi.h header defines GetModuleFileName as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors.
  2. stackoverflow.com

    You are misusing GetModuleFileName(). You are not passing an allocated buffer to GetModuleFileName(), so it has nowhere to store its output. A string's c_str() method never returns a NULL pointer, so if the string is empty, c_str() returns a pointer to a null character that is stored in static memory.
  3. learn.microsoft.com

    To retrieve the name of a module in the current process, use the GetModuleFileName function. This is more efficient and more reliable than calling GetModuleFileNameEx with a handle to the current process. To retrieve the name of the main executable module for a remote process, ...
  4. learn.microsoft.com

    WINAPI DWORD GetModuleFileName( HMODULE hModule, LPWSTR lpFilename, DWORD nSize); Parameters. hModule [in] Handle to the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process.
  5. winapi.freetechsecrets.com

    GetModuleFileName The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.. Windows 95: The GetModuleFilename function will return long filenames when an application's version number is greater than or equal to 4.00 and the long filename is available. Otherwise, it returns only 8.3 format filenames.
  6. embeddedguruji.blogspot.com

    GetModuleFileName function is used to give the fully qualified path of the module passed. Syntax: DWORD WINAPI GetModuleFileName( _In_opt_ HMODULE hModule, _Out_ LPTSTR lpFilename, _In_ DWORD nSize ); Parameters: hModule: Handle to the loaded module. If you pass NULL as the first argument , it gives us the path of the executable file of the ...
  7. hModule [in] Handle to the module whose file name is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file containing the current process. lpFilename [out] Pointer to a buffer that receives the path and file name of the specified module. nSize [in] Specifies the length, in TCHARs, of the lpFilename buffer.
  8. gist.github.com

    GetModuleFileName (WinAPI) equivalent implementation for OSX Raw. GetModuleFileName.cpp This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ...
  9. Can’t find what you’re looking for?

    Help us improve DuckDuckGo searches with your feedback

  1. You are misusing GetModuleFileName().

    You are not passing an allocated buffer to GetModuleFileName(), so it has nowhere to store its output. A string's c_str() method never returns a NULL pointer, so if the string is empty, c_str() returns a pointer to a null character that is stored in static memory. You are telling GetModuleFileName() that you have allocated memory for the buffer you give it, but you really haven't, so when GetModuleFileName() tries to write to your non-allocated buffer, it will either trash memory, or outright just crash.

    Use something more like this instead:

    this->LogMessage(_D("Iniciando serviço"), EVENTLOG_INFORMATION_TYPE, 0, 0);
    
    WCHAR szBuffer[MAX_PATH];
    DWORD tamanho = GetModuleFileNameW(NULL, szBuffer, MAX_PATH);
    
    if( tamanho == 0 ){ // retornou nome !
    {
        this->LogMessage(_D("Impossível determinar pasta do  executável"), EVENTLOG_ERROR_TYPE, 0, 0);
        Started = false;
        return;
    }
    
    String exefile(szBuffer, tamanho);
    
    String sIniFile = ChangeFileExt(exefile, _D(".ini"));
    if (!FileExists(sIniFile))
    {
        this->LogMessage(_D("Arquivo de inicialização não encontrado"), EVENTLOG_ERROR_TYPE, 0, 0);
        Started = false;
        return;
    }
    
    this->LogMessage(sIniFile, EVENTLOG_INFORMATION_TYPE, 0, 0);
    
    /*
    // Debug
    Started = true;
    return;
    */

    Or, you can do this:

    this->LogMessage(_D("Iniciando serviço"), EVENTLOG_INFORMATION_TYPE, 0, 0);
    
    UnicodeString exefile;
    exefile.SetLength(MAX_PATH);
    
    DWORD tamanho = GetModuleFileNameW(NULL, &exefile[1], MAX_PATH);
    
    if( tamanho == 0 ){ // retornou nome !
    {
        this->LogMessage(_D("Impossível determinar pasta do  executável"), EVENTLOG_ERROR_TYPE, 0, 0);
        Started = false;
        return;
    }
    
    exefile.SetLength(tamanho);
    
    String sIniFile = ChangeFileExt(exefile, _D(".ini"));
    if (!FileExists(sIniFile))
    {
        this->LogMessage(_D("Arquivo de inicialização não encontrado"), EVENTLOG_ERROR_TYPE, 0, 0);
        Started = false;
        return;
    }
    
    this->LogMessage(sIniFile, EVENTLOG_INFORMATION_TYPE, 0, 0);
    
    /*
    // Debug
    Started = true;
    return;
    */

    That being said, you don't actually need to call GetModuleFileName() directly at all. You can use the RTL's ParamStr() 1 function instead. When its Index parameter is 0, it returns the path and filename of the calling process (ie, it calls GetModuleFileName() internally for you), eg:

    this->LogMessage(_D("Iniciando serviço"), EVENTLOG_INFORMATION_TYPE, 0, 0);
    
    String exefile = ParamStr(0);
    
    String sIniFile = ChangeFileExt(exefile, _D(".ini"));
    if (!FileExists(sIniFile))
    {
        this->LogMessage(_D("Arquivo de inicialização não encontrado"), EVENTLOG_ERROR_TYPE, 0, 0);
        Started = false;
        return;
    }
    
    this->LogMessage(sIniFile, EVENTLOG_INFORMATION_TYPE, 0, 0);
    
    /*
    // Debug
    Started = true;
    return;
    */

    1: In a VCL Forms Application, the Application->ExeName property simply returns ParamStr(0).

    --Remy Lebeau

    Was this helpful?
Custom date rangeX