Solved

How to get the module handle of an ocx?

Posted on 2002-07-17
3
443 Views
Last Modified: 2013-11-20
I need to be able to get the module handle of an ocx. I won't know where the ocx is installed so I need a programmatic way of fetching it.

I assume GetModuleFilename/GetModuleHandle are not available for this since they return the handle to the application using the ocx.

0
Comment
Question by:rascal
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 7160919
Add a "DllMain()" to the OCX if it isn't already present and use - yes, you are reading right - "GetModuleFileName()". From the VC++ docs:

The DllMain function is an optional method of entry into a dynamic-link library (DLL). If the function is used, it is called by the system when processes and threads are initialized and terminated, or upon calls to the LoadLibrary and FreeLibrary functions.

DllMain is a placeholder for the library-defined function name. Earlier versions of the SDK documentation used DllEntryPoint as the entry-point function name. You must specify the actual name you use when you build your DLL. For more information, see the documentation included with your development tools.

BOOL WINAPI DllMain(
  HINSTANCE hinstDLL,  // handle to DLL module
  DWORD fdwReason,     // reason for calling function
  LPVOID lpvReserved   // reserved
);
 
Parameters
hinstDLL
A handle to the DLL. The value is the base address of the DLL. The HINSTANCE of a DLL is the same as the HMODULE of the DLL, so hinstDLL can be used in subsequent calls to the GetModuleFileName function and other functions that require a module handle.


0
 
LVL 1

Author Comment

by:rascal
ID: 7160926
Thanks, but in the meantime I found another solution:

AfxGetInstanceHandle() used in conjunction with specifying _USRDLL (which the ocx wizard set for me anyway) did the trick.

Thanks anyway!
0
 
LVL 1

Author Comment

by:rascal
ID: 7160927
Thanks, but in the meantime I found another solution:

AfxGetInstanceHandle() used in conjunction with specifying _USRDLL (which the ocx wizard set for me anyway) did the trick.

Thanks anyway!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now