Solved

How to get the module handle of an ocx?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 49
EvenOdd challenge 10 107
Path of Workbook 3 76
Message not shown 5 49
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

785 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