Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get the module handle of an ocx?

Posted on 2002-07-17
3
Medium Priority
?
477 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 150 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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