Solved

How to get the module handle of an ocx?

Posted on 2002-07-17
3
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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