Solved

need to implement DllCanUnloadNow() function

Posted on 2013-12-12
3
502 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
ID: 39715820
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Non-recursive backtracking, using a stack 1 103
PHP question(s) about order of output 9 57
Add values of each row in an array 3 50
Issues with C++ Class 19 81
This article will show, step by step, how to integrate R code into a R Sweave document
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 explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 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

26 Experts available now in Live!

Get 1:1 Help Now