Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:55:00+00:00 2026-06-05T00:55:00+00:00

In Visual Studio 2008, using C++, I tried to build a DLL using the

  • 0

In Visual Studio 2008, using C++, I tried to build a DLL using the instructions at http://msdn.microsoft.com/en-us/library/ms235636.aspx, except I named a source file with an extension of “.c” rather than the suggested “.cpp”.

With an extension of .c, the compiler throws 37 errors. With an extension of .cpp, the DLL builds successfully.

What difference does the extension of a source file make?

Here is the full code:

// MathFuncsDll.cpp
// compile with: /EHsc /LD

#include "MathFuncsDll.h"

#include <stdexcept>

using namespace std;

namespace MathFuncs
{
    double MyMathFuncs::Add(double a, double b)
    {
        return a + b;
    }

    double MyMathFuncs::Subtract(double a, double b)
    {
        return a - b;
    }

    double MyMathFuncs::Multiply(double a, double b)
    {
        return a * b;
    }

    double MyMathFuncs::Divide(double a, double b)
    {
        if (b == 0)
        {
            throw new invalid_argument("b cannot be zero!");
        }

        return a / b;
    }
}




// MathFuncsDll.h

namespace MathFuncs
{
    class MyMathFuncs
    {
    public:
        // Returns a + b
        static __declspec(dllexport) double Add(double a, double b);

        // Returns a - b
        static __declspec(dllexport) double Subtract(double a, double b);

        // Returns a * b
        static __declspec(dllexport) double Multiply(double a, double b);

        // Returns a / b
        // Throws DivideByZeroException if b is 0
        static __declspec(dllexport) double Divide(double a, double b);
    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:55:02+00:00Added an answer on June 5, 2026 at 12:55 am

    The compiler (driver program) guesses at the source language based on the extension, assuming C for .c and C++ for .cpp. You can override that guess with -Tp to force C++ or -Tc to force C. If you want that for all the files you pass instead of just one, capitalize (-TP or -TC).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to build ICU4C sample uncv using visual studio 2008 without success I
I created an ActiveX control ocx file using Visual Studio 2008. Then tried registering
I have CruiseControl.net running Visual Studio (2005/2008 - using devenv.com) as we need to
I am using Visual Studio 2008 to build my projects. I often take existing
I've developed a 64 bit dll using C++ and Visual Studio 2008 and i'm
I'm working in Visual Studio 2008 using c#. Let's say I have 2 xsd
I'm helping develop a MVC application in Visual Studio 2008 using the Entity Model
I'm using a unordered map pointer because of C++/Cli on Visual Studio 2008 (Using
Visual Studio 2008 I am using the following source code that compiles ok using
Visual Studio C++ 2008 I am using threads. However, I have this warnings and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.