Solved

need to implement DllCanUnloadNow() function

Posted on 2013-12-12
3
520 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 116
Safe conversion? 4 72
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 39
How to convert Structure to vector of byte and vice versa 5 24
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

860 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