Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 911951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:17:50+00:00 2026-05-15T17:17:50+00:00

I am using MinGW which does not have full functionality. eg. It has no

  • 0

I am using MinGW which does not have full functionality. eg. It has no wchar_t stream support.
I’ve managed to get around that by writing a mini-set of manipulators (the wcusT() in the code below).. but I find I’m getting stymied again with GetModuleFileNameEx.
I have not been able to natively run GetModuleFileNameEx()
This function is defined in <psapi.h>, but there seems to be nothing for it to link to. That is my no.1 question: Can/does/is MinGW able to run GetModuleFileNameEx? What do I need to do? Am I missing something simple?
As a workaround, I’ve tried to run it indirectly via a call to its dll (psapi.dll) which is in the Windows system32 folder… but something is wrong.
I’ve got another no-go situation. I’d appreciate any comments on the code below .. thanks

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{ /// typedef and load a dll function
  /// ===============================
  typedef DWORD (__stdcall *foo)(HANDLE, HMODULE, LPTSTR, DWORD);
  LPTSTR  ptcPSAPI_DLL = _T("C:\\WINDOWS\\system32\\psapi.dll");
  HMODULE   hPSAPI_DLL = LoadLibrary(ptcPSAPI_DLL);
  if( !hPSAPI_DLL ) 
  { std::cout<<"ERROR: Failed to load "<<wcusT(ptcPSAPI_DLL)<<std::endl;
    return 1;
  }
  foo GetModFnEx=(foo)GetProcAddress(hPSAPI_DLL,
                  #ifdef  UNICODE
                         "GetModuleFileNameExW");
                  #else
                         "GetModuleFileNameExA");
                  #endif

  /// call the dll library function
  /// =============================
  HWND   hWndNPP = FindWindow(_T("Notepad++"),NULL); // the window calass name
  TCHAR  ytcMFqFn[FILENAME_MAX]; // the buffer for the file name
  DWORD  dwBytes = (GetModFnEx)( hWndNPP, NULL, ytcMFqFn, sizeof(ytcMFqFn) );  
  DWORD  dwError = GetLastError();

  std::cout<<wcusT(_T("hWndNPP  "))<<"="<<hWndNPP        <<"="<<std::endl;
  std::cout<<wcusT(_T("ytcMFqFn "))<<"="<<wcusT(ytcMFqFn)<<"="<<std::endl;
  std::cout<<wcusT(_T("dwBytes  "))<<"="<<dwBytes        <<"="<<std::endl;
  std::cout<<wcusT(_T("dwError  "))<<"="<<dwBytes        <<"="<<std::endl;
  return 0;

  // Output ===============
  // SBCS 
  //   hWndNPP  =0x320606=
  //   ytcMFqFn ==
  //   dwBytes  =0=
  //   dwError  =0=
  // UNICODE
  //   h W n d N P P     =0x320606=
  //   y t c M F q F n   =(☻æ|♀ =
  //   d w B y t e s     =0=
  //   d w E r r o r     =0=
  //  ======================
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:17:50+00:00Added an answer on May 15, 2026 at 5:17 pm

    Your calling GetModuleFileNameEx incorrectly

    HWND   hWndNPP = FindWindow(_T("Notepad++"),NULL); 
    DWORD  dwBytes = (GetModFnEx)( hWndNPP // this is ment to be a process handle, not a HWND
      , NULL, ytcMFqFn, sizeof(ytcMFqFn) );
    

    MSDN doc on GetModuleFileNameEx

    you might try getting a process handle using one of the following

    ::GetWindowThreadProcessId(hWnd, &dwProcessID);
    HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessID);
    
    // also in PSAPI - EnumProcesses will return an array of app process ids
    (BOOL(WINAPI *)(DWORD *,DWORD, DWORD *)) GetProcAddress( psapi, "EnumProcesses" );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.