473,795 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mixed mode ActiveX DLL

Hi ,

I am trying to host .Net UserControls in a MFC Application. The MFC
Application is an ActiveX DLL. I inserted required managed code inside the
MFC application, making it a mixed mode DLL.
I am following the KB article for mixed mode DLL's
http://support.microsoft.com/?id=814472
I linked the DLL with /noentry option. Also I added and exported the
DllEnsureInit and DllForceTerm methods in my DLL which call
__crt_dll_initi alize() and __crt_dll_termi nate() respectively. So far so good.

Now in the consumer application, this ActiveX control is created dynamically
by the COleControlSite ::CreateControl method. I understand that I would need
to invoke my init/term DLL functions manually after loading the the mixed
mode DLL.
How do I go about invoking these functions here ? The KB article
demonstrates use of GetModuleHandle and GetProcAddress which I believe may
not be usefule

Is this feasible ? Kindly advise.
Any inputs would be highly appreciated.
Thanks in advance,
Niranjan
Aug 15 '06 #1
5 3192
The intention of the delayed CRT initialization is to avoid a deadlock,
which can happen if managed code is executed during DLLMain. After DLLMain
is called, your client will likely call DllGetClassObje ct to instantiate the
COM object. Unless some other code is called before DllGetClassObje ct, I
would initialize the CRT in your DllGetClassObje ct implementation.

Marcus

"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:5C******** *************** ***********@mic rosoft.com...
Hi ,

I am trying to host .Net UserControls in a MFC Application. The MFC
Application is an ActiveX DLL. I inserted required managed code inside
the
MFC application, making it a mixed mode DLL.
I am following the KB article for mixed mode DLL's
http://support.microsoft.com/?id=814472
I linked the DLL with /noentry option. Also I added and exported the
DllEnsureInit and DllForceTerm methods in my DLL which call
__crt_dll_initi alize() and __crt_dll_termi nate() respectively. So far so
good.

Now in the consumer application, this ActiveX control is created
dynamically
by the COleControlSite ::CreateControl method. I understand that I would
need
to invoke my init/term DLL functions manually after loading the the mixed
mode DLL.
How do I go about invoking these functions here ? The KB article
demonstrates use of GetModuleHandle and GetProcAddress which I believe may
not be usefule

Is this feasible ? Kindly advise.
Any inputs would be highly appreciated.
Thanks in advance,
Niranjan


Aug 17 '06 #2
Hi Marcus,
Thanks for your reply.

I tried to investigate the current scenario without the CRT initialization
code in place. The client is calling the DllGetClassObje ct in library file
oleexp.cpp. I do not have my implementation of DllGetClassObje ct. If I try
to implement my DllGetClassObje ct in the DLL code, the linker gives error
saying DllGetClassObje ct is already linked from oleexp.cpp.

What would I need to do to provide and use my implementation of
DllGetClassObje ct ?

The call to DllGetClassObje ct is currently failing with
CLASS_E_CLASSNO TAVAILABLE (ClassFactory cannot supply
requested class ), which I would assume is because of lack of CRT
initialization.

Thanks,
Niranjan

"Marcus Heege" wrote:
The intention of the delayed CRT initialization is to avoid a deadlock,
which can happen if managed code is executed during DLLMain. After DLLMain
is called, your client will likely call DllGetClassObje ct to instantiate the
COM object. Unless some other code is called before DllGetClassObje ct, I
would initialize the CRT in your DllGetClassObje ct implementation.

Marcus

"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:5C******** *************** ***********@mic rosoft.com...
Hi ,

I am trying to host .Net UserControls in a MFC Application. The MFC
Application is an ActiveX DLL. I inserted required managed code inside
the
MFC application, making it a mixed mode DLL.
I am following the KB article for mixed mode DLL's
http://support.microsoft.com/?id=814472
I linked the DLL with /noentry option. Also I added and exported the
DllEnsureInit and DllForceTerm methods in my DLL which call
__crt_dll_initi alize() and __crt_dll_termi nate() respectively. So far so
good.

Now in the consumer application, this ActiveX control is created
dynamically
by the COleControlSite ::CreateControl method. I understand that I would
need
to invoke my init/term DLL functions manually after loading the the mixed
mode DLL.
How do I go about invoking these functions here ? The KB article
demonstrates use of GetModuleHandle and GetProcAddress which I believe may
not be usefule

Is this feasible ? Kindly advise.
Any inputs would be highly appreciated.
Thanks in advance,
Niranjan


Aug 18 '06 #3
I my answer, I assumed that you used ATL instead of MFC. In this case, it
would have been easy to overwrite DllGetClassObje ct.With MFC, the story is
more difficult. I currently don't have VS2003 installed on my machine.
Therefore, I can't easily try it before I suggest something. But you may try
the following:

Modify the .def file so that

EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObje ct = MyDllGetClassOb ject PRIVATE
DllRegisterServ er PRIVATE
DllUnregisterSe rver PRIVATE

Implement MyDllGetClassOb ject so that you initialize the CRT if this has not
happened before. Once you ensured that the CRT is initialized, call
DllGetClassObje ct.

Please let us know if this works

Marcus
"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:3E******** *************** ***********@mic rosoft.com...
Hi Marcus,
Thanks for your reply.

I tried to investigate the current scenario without the CRT initialization
code in place. The client is calling the DllGetClassObje ct in library file
oleexp.cpp. I do not have my implementation of DllGetClassObje ct. If I
try
to implement my DllGetClassObje ct in the DLL code, the linker gives error
saying DllGetClassObje ct is already linked from oleexp.cpp.

What would I need to do to provide and use my implementation of
DllGetClassObje ct ?

The call to DllGetClassObje ct is currently failing with
CLASS_E_CLASSNO TAVAILABLE (ClassFactory cannot supply
requested class ), which I would assume is because of lack of CRT
initialization.

Thanks,
Niranjan

"Marcus Heege" wrote:
>The intention of the delayed CRT initialization is to avoid a deadlock,
which can happen if managed code is executed during DLLMain. After
DLLMain
is called, your client will likely call DllGetClassObje ct to instantiate
the
COM object. Unless some other code is called before DllGetClassObje ct, I
would initialize the CRT in your DllGetClassObje ct implementation.

Marcus

"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:5C******* *************** ************@mi crosoft.com...
Hi ,

I am trying to host .Net UserControls in a MFC Application. The MFC
Application is an ActiveX DLL. I inserted required managed code inside
the
MFC application, making it a mixed mode DLL.
I am following the KB article for mixed mode DLL's
http://support.microsoft.com/?id=814472
I linked the DLL with /noentry option. Also I added and exported the
DllEnsureInit and DllForceTerm methods in my DLL which call
__crt_dll_initi alize() and __crt_dll_termi nate() respectively. So far
so
good.

Now in the consumer application, this ActiveX control is created
dynamically
by the COleControlSite ::CreateControl method. I understand that I would
need
to invoke my init/term DLL functions manually after loading the the
mixed
mode DLL.
How do I go about invoking these functions here ? The KB article
demonstrates use of GetModuleHandle and GetProcAddress which I believe
may
not be usefule

Is this feasible ? Kindly advise.
Any inputs would be highly appreciated.
Thanks in advance,
Niranjan




Aug 22 '06 #4
Hi Marcus,
Actually I did it in a different way and it works. Though it has taken me by
a bit of surprise. Heres the story - If I provide implementation of only
DllGetClassObje ct
the linker complains of multiply defined symbols. Same is the case if I just
implement DllCanUnloadNow . However if I implement both, the linker is happy
and moreover my implementations get used. I implemented both
DllGetClassObje ct and DllCanUnloadNow and put the CRT initilization in
DllGetClassObje ct. It worked.
What do you think have made this happen ? (is it an intelligent compiler /
linker ?)

Thanks,
Niranjan

"Marcus Heege" wrote:
I my answer, I assumed that you used ATL instead of MFC. In this case, it
would have been easy to overwrite DllGetClassObje ct.With MFC, the story is
more difficult. I currently don't have VS2003 installed on my machine.
Therefore, I can't easily try it before I suggest something. But you may try
the following:

Modify the .def file so that

EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObje ct = MyDllGetClassOb ject PRIVATE
DllRegisterServ er PRIVATE
DllUnregisterSe rver PRIVATE

Implement MyDllGetClassOb ject so that you initialize the CRT if this has not
happened before. Once you ensured that the CRT is initialized, call
DllGetClassObje ct.

Please let us know if this works

Marcus
"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:3E******** *************** ***********@mic rosoft.com...
Hi Marcus,
Thanks for your reply.

I tried to investigate the current scenario without the CRT initialization
code in place. The client is calling the DllGetClassObje ct in library file
oleexp.cpp. I do not have my implementation of DllGetClassObje ct. If I
try
to implement my DllGetClassObje ct in the DLL code, the linker gives error
saying DllGetClassObje ct is already linked from oleexp.cpp.

What would I need to do to provide and use my implementation of
DllGetClassObje ct ?

The call to DllGetClassObje ct is currently failing with
CLASS_E_CLASSNO TAVAILABLE (ClassFactory cannot supply
requested class ), which I would assume is because of lack of CRT
initialization.

Thanks,
Niranjan

"Marcus Heege" wrote:
The intention of the delayed CRT initialization is to avoid a deadlock,
which can happen if managed code is executed during DLLMain. After
DLLMain
is called, your client will likely call DllGetClassObje ct to instantiate
the
COM object. Unless some other code is called before DllGetClassObje ct, I
would initialize the CRT in your DllGetClassObje ct implementation.

Marcus

"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:5C******** *************** ***********@mic rosoft.com...
Hi ,

I am trying to host .Net UserControls in a MFC Application. The MFC
Application is an ActiveX DLL. I inserted required managed code inside
the
MFC application, making it a mixed mode DLL.
I am following the KB article for mixed mode DLL's
http://support.microsoft.com/?id=814472
I linked the DLL with /noentry option. Also I added and exported the
DllEnsureInit and DllForceTerm methods in my DLL which call
__crt_dll_initi alize() and __crt_dll_termi nate() respectively. So far
so
good.

Now in the consumer application, this ActiveX control is created
dynamically
by the COleControlSite ::CreateControl method. I understand that I would
need
to invoke my init/term DLL functions manually after loading the the
mixed
mode DLL.
How do I go about invoking these functions here ? The KB article
demonstrates use of GetModuleHandle and GetProcAddress which I believe
may
not be usefule

Is this feasible ? Kindly advise.
Any inputs would be highly appreciated.
Thanks in advance,
Niranjan




Aug 23 '06 #5
Marcus,
I have tried it your way too and it works as well. However I have still not
been able to find how does the linker permits multiply defined symbols in my
case, as I have mentioned in the previous post.
Thanks.

"NPotnis" wrote:
Hi Marcus,
Actually I did it in a different way and it works. Though it has taken me by
a bit of surprise. Heres the story - If I provide implementation of only
DllGetClassObje ct
the linker complains of multiply defined symbols. Same is the case if I just
implement DllCanUnloadNow . However if I implement both, the linker is happy
and moreover my implementations get used. I implemented both
DllGetClassObje ct and DllCanUnloadNow and put the CRT initilization in
DllGetClassObje ct. It worked.
What do you think have made this happen ? (is it an intelligent compiler /
linker ?)

Thanks,
Niranjan

"Marcus Heege" wrote:
I my answer, I assumed that you used ATL instead of MFC. In this case, it
would have been easy to overwrite DllGetClassObje ct.With MFC, the story is
more difficult. I currently don't have VS2003 installed on my machine.
Therefore, I can't easily try it before I suggest something. But you may try
the following:

Modify the .def file so that

EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObje ct = MyDllGetClassOb ject PRIVATE
DllRegisterServ er PRIVATE
DllUnregisterSe rver PRIVATE

Implement MyDllGetClassOb ject so that you initialize the CRT if this has not
happened before. Once you ensured that the CRT is initialized, call
DllGetClassObje ct.

Please let us know if this works

Marcus
"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
news:3E******** *************** ***********@mic rosoft.com...
Hi Marcus,
Thanks for your reply.
>
I tried to investigate the current scenario without the CRT initialization
code in place. The client is calling the DllGetClassObje ct in library file
oleexp.cpp. I do not have my implementation of DllGetClassObje ct. If I
try
to implement my DllGetClassObje ct in the DLL code, the linker gives error
saying DllGetClassObje ct is already linked from oleexp.cpp.
>
What would I need to do to provide and use my implementation of
DllGetClassObje ct ?
>
The call to DllGetClassObje ct is currently failing with
CLASS_E_CLASSNO TAVAILABLE (ClassFactory cannot supply
requested class ), which I would assume is because of lack of CRT
initialization.
>
Thanks,
Niranjan
>
"Marcus Heege" wrote:
>
>The intention of the delayed CRT initialization is to avoid a deadlock,
>which can happen if managed code is executed during DLLMain. After
>DLLMain
>is called, your client will likely call DllGetClassObje ct to instantiate
>the
>COM object. Unless some other code is called before DllGetClassObje ct, I
>would initialize the CRT in your DllGetClassObje ct implementation.
>>
>Marcus
>>
>"NPotnis" <NP*****@discus sions.microsoft .comwrote in message
>news:5C******* *************** ************@mi crosoft.com...
Hi ,
>
I am trying to host .Net UserControls in a MFC Application. The MFC
Application is an ActiveX DLL. I inserted required managed code inside
the
MFC application, making it a mixed mode DLL.
I am following the KB article for mixed mode DLL's
http://support.microsoft.com/?id=814472
I linked the DLL with /noentry option. Also I added and exported the
DllEnsureInit and DllForceTerm methods in my DLL which call
__crt_dll_initi alize() and __crt_dll_termi nate() respectively. So far
so
good.
>
Now in the consumer application, this ActiveX control is created
dynamically
by the COleControlSite ::CreateControl method. I understand that I would
need
to invoke my init/term DLL functions manually after loading the the
mixed
mode DLL.
How do I go about invoking these functions here ? The KB article
demonstrates use of GetModuleHandle and GetProcAddress which I believe
may
not be usefule
>
Is this feasible ? Kindly advise.
Any inputs would be highly appreciated.
Thanks in advance,
Niranjan
>
>
>>
>>
>>
Sep 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2202
by: Mike Kamzyuk | last post by:
Hello all. Basically, I need to call a mixed-mode dll's function (which uses managed code) from a native or mixed-mode dll function (which does not use managed code). I'm wondering if this could be accomplished and how. Here's the problem. We have a third party app (TPA) capable of loading native and mixed-mode dlls somehow (we don't know how). It loads our native dll (OND) and allows us to use our code inside the app (that is, we...
0
1677
by: Edward Diener | last post by:
I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the "Managed Extensions for C++ Reference". 1) The first instruction in converting to mixed mode is to link with /NOENTRY. This occurs despite the fact that a pure mode DLL is already set up with this option in the linker, and the previous...
9
2592
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and explain it. I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the "Managed Extensions for C++ Reference"....
8
3517
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
8
2000
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid the usage of old style COM, my alternative is to expose my unmanaged interface through the CLI, to achieve that I have created a mixed mode DLL in which my unmanaged class are defined. When referencing the DLL just described in another mixed mode EXE...
2
1648
by: Doug Belkofer | last post by:
We have created a fairly complex mixed-mode DLL that we want to use from VB.NET. The mixed-mode DLL is written in C++, and does use the standard C runtime libraries. An unusual thing is happening in that when we look at this DLL from the Object Browser in Visual Studio, it seems to be exporting several items related to the standard C runtime libraries. One example is that there is a namespace called "std" in the Object Browser, and in that...
0
958
by: Doug Belkofer | last post by:
We have created a fairly complex mixed-mode DLL that we want to use from VB.NET. The mixed-mode DLL is written in C++, and does use the standard C runtime libraries. An unusual thing is happening in that when we look at this DLL from the Object Browser in Visual Studio, it seems to be exporting several items related to the standard C runtime libraries. One example is that there is a namespace called "std" in the Object Browser, and in that...
8
2323
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
0
3003
by: emu | last post by:
Hi All, I have an unmanaged C++ application that references a mixed mode image DLL (mixed managed and unmanaged). Under .NET 1.1 we could trust the dll (the mixed mode dll) by running the following command line: caspol.exe -polchgprompt off -machine -addgroup 1 -url "file://<UNC path to dll>\mixedMode.dll" FullTrust ame "GroupName" -polchgprompt on
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.