Click here to Skip to main content
15,921,113 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionVC++ Substitute for SetIcon?? Pin
Programm3r8-Oct-06 21:54
Programm3r8-Oct-06 21:54 
AnswerRe: VC++ Substitute for SetIcon?? Pin
_AnsHUMAN_ 8-Oct-06 22:11
_AnsHUMAN_ 8-Oct-06 22:11 
AnswerRe: VC++ Substitute for SetIcon?? Pin
PJ Arends8-Oct-06 22:14
professionalPJ Arends8-Oct-06 22:14 
AnswerRe: VC++ Substitute for SetIcon?? Pin
David Crow9-Oct-06 4:28
David Crow9-Oct-06 4:28 
Question:-: HInstance Question :-: Pin
Programm3r8-Oct-06 21:13
Programm3r8-Oct-06 21:13 
AnswerRe: :-: HInstance Question :-: Pin
prasad_som8-Oct-06 21:20
prasad_som8-Oct-06 21:20 
QuestionRe: :-: HInstance Question :-: Pin
Programm3r8-Oct-06 21:28
Programm3r8-Oct-06 21:28 
AnswerRe: :-: HInstance Question :-: Pin
Stephen Hewitt8-Oct-06 21:39
Stephen Hewitt8-Oct-06 21:39 
Here another way. The function GetHandleToModuleWhichContainsThisFunction returns the HMODULE of the module that contains it. It's better to use the value passed in WinMain but this technique come in handy from time to time.

#include <iostream>
#include <windows.h>
 
namespace
{
 
HMODULE GetHandleToModuleWhichContainsThisFunction()
{
    HMODULE hMod = NULL;
 
    const void *pFunc = &GetHandleToModuleWhichContainsThisFunction;
    MEMORY_BASIC_INFORMATION mbi;
    if ( VirtualQuery(pFunc, &mbi, sizeof(mbi)) == sizeof(mbi) )
    {
       hMod = reinterpret_cast<HMODULE>(mbi.AllocationBase);
    }
 	
    return hMod;	
}
 
HMODULE GetHandleToInstanceWhichContainsThisFunction()
{
    return reinterpret_cast<HINSTANCE>(GetHandleToModuleWhichContainsThisFunction());
}
 
} // namespace
 
int main()
{
    HMODULE hMod = GetHandleToModuleWhichContainsThisFunction();
 
    using namespace std;
    char Path[MAX_PATH];
    GetModuleFileName(hMod, Path, sizeof(Path)/sizeof(Path[0]));
    cout << Path << endl;
 
    return 0;
}


Steve

GeneralRe: :-: HInstance Question :-: Pin
Programm3r8-Oct-06 21:42
Programm3r8-Oct-06 21:42 
QuestionWhy GetWindowRect function gives wrong values for context menus? Pin
Hemant kulkarni8-Oct-06 20:37
Hemant kulkarni8-Oct-06 20:37 
AnswerRe: Why GetWindowRect function gives wrong values for context menus? Pin
Stephen Hewitt8-Oct-06 21:06
Stephen Hewitt8-Oct-06 21:06 
GeneralRe: Why GetWindowRect function gives wrong values for context menus? Pin
Hemant kulkarni8-Oct-06 21:39
Hemant kulkarni8-Oct-06 21:39 
GeneralRe: Why GetWindowRect function gives wrong values for context menus? Pin
Stephen Hewitt8-Oct-06 21:50
Stephen Hewitt8-Oct-06 21:50 
GeneralRe: Why GetWindowRect function gives wrong values for context menus? Pin
Hemant kulkarni8-Oct-06 23:45
Hemant kulkarni8-Oct-06 23:45 
GeneralRe: Why GetWindowRect function gives wrong values for context menus? Pin
Stephen Hewitt9-Oct-06 0:16
Stephen Hewitt9-Oct-06 0:16 
Questionsmart technology access from C# Pin
ravi khadka8-Oct-06 19:33
ravi khadka8-Oct-06 19:33 
NewsRe: smart technology access from C# Pin
Rajesh R Subramanian8-Oct-06 20:12
professionalRajesh R Subramanian8-Oct-06 20:12 
AnswerRe: smart technology access from C# Pin
Hamid_RT8-Oct-06 21:08
Hamid_RT8-Oct-06 21:08 
QuestionCOM ATL EXE program Pin
Sakthiu8-Oct-06 19:11
Sakthiu8-Oct-06 19:11 
AnswerRe: COM ATL EXE program Pin
Rinu_Raj8-Oct-06 19:28
Rinu_Raj8-Oct-06 19:28 
AnswerRe: COM ATL EXE program Pin
Hamid_RT8-Oct-06 21:09
Hamid_RT8-Oct-06 21:09 
QuestionVirtual memory usage of a process in c++ Pin
Manish_Home8-Oct-06 19:02
Manish_Home8-Oct-06 19:02 
AnswerRe: Virtual memory usage of a process in c++ Pin
John M. Drescher8-Oct-06 19:10
John M. Drescher8-Oct-06 19:10 
GeneralRe: Virtual memory usage of a process in c++ Pin
Manish_Home8-Oct-06 19:28
Manish_Home8-Oct-06 19:28 
GeneralRe: Virtual memory usage of a process in c++ Pin
John M. Drescher9-Oct-06 2:15
John M. Drescher9-Oct-06 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.