Solved

need to implement DllCanUnloadNow() function

Posted on 2013-12-12
3
540 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
[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
3 Comments
 
LVL 25

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

729 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