0

When I compile this program,

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <afxdb.h>
#define _AFXDLL

int main(int argc, char *argv[])
{
    CString sDsn;
    CDatabase db;

    sDsn = "ODBC; DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; DSN = ''; DBQ = D:\DATABASE\bible.mdb";
    db.Open(NULL, false, false, sDsn);

    try
    {
        CRecordset rs(&db);
        CString strOut;
        CString strOut2;
        CString strOut3;

        CString SqlString = "SELECT nom_prophete FROM L_PROPHETE";

        rs.Open(CRecordset::snapshot, SqlString, CRecordset::appendOnly);

        rs.GetFieldValue((short)0, strOut);
        AfxMessageBox(strOut);

        // --- petite transformation en string
        // --- pour l'affichage sur la console

        CT2CA pszConvertedAnsiString(strOut);

        std::string strStd(pszConvertedAnsiString);

        std::cout << "--" << strStd.c_str() << std::endl;

        rs.MoveNext();

        // --- petite transformation en string
        // --- pour l'affichage sur la console

        CT2CA pszConvertedAnsiString2(strOut2);

        std::string strStd2(pszConvertedAnsiString2);

        std::cout << "--" << strStd2.c_str() << std::endl;

        rs.MoveNext();

        rs.GetFieldValue((short)0, strOut3);
        AfxMessageBox(strOut3);

        // -- petite transformation en string
        // -- pour l'affichage sur la console

        CT2CA pszConvertedAnsiString3(strOut3);

        std::string strStd3(pszConvertedAnsiString3);

        std::cout << "--" << strStd3.c_str() << std::endl;

        rs.Close();
    }
    catch (CDBException *p)
    {
        AfxMessageBox(p->m_strError);
    }
    return 0;
}

it shows this error,

Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:\program files (x86)\microsoft visual studio 12.0\vc\atlmfc\include\afx.h 24 1 MA_BIBLE */

1 Answer 1

1

Go to Project Settings -> Configuration Properties -> General and make sure that you set "Using MFC in a Shared DLL" for both debug and release versions.

Also if you include windows.h somewhere - remove that line since MFC projects should include only afxwin.h

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.