Reputation:

MFC programming in c++

I am new to this MFC stuff, I am working on a project, where i need to use class CFileFind which is in MFC. how can I link to my regular VC++ program to use that class.

I am completely new to MFC, n apologize if there is a mistake.

thanks in advance.

Upvotes: 0

Views: 644

Answers (5)

Karthik Krish
Karthik Krish

Reputation: 131

If only finding the file is wanted in the application, simply use FindFirstFile, FindNextFile, FindClose and PathMatchSpec window APIs. No need to include MFC library for that. These APIs have better approach than MFC CFileFind and there is no library include overhead.

Upvotes: 0

Andrew Komiagin
Andrew Komiagin

Reputation: 6566

You'll need to include the following headers (better in precompiled header like stdafx.h/cpp)

#include <afx.h>
#include <afxwin.h>         // MFC core and standard components

you should also initialize MFC framework by calling:

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
  _tcerr << _T("Fatal Error: MFC initialization failed") << endl;
}

Hope it helps.

Upvotes: 0

ggponti
ggponti

Reputation: 395

Include afx.h and look at the general project settings. There should be an option to specify that you want to use MFC either as shared DLL or static library.

What version of Visual Studio are you using?

Upvotes: 2

Reed Copsey
Reed Copsey

Reputation: 564851

Why not just use the Windows API directly, via FindFirstFile, FindNextFile, and FindClose?

MFC will add a lot of overhead... if you're just using it for this, it's a waste. I would only consider MFC if you're planning to write large portions of your application using the whole MFC framework.

That being said, I'd actually recommend avoiding MFC altogether unless you have a reason to use it. There are many other clean, easy to use frameworks if you need an entire GUI framework, such as Qt.

Upvotes: 6

Gerald
Gerald

Reputation: 23499

You'll either need to make your other program an MFC application, or you'll need to encapsulate the MFC stuff in an MFC DLL and invoke the DLL from your application.

Upvotes: 0

Related Questions