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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.
> 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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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.

> 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.