diff --git a/cpp/SampleCommands/SampleFunctions.cpp b/cpp/SampleCommands/SampleFunctions.cpp index d0447b0b..3355fb7f 100644 --- a/cpp/SampleCommands/SampleFunctions.cpp +++ b/cpp/SampleCommands/SampleFunctions.cpp @@ -412,6 +412,20 @@ bool IsRhinoReparented() return hParent != hDesktop; } +/// +/// Returns module handle where "this" function is running in: EXE or DLL. +/// +HMODULE FancyGetModuleHandle() +{ + HMODULE hModule = NULL; + ::GetModuleHandleEx( + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCTSTR)FancyGetModuleHandle, + &hModule + ); + return hModule; +} + /// /// Begin a CRhinoDoc undo record. diff --git a/cpp/SampleCommands/SampleFunctions.h b/cpp/SampleCommands/SampleFunctions.h index d8fe4602..8ddd47c8 100644 --- a/cpp/SampleCommands/SampleFunctions.h +++ b/cpp/SampleCommands/SampleFunctions.h @@ -163,6 +163,11 @@ bool RhinoHasFocus(); /// bool IsRhinoReparented(); +/// +/// Returns module handle where "this" function is running in: EXE or DLL. +/// +HMODULE FancyGetModuleHandle(); + /// /// CRhinoDoc::BeginUndoRecord and CRhinoDoc::EndUndoRecord helper.