How to static-link to MFC when building ActiveX control?

How can I static-link to MFC when building ActiveX control?

Static-linking to MFC seems harder when building an ActiveX
control than when building an application. How can I make this work?

Using VisualC++5.0 (I do not own 6.0), I can use the MFC ActiveX
ControlWizard to generate a default project for my ActiveX control.
Notice, however, that the wizard gives no option to use
static (not dynamic) linking with MFC.

After ControlWizard completes, it is easy to open project settings
and change the link setting from "Use MFC in shared DLL"
to "Use MDC in static library".

However, this leads to compiler errors...

For example:
--------------------Configuration: testActivexWizard - Win32 Debug--------------------
   Creating library Debug/testActivexWizard.lib and object Debug/testActivexWizard.exp
testActivexWizard.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall COleControlModule::GetRuntimeClass(void)const " (?GetRuntimeClass@COleControlModule@@UBEPAUCRuntimeClass@@XZ)
testActivexWizard.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall COleControlModule::ExitInstance(void)" (?ExitInstance@COleControlModule@@UAEHXZ)

I know some ActiveX controls today do
link statically with MFC (e.g. Olectra Chart from

So how do I do it?
Is it possible using Studio97/VisualC++5.0?

Who is Participating?
mikeblasConnect With a Mentor Commented:
> So I am still a little skeptical.

Perhaps a little introduction is in order: at the time this feature was implemented, I was the development lead on the MFC and ATL teams at Microsoft. Dean McCrory, one of the original MFC authors, reported to me at the time. He's the guy who actually did the work to enable MFC to statically link OLE control implementations.

We never wanted to implement MFC ActiveX controls to statically link MFC because the resulting size would be very large. The resulting working set of an app that was written in MFC and used a few ActiveX controls could potentially be astrnomically large.

Dean did lots of optimizations to bring the size down, and we decided to ship those changes for customers who insisted on statically linking their controls.

Because the size was still unacceptable to us, we decided to not call attention to this change by documenting it. I didn't even mention it when I wrote the "What's new in MFC" topic for MSDN. As such, I think it will be hard to find documentation for this feature.

The documentation _does_ call out, in quite a few spots, that the static link size patterns of the library were significantly improved in the VC++ 6.0 release. That improvement, in large part, was becasue of the tuning that Dean did for statically linking OLE Controls.

There's no need to be skeptical: you're getting the answer straight from the source.

..B ekiM


Using static libraries which are built in release mode is causing U problem If UR want UR Activex to have static labrary then build it in release mode
Go to Build Set Active Configuration select release mode UR project will compile now.

Hope this helps
cternoeyAuthor Commented:
I do not believe I am using static libraries built in relase mode. Anyway, the test case is to accept all default settings from ControlWizard and then change ProjectSettings to link MFC as a static (not dynamic) library. This test case gives linking errors whether I build in release mode or debug mode.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

> Is it possible using Studio97/VisualC++5.0?

No, it's not... not unless you want to some pretty major surgery on MFC by yourself.

The ability to statically link an MFC-based ActiveX control was added in Visual C++ 6.0.

..B ekiM
cternoeyAuthor Commented:
Adjusted points to 150
cternoeyAuthor Commented:
Thanks for this tip.
However, I really need to be sure about this, so I must have some supporting evidence for the claim.

To the contrary, there is no mention of static linking as a new feature in the "What's New" section of VC6.0 product info:
So I am still a little skeptical.

I will give an A grade to any answer with some supporting evididence for this claim.

Please resubmit if you have a reference to support this point.

cternoeyAuthor Commented:
You work for Microsoft?
Now I REALLY don't trust you.
Kidding, of course.
MFC and ATL are amazing libraries.
Sincere thanks for contributing to the awesome power of VC++.
And for clarifying the issue.

 > You work for Microsoft?

See my bio.

 > Now I REALLY don't trust you.

Good luck with your project.

..B ekiM
All Courses

From novice to tech pro — start learning today.