GetModuleHandle 和 AfxGetInstanceHandle

18 篇文章 1 订阅
11 篇文章 0 订阅

获取exe的句柄,使用AfxGetInstanceHandle, 要获取exe调用的 dll 句柄,用 GetModuleHandle(dllName);

 

1.GetModuleHandle(LPCTSTR lpModuleName)
   
  If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).
  如果参数为空,那么获取的就是调用这个DLL 的exe的 句柄,也即application(执行体)句柄,而不是DLL的句柄

  如果要获得当前DLL的句柄,要传入DLL的名称。

2.AfxGetInstanceHandle()
  
   An HINSTANCE to the current instance of the application. If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL is returned.
   返回的是一个application的句柄,但是如果这个函数是从一个MFC的USRDLL版本DLL的内部被调用,那么返回的就是这个DLL的句柄

3.CWinApp->m_hInstance
   
  The m_hInstance data member is a handle to the current instance of the application running under Windows. This is returned by the global function AfxGetInstanceHandle. m_hInstance is a public variable of type HINSTANCE.
  因为它是从 AfxGetInstanceHandle()返回来获得的,所以跟AfxGetInstanceHandle()的返回值一样。

在windows核心编程中对GetModuleHandle的介绍:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值