本文介绍了反复调用GetModuleHandle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一些旧代码,并遇到了以下内容

I''m wading through some legacy code and came across the following

HANDLE	hDll;

for (;;) {
    hDll = GetModuleHandle("xxx.dll"); // this is in xxx.dll''s source
    if (NULL != hDll) {
         break;
    }
}



我真的看不出这样做的意义,而且MSDN没有对重复调用一事无成.它要么成功并且仅循环一次,要么失败并永远循环.

有什么需要的情况吗?

在此先感谢



I really don''t see the point of doing this, and MSDN says nothing about calling it repeatedly. Either it succeeds and loops only once, or fails and loops forever.

Is there any scenario where it is required?

Thanks in advance

推荐答案



#include<windows.h>
#include<stdio.h>
#include<string.h>

int main(void)
{
	HMODULE module_handle = 0;
	while((module_handle = GetModuleHandle(TEXT("library.dll"))) == 0)
		printf("The specified module could not be found.\n");
	printf("Module handle = %x\n", module_handle);
	return 0;
}


这篇关于反复调用GetModuleHandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:26