当前位置: 首页>>代码示例>>C++>>正文


C++ GetModuleHandleEx函数代码示例

本文整理汇总了C++中GetModuleHandleEx函数的典型用法代码示例。如果您正苦于以下问题:C++ GetModuleHandleEx函数的具体用法?C++ GetModuleHandleEx怎么用?C++ GetModuleHandleEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetModuleHandleEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OpenProcess

int CSDShellExt::GetExtensionDirectory(wchar_t *path) {
    HMODULE moduleHandle = NULL;
    HANDLE processHandle =  NULL;

    processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, GetCurrentProcessId());

    if(processHandle == NULL) {
        //
        // failed to get process handle
        //
        return 0;
    }

    if(GetModuleHandleEx(0, L"SDShellNative.dll", &moduleHandle) == 0) {
        if(GetModuleHandleEx(0, L"SDShellNative32.dll", &moduleHandle) == 0) {
            //
            // try get for 64 bit version instead
            //
            if(GetModuleHandleEx(0, L"SDShellNative64.dll", &moduleHandle) == 0) {
                //
                // failed
                //
                CloseHandle(processHandle);
                return 0;
            }
        }
    }

    //
    // get the file path
    //
    if(GetModuleFileNameEx(processHandle, moduleHandle, path, MAX_PATH) == 0) {
        //
        // failed
        //
        CloseHandle(processHandle);
        return 0;
    }

    //
    // extract directory
    //
    int length = wcslen(path);

    for(int i = length - 1;i > 0;i--) {
        if(path[i] == '\\') {
            //
            // end the string here
            //
            path[i + 1] = 0;
            break;
        }
    }

    CloseHandle(processHandle);
    return 1;
}
开发者ID:datascicat,项目名称:SecureDelete,代码行数:57,代码来源:SDShellExt.cpp

示例2: strcat

void ofxPS3::StartSettingsDialog()
{
   HWND        hwnd;
   MSG         msg;
   WNDCLASS    wndclass;
   char        szAppName[64] = "PS3 Eye settings: ";
   strcat(szAppName,GUIDToString(guid).c_str());
   wndclass.style         = 0;
   wndclass.lpfnWndProc   = ofxPS3::WndProc;
   wndclass.cbClsExtra    = 0;
   wndclass.cbWndExtra    = 0;
   HMODULE hInstance;
   GetModuleHandleEx(0,NULL,&hInstance);
   wndclass.hInstance     = hInstance;
   wndclass.hIcon         = LoadIconA(hInstance, szAppName);
   wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
   //wndclass.lpszMenuName  = szAppName;
   //wndclass.lpszClassName = szAppName;
   RegisterClass(&wndclass);

   InitCommonControls(); 

   hwnd = CreateWindowA(szAppName,
      szAppName,
      DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
	  0, 0, 465, cameraPixelMode ? 410 : 110,
      NULL, NULL, hInstance, 0);
   SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)(this));
   while (GetMessage(&msg, NULL, 0, 0)) 
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
}
开发者ID:kitronyx,项目名称:ccvs,代码行数:35,代码来源:ofxPS3.cpp

示例3: WAI_PREFIX

WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
  HMODULE module;
  int length = -1;

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4054)
#endif
  if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)
  #if defined(_MSC_VER)
  _ReturnAddress()
  #else
  __builtin_extract_return_addr(__builtin_return_address(0))
  #endif
  , &module))
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
  {
    length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length);
  }

  return length;
}
开发者ID:RobertLeahy,项目名称:whereami,代码行数:27,代码来源:whereami.c

示例4: QueryRecycleBinThreadProc

DWORD WINAPI QueryRecycleBinThreadProc(void* pParam)
{
	// NOTE: Do not use CRT functions (since thread was created with CreateThread())!

	SHQUERYRBINFO rbi = {0};
	rbi.cbSize = sizeof(SHQUERYRBINFO);
	SHQueryRecycleBin(NULL, &rbi);
	g_BinCount = (double)rbi.i64NumItems;
	g_BinSize = (double)rbi.i64Size;

	EnterCriticalSection(&g_CriticalSection);
	HMODULE module = NULL;
	if (g_FreeInstanceInThread)
	{
		DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
		GetModuleHandleEx(flags, (LPCWSTR)DllMain, &module);
		g_FreeInstanceInThread = false;
	}

	g_Thread = false;
	LeaveCriticalSection(&g_CriticalSection);

	if (module)
	{
		// Decrement the ref count and possibly unload the module if this is
		// the last instance.
		FreeLibraryAndExitThread(module, 0);
	}

	return 0;
}
开发者ID:JamesAC,项目名称:rainmeter,代码行数:31,代码来源:RecycleManager.cpp

示例5: global_symbols_link

    static dynamic_link_handle global_symbols_link( const wchar_t* library, const dynamic_link_descriptor descriptors[], size_t required ) {
        ::tbb::internal::suppress_unused_warning( library );
        dynamic_link_handle library_handle;
#if _WIN32
        if ( GetModuleHandleEx( 0, library, &library_handle ) ) {
            if ( resolve_symbols( library_handle, descriptors, required ) )
                return library_handle;
            else
                FreeLibrary( library_handle );
        }
#else /* _WIN32 */
    #if !__TBB_DYNAMIC_LOAD_ENABLED /* only __TBB_WEAK_SYMBOLS_PRESENT is defined */
        if ( !dlopen ) return 0;
    #endif /* !__TBB_DYNAMIC_LOAD_ENABLED */
        library_handle = dlopen( NULL, RTLD_LAZY );
    #if !__ANDROID__
        // On Android dlopen( NULL ) returns NULL if it is called during dynamic module initialization.
        LIBRARY_ASSERT( library_handle, "The handle for the main program is NULL" );
    #endif
        // Check existence of the first symbol only, then use it to find the library and load all necessary symbols.
        pointer_to_handler handler;
        dynamic_link_descriptor desc;
        desc.name = descriptors[0].name;
        desc.handler = &handler;
        if ( resolve_symbols( library_handle, &desc, 1 ) )
            return pin_symbols( library_handle, desc, descriptors, required );
#endif /* _WIN32 */
        return 0;
    }
开发者ID:rpgfreak128,项目名称:LoLUpdater,代码行数:29,代码来源:dynamic_link.cpp

示例6: loadPathHack

void loadPathHack (char buf[256], void *addr)
{
  HMODULE h;
  size_t sz;
  DWORD k;
  BOOL brc;
  char libBuf[1024];

  buf[0] = '\0';
  brc = GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
                           GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                           (LPCTSTR)addr, &h);
  if (brc) {  /* OK: got a handle */
    k = GetModuleFileName (h, libBuf, sizeof(libBuf));
    if (k > 0) {                /* success */
      /* do some trimming later */
      sz = strlen(libBuf);
      if (sz <= 255) {
        memcpy (buf, libBuf, sz);
        buf[sz] = '\0';
      }
    }
  }

  return;
} /* loadPathHack */
开发者ID:lolow,项目名称:gdxtools,代码行数:26,代码来源:loadpathutil.c

示例7: Finalize

PLUGIN_EXPORT void Finalize(void* data)
{
	Measure* measure = (Measure*)data;

	std::unique_lock<std::recursive_mutex> lock(measure->mutex);

	if (measure->threadActive)
	{
		// Increment ref count of this module so that it will not be
		// unloaded prior to thread completion.
		DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS;
		HMODULE module;
		GetModuleHandleEx(flags, (LPCWSTR)DllMain, &module);

		if (measure->hProc != INVALID_HANDLE_VALUE &&
			!TerminateApp(measure->hProc, measure->dwPID, (measure->state == SW_HIDE)))
		{
			measure->value = 105.0f;
			RmLogF(measure->rm, LOG_ERROR, err_Terminate, measure->program.c_str());	// Could not terminate process (very rare!)
		}

		// Tell the thread to perform any cleanup
		measure->threadActive = false;
		return;
	}

	lock.unlock();
	delete measure;
}
开发者ID:NighthawkSLO,项目名称:rainmeter,代码行数:29,代码来源:PluginRunCommand.cpp

示例8: hookDXGI

/// @param hDXGI must be a valid module handle.
void hookDXGI(HMODULE hDXGI, bool preonly) {
	wchar_t modulename[MODULEFILEPATH_BUFLEN];
	GetModuleFileNameW(NULL, modulename, ARRAY_NUM_ELEMENTS(modulename));
	ods("DXGI: hookDXGI in App '%ls'", modulename);

	// Add a ref to ourselves; we do NOT want to get unloaded directly from this process.
	HMODULE hTempSelf = NULL;
	GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCTSTR>(&hookDXGI), &hTempSelf);

	bHooked = true;

	// Can we use the prepatch data?
	GetModuleFileNameW(hDXGI, modulename, ARRAY_NUM_ELEMENTS(modulename));
	if (_wcsicmp(dxgi->wcFileName, modulename) == 0) {
		// The module seems to match the one we prepared d3dd for.

		unsigned char *raw = (unsigned char *) hDXGI;
		HookPresentRaw((voidFunc)(raw + dxgi->offsetPresent));
		HookResizeRaw((voidFunc)(raw + dxgi->offsetResize));

	} else if (! preonly) {
		ods("DXGI: Interface changed, can't rawpatch. Current: %ls ; Previously: %ls", modulename, dxgi->wcFileName);
	} else {
		bHooked = false;
	}
}
开发者ID:MumbleTransifexBot,项目名称:mumble,代码行数:27,代码来源:dxgi.cpp

示例9: defined

bool Renderer::initializeCompiler()
{
#if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES)
    // Find a D3DCompiler module that had already been loaded based on a predefined list of versions.
    static TCHAR* d3dCompilerNames[] = ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES;

    for (size_t i = 0; i < ArraySize(d3dCompilerNames); ++i)
    {
        if (GetModuleHandleEx(0, d3dCompilerNames[i], &mD3dCompilerModule))
        {
            break;
        }
    }
#else
    // Load the version of the D3DCompiler DLL associated with the Direct3D version ANGLE was built with.
    mD3dCompilerModule = LoadLibrary(D3DCOMPILER_DLL);
#endif  // ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES

    if (!mD3dCompilerModule)
    {
        ERR("No D3D compiler module found - aborting!\n");
        return false;
    }

    mD3DCompileFunc = reinterpret_cast<pCompileFunc>(GetProcAddress(mD3dCompilerModule, "D3DCompile"));
    ASSERT(mD3DCompileFunc);

    return mD3DCompileFunc != NULL;
}
开发者ID:ConradIrwin,项目名称:gecko-dev,代码行数:29,代码来源:Renderer.cpp

示例10: MyLoadLibraryA

static HMODULE WINAPI
MyLoadLibraryA(LPCSTR lpLibFileName)
{
    if (VERBOSITY >= 2) {
        debugPrintf("%s(\"%s\")\n", __FUNCTION__, lpLibFileName);
    }

    if (VERBOSITY > 0) {
        const char *szBaseName = getBaseName(lpLibFileName);
        for (unsigned i = 0; i < numReplacements; ++i) {
            if (stricmp(szBaseName, replacements[i].szMatchModule) == 0) {
                debugPrintf("%s(\"%s\")\n", __FUNCTION__, lpLibFileName);
#ifdef __GNUC__
                void *caller = __builtin_return_address (0);

                HMODULE hModule = 0;
                BOOL bRet = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
                                              (LPCTSTR)caller,
                                              &hModule);
                assert(bRet);
                char szCaller[256];
                DWORD dwRet = GetModuleFileNameA(hModule, szCaller, sizeof szCaller);
                assert(dwRet);
                debugPrintf("  called from %s\n", szCaller);
#endif
                break;
            }
        }
    }

    return MyLoadLibrary(lpLibFileName);
}
开发者ID:hadrien-psydk,项目名称:apitrace,代码行数:32,代码来源:injectee.cpp

示例11: GetFnOffsetInModule

int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName) {

	HMODULE hModule = NULL;

	if (! GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (char *) fnptr, &hModule)) {
		ods((logPrefix + ": Failed to get module for " + fnName).c_str());
		return -1;
	}

	const bool bInit = refmodulepath[0] == '\0';
	if (bInit) {
		GetModuleFileNameW(hModule, refmodulepath, refmodulepathLen);
	} else {
		wchar_t modulename[MODULEFILEPATH_BUFLEN];
		GetModuleFileNameW(hModule, modulename, ARRAY_NUM_ELEMENTS(modulename));
		if (_wcsicmp(modulename, refmodulepath) != 0) {
			ods((logPrefix + ": " + fnName + " functions module path does not match previously found. Now: '%ls', Previously: '%ls'").c_str(), modulename, refmodulepath);
			return -2;
		}
	}

	unsigned char *fn = reinterpret_cast<unsigned char *>(fnptr);
	unsigned char *base = reinterpret_cast<unsigned char *>(hModule);
	unsigned long off = static_cast<unsigned long>(fn - base);

	// XXX: convert this function to use something other than int.
	// Issue mumble-voip/mumble#1924.
	if (off > static_cast<unsigned long>(std::numeric_limits<int>::max())) {
		ods("Internal overlay error: GetFnOffsetInModule() offset greater than return type can hold.");
		return -1;
	}

	return static_cast<int>(off);
}
开发者ID:CimpianAlin,项目名称:mumble,代码行数:34,代码来源:lib.cpp

示例12: GetModuleHandleEx

ds::ds()
{
    HMODULE hModule = NULL;
    BOOL bRc = GetModuleHandleEx(
                   GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
                   ( LPCSTR)this, &hModule );
    if ( bRc )
    {
        GetModuleFileName(hModule, g_szProjectName, MAX_PATH);
        FreeLibrary(hModule);
        DebugOut(
            "\n*******************Memory Check %s!\n\n",
            g_szProjectName );
    }
    else
    {
        OutputDebugString("\n*******************GetModuleHandleEx Failed!\n\n");
    }



    _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
    _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
    /*
    * Set the debug-heap flag to keep freed blocks in the
    * heap's linked list - This will allow us to catch any
    * inadvertent use of freed memory
    */
    //int tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
    //tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF;
    //_CrtSetDbgFlag(tmpDbgFlag);
}
开发者ID:fatrar,项目名称:yiqiulib,代码行数:32,代码来源:MemCheck.cpp

示例13: WinMain

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow )
{
	char    cBuff[MAX_PATH];
	DWORD   dwPID;
	HANDLE  hProcs;

	// get the calling exe path
	GetModuleFileName(NULL, cBuff, sizeof(cBuff));

	// get PID
	dwPID = GetProcessPathID(cBuff);
	if (!dwPID)
	{
		MessageBox(0, "Couldn't get PID :(", NULL, MB_ICONERROR);
		return -1;
	}
	// get procs.dll base
	hProcs = GetModuleHandleEx(dwPID, "procs.dll");
	if (!hProcs)
	{
		MessageBox(0, "GetModuleHandleEx failed :(", NULL, MB_ICONERROR);
		return -1;
	}

	// print result
	wsprintf(cBuff, "My PID: 0x%08lX\nProcs.dll base: 0x%08lX", dwPID, hProcs);
	MessageBox(0, cBuff, ":D", MB_ICONINFORMATION | MB_SYSTEMMODAL);

	return 0;
}
开发者ID:giantbranch,项目名称:MyLearningCode,代码行数:33,代码来源:USEPROCS.C

示例14: addLibrary

	bool addLibrary(char* libraryName,void* addressContained)
	{
		HMODULE module;

		if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,(LPCSTR)addressContained,&module))
		{
			HANDLE process =  GetCurrentProcess();
			_MODULEINFO moduleInfo;

			if(GetModuleInformation(process,module,&moduleInfo,sizeof moduleInfo))
			{
				CloseHandle(process);

				LibraryInfo* libraryInfo = new LibraryInfo;

				libraryInfo->baseAddress = (void*) moduleInfo.lpBaseOfDll;
				libraryInfo->length = moduleInfo.SizeOfImage;
				libraryInfo->handle = module;

				LibraryNameToLibraryInfo->insert(libraryName,libraryInfo);

				return true;
			}
		}

		return false;
	}
开发者ID:ShootingKing-AM,项目名称:OrpheuPack2.3,代码行数:27,代码来源:librariesManager.cpp

示例15: _zbar_processor_open

int _zbar_processor_open (zbar_processor_t *proc,
                          char *title,
                          unsigned width,
                          unsigned height)
{
    HMODULE hmod = NULL;
    if(!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
                          GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                          (void*)_zbar_processor_open, (HINSTANCE*)&hmod))
        return(err_capture(proc, SEV_ERROR, ZBAR_ERR_WINAPI, __func__,
                           "failed to obtain module handle"));

    ATOM wca = win_register_class(hmod);
    if(!wca)
        return(err_capture(proc, SEV_ERROR, ZBAR_ERR_WINAPI, __func__,
                           "failed to register window class"));

    RECT r = { 0, 0, width, height };
    AdjustWindowRectEx(&r, WIN_STYLE, 0, EXT_STYLE);
    proc->display = CreateWindowEx(EXT_STYLE, (LPCTSTR)(long)wca,
                                   "ZBar", WIN_STYLE,
                                   CW_USEDEFAULT, CW_USEDEFAULT,
                                   r.right - r.left, r.bottom - r.top,
                                   NULL, NULL, hmod, proc);

    if(!proc->display)
        return(err_capture(proc, SEV_ERROR, ZBAR_ERR_WINAPI, __func__,
                           "failed to open window"));
    return(0);
}
开发者ID:liumeng1201,项目名称:qrcode_scan,代码行数:30,代码来源:win.c


注:本文中的GetModuleHandleEx函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。