Solved

How to get the module handle of an ocx?

Posted on 2002-07-17
3
454 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 110
wait notify demo infinite loop 3 135
Line meaning 9 89
noX challenge 17 134
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

713 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