none
MFC shared dll version.

    Question

  • Hello,everyone!
     It is a windows project.I got the error when I ran it:fatal error C1189: #error :  Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
    How can I get rid of it?And this is the source file;

    #include<windows.h>
    #include<afxwin.h>
    class MyFrameWindow:public CFrameWnd
    {public:
        afx_msg void onpaint()
     {CPaintDC paintDC(this);
      paintDC.Textout(0,0,"This is my first window");
     }
     DECLARE_MESSAGE_MAP()
    };
    BEGIN_MESSAGE_MAP(MyFrameWindow,CFrameWnd)
     ON_WM_PAINT()
     END_MESSAGE_MAP()

     class HelloApp:public CWinApp
    {public:
     HelloApp():CWinApp("Hello World!"){}
     BOOL InitInstance()
     {CFrameWnd *MyFrame=new MyFrameWindow;
     M_PMainWnd=MyFrame;
     MyFrame->Create(NULL,(LPCTSTR)"Hello");
     MyFrame->ShowWindow(SW_SHOW);
     return TRUE;
     }
    }Hello World;

    Saturday, May 9, 2009 9:08 AM

Answers

  • 1. Remove the line

    #include <windows.h>

    (MFC projects should use only afxwin.h)

    2. In Project Settings->Configuration Properties->Use of MFC, make sure that
    "Using MFC in a Shared DLL" is specified for both debug and release version. Or,
    you can select "Use MFC in a Static Library", just not "Using Standard Windows
    Libraries".

    --
    David Wilkinson
    Visual C++ MVP
    • Marked as answer by Trenchless Saturday, May 9, 2009 2:31 PM
    Saturday, May 9, 2009 10:55 AM

All replies

  • The error message tells you what to do.  Project + Properties, General, Use of MFC = Shared DLL.

    Hans Passant.
    Saturday, May 9, 2009 10:53 AM
    Moderator
  • 1. Remove the line

    #include <windows.h>

    (MFC projects should use only afxwin.h)

    2. In Project Settings->Configuration Properties->Use of MFC, make sure that
    "Using MFC in a Shared DLL" is specified for both debug and release version. Or,
    you can select "Use MFC in a Static Library", just not "Using Standard Windows
    Libraries".

    --
    David Wilkinson
    Visual C++ MVP
    • Marked as answer by Trenchless Saturday, May 9, 2009 2:31 PM
    Saturday, May 9, 2009 10:55 AM
  • Hi,
    i have the same problem as you using the custon MESSAGE!
    I have this error when compiling:

    1>Form1.cpp
    
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afx.h(24) : fatal error C1189: #error :  Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
    
    


    My code is the following:

    //Form1.h
    
    #pragma once
    
    #include "afxwin.h"
    
    namespace Progetto007 {
    
     using namespace System;
    
     using namespace System::ComponentModel;
    
     using namespace System::Collections;
    
     using namespace System::Windows::Forms;
    
     using namespace System::Data;
    
     using namespace System::Drawing;
    
    
    
     /// <summary>
    
     /// Riepilogo per Form1
    
     ///
    
     /// AVVISO: se si modifica il nome della classe, sarà necessario modificare la
    
     ///          proprietà 'Nome file di risorse' relativa allo strumento Compilatore di risorse gestite
    
     ///          associato a tutti i file RESX da cui dipende la classe. In caso contrario,
    
     ///          le finestre di progettazione non saranno in grado di interagire correttamente con le
    
     ///          risorse localizzate associate al form.
    
     /// </summary>
    
     public ref class Form1 : public System::Windows::Forms::Form
    
     {
    
     public:
    
      Form1(void)
    
      {
    
       InitializeComponent();
    
       //
    
       //TODO: aggiungere qui il codice del costruttore.
    
       //
    
      }
    
    
    
     protected:
    
      /// <summary>
    
      /// Liberare le risorse in uso.
    
      /// </summary>
    
      ~Form1()
    
      {
    
       if (components)
    
       {
    
        delete components;
    
       }
    
      }
    
    
    
     protected: 
    
       //{{AFX_MSG(Form1)
    
       //}}AFX_MSG
    
       
    
       DECLARE_MESSAGE_MAP()
    
       afx_msg LRESULT CustomMSG(WPARAM wparam, LPARAM lparam);  
    
       
    
      
    
     private:
    
      /// <summary>
    
      /// Variabile di progettazione necessaria.
    
      /// </summary>
    
      System::ComponentModel::Container ^components;
    
    
    
    #pragma region Windows Form Designer generated code
    
      /// <summary>
    
      /// Metodo necessario per il supporto della finestra di progettazione. Non modificare
    
      /// il contenuto del metodo con l'editor di codice.
    
      /// </summary>
    
      void InitializeComponent(void)
    
      {
    
       this->components = gcnew System::ComponentModel::Container();
    
       this->Size = System::Drawing::Size(300,300);
    
       this->Text = L"Form1";
    
       this->Padding = System::Windows::Forms::Padding(0);
    
       this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    
      }
    
    #pragma endregion
    
     };
    
    }
    
    

     

    //Form1.cpp
    
    
    
    #include "StdAfx.h"
    
    #include "Form1.h"
    
    #define WM_TEST (WM_USER + 100)
    
    
    
    BEGIN_MESSAGE_MAP(Form1, Form)
    
    //{{AFX_MSG_MAP(Form1)
    
    //}}AFX_MSG_MAP
    
        ON_MESSAGE(WM_TEST, CustomMSG)  
    
    END_MESSAGE_MAP()
    
    
    
    afx_msg LRESULT Form1::CustomMSG(WPARAM wparam, LPARAM lparam)
    
    {
    
    int a=1;
    
    return 0L;
    
    }
    
    


    What kind of configuration  do you suggest in the Project Settings??
    Many thanks!

    Saturday, May 16, 2009 10:55 AM
  • obiwan:

    Since you are using a WinForm you must choose CLR - Windows Forms Application. If you are going to use MFC, you must also select "Using MFC in a Shared DLL".

    It may be OK to put an MFC message map into a WinForm like this, but why are you doing it? Subscribing to an event is a much more elegant communication mechanism.
    David Wilkinson | Visual C++ MVP
    Saturday, May 16, 2009 11:09 AM
  • It is not okay to put MFC message maps in a Windows Forms app.  It isn't going to work.

    You would rarely ever use custom window messages in a WF app, .NET programming supports events.  This is much more efficient and richer programming model, one that doesn't require stuffing the data your want to pass in a WPARAM and LPARAM.  The best way to learn how to use them is through a book.  You'll want to focus on the notion of a delegate and the "event" keyword.
    Hans Passant.
    Saturday, May 16, 2009 1:03 PM
    Moderator
  • It is not okay to put MFC message maps in a Windows Forms app.  It isn't going to work.
    Hans:

    Of course you are right; what the OP was trying to do cannot possibly work. An MFC message map must be in a native class derived from CWnd.

    However it is possible to have an application that contains both native windows (HWND/CWnd) and WinForms, as evidenced by the MFC classes CWinFormsView, CWinFormsDialog, CWinFormsControl. Nishant Sivakumar's book "C++/CLI in Action" contains all kinds of techniques for mixing MFC and WinForms.

    David Wilkinson | Visual C++ MVP
    Sunday, May 17, 2009 1:18 AM
  • hi, 
    thank you for your answers. I am beginner in VC++ NET (i used Borland C++Builder)
    I need to create a classic Windows application multiform (File -> New -> Project -> Visual C + + -> Windows Form Application) I need to provide custom message using SendMessage () function.
    Can you suggest me something?
    thanks.
    Monday, May 18, 2009 8:12 AM
  • I think you can use Form::WndProc().

    David Wilkinson | Visual C++ MVP
    Monday, May 18, 2009 11:13 AM
  • I think you can use Form::WndProc().

    David Wilkinson | Visual C++ MVP

    I would avoid using WndProc() function.
    I'm looking for an other way to create and intercept custom messages in a WinForm... Does it exist??
    Thanks a lot.
    Monday, May 18, 2009 4:18 PM
  • As long as you use custom messages sent or posted with Send/PostMessage(), you will have to override WndProc() to detect them.  There is no other way.

    Hans Passant.
    Monday, May 18, 2009 5:29 PM
    Moderator
  • Go to Project settings-->Configuration settings-->C/C++-->Preprocessor.

    In Preprocessor defination add "_AFXDLL".

    That's all

    • Proposed as answer by Eq_Nilam Friday, May 18, 2012 12:22 PM
    Wednesday, December 28, 2011 9:38 AM
  • Thanks..This is d correct answer
    Friday, May 18, 2012 12:23 PM
  • In Visual Studio 2013: PROJECT -> Properties -> Configuration Properties -> General -> Use of MFC 

    -> Use of MFC in a shared DLL.

    Monday, October 20, 2014 12:07 AM
  • Hi, Davewilk,

    I am a VC++ beginner, I can not answer your question at this point.

    Best regards,

    ddmmaa

    Wednesday, March 18, 2015 4:30 PM