Note that there are some explanatory texts on larger screens.

plurals
  1. POcalling GetModuleFileNameEx via psapi.dll is not working, but why?
    text
    copied!<p>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 <code>&lt;psapi.h&gt;</code>, 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</p> <pre><code>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&lt;&lt;"ERROR: Failed to load "&lt;&lt;wcusT(ptcPSAPI_DLL)&lt;&lt;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&lt;&lt;wcusT(_T("hWndNPP "))&lt;&lt;"="&lt;&lt;hWndNPP &lt;&lt;"="&lt;&lt;std::endl; std::cout&lt;&lt;wcusT(_T("ytcMFqFn "))&lt;&lt;"="&lt;&lt;wcusT(ytcMFqFn)&lt;&lt;"="&lt;&lt;std::endl; std::cout&lt;&lt;wcusT(_T("dwBytes "))&lt;&lt;"="&lt;&lt;dwBytes &lt;&lt;"="&lt;&lt;std::endl; std::cout&lt;&lt;wcusT(_T("dwError "))&lt;&lt;"="&lt;&lt;dwBytes &lt;&lt;"="&lt;&lt;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= // ====================== </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload