Solved

need to implement DllCanUnloadNow() function

Posted on 2013-12-12
3
490 Views
Last Modified: 2015-05-17
Hi,

I need to define the DllCanUnloadNow() function in one of my .ocx component(OLE based COM DLL).  
The COM DLLs which are having ATL support are also having CComModule global object, which can be used to get the lock count. For this particular case it's easy to implement the DllCanUnloadNow() function.

In my .ocx component, I do not have the ATL support. For this I am looking for some alternate of CComModule to implement the DllCanUnloadNow() function.

So, my question is to how to implement the DllCanUnloadNow() function if we do not have the CComModule object?

If we see the MSDN documentation for DllCanUnloadNlow(), it says-
"OLE does not provide this function. DLLs that support the OLE Component Object Model (COM) should implement and export DllCanUnloadNow."

Any ideas would be highly appreciable.
0
Comment
Question by:davinder101
3 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
Comment Utility
Just create a exported function with this signature:
HRESULT __stdcall DllCanUnloadNow(void);

Open in new window

Then implement the function, returning S_OK or S_FALSE depending on whether the dll can be unloaded or not.
It just all depends on your project coding style. If you use __declspec syntax then the function should be exported like your other functions, like this:
#ifdef MY_OCX_EXPORTS
#define MY_OCX_API __declspec(dllexport)
#else
#define MY_OCX_API __declspec(dllimport)
#endif
MY_OCX_API HRESULT __stdcall DllCanUnloadNow(void);

Open in new window

If you use a def file, then just use in the 'h' file this syntax
HRESULT __stdcall DllCanUnloadNow(void);

Open in new window

and add DllCanUnloadNow to the EXPORTS section of the file:
EXPORTS
    ; Explicit exports can go here
    DllCanUnloadNow

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 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

14 Experts available now in Live!

Get 1:1 Help Now