LNK1120未解析的外部:用于MFC项目的CLR包装器

时间:2015-08-17 17:51:27

标签: c++ mfc wrapper

通常这些错误意味着函数声明与它们的实体之间存在不匹配。我已经检查过所有类都具有确切数量的函数实现,如其各自的类中所定义。所有项目都在同一解决方案中并位于同一平台上(x86)。我认为这不是重复的问题,因为我试图阅读论坛上与此问题相关的所有问题。

我有一个MFC项目可以自行运行。我添加了一个名为MathFuncs.cpp的类与头文件,以便我可以在Wrapper类中使用它。我想在我的C#项目中使用Wrapper类。

我已经尝试了许多不同的方法来开发包装类项目,MFC DLL,普通类库和Win32 MFC动态链接库。我已经更改了不同的设置,就像添加依赖项目一样,包括外部目录但没有用。我继续得到LNK 2028,2019和1120错误。

如果我没有在MathFuncs.cpp中引用其他类对象,那么每件事都可以正常工作但是一旦我开始创建其他类(在同一个项目中)对象并使用它们的函数CLR(DLL)项目对此感到不安。我不确定我错在哪里。请注意,这两个项目都与VS2010的解决方案相同。

以下是MathFuncs.h的代码:

#pragma once

#include <stdexcept>
#include "ESCppClientDlg.h"
using namespace std;

class MyMathFuncs 
{
public:
    MyMathFuncs();
   double Add(double a, double b);
   double Subtract(double a, double b);
   double Multiply(double a, double b);
   double Divide(double a, double b);
   //char *getResultValue();
//private:
//  CESCppClientDlg dlg;
};

和Mathfuns.h

    #pragma once
#include "MathFuncs.h"

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 invalid_argument("b cannot be zero!");
    return a/b;
}
//char * MyMathFuncs::getResultValue()
//  {
//      
//
//      return dlg.GetResultValue();    
//  }

MyMathFuncs::MyMathFuncs()
{
    CWnd *pParent = (CWnd *)0;
    CESCppClientDlg dlg = new CESCppClientDlg();    
}

以下是类库的代码

// ClassLibrary1.h

#pragma once

#include "Stdafx.h";
#include "C:\Programming\C#\LiecaClientLibrary\ESCppClient Solution 13082015 - V2\MathFuncs.h"
#include "C:\Programming\C#\LiecaClientLibrary\ESCppClient Solution 13082015 - V2\MathFuncs.cpp"

using namespace System;

namespace CppWrapper {
    public ref class MyMathFuncsWrapper
    {
    public:
       // constructor


       MyMathFuncsWrapper()
        { 
            initVal = 20.0; 
            myCppClass = new MyMathFuncs(); //initiate C++ class's instance
        }

        double AddWrapper ( double a, double b)
        {   return myCppClass->Add(a,b);   }

        double SubtractWrapper (double a, double b)
        {   return myCppClass->Subtract(a,b);   }

        double MultiplyWrapper (double a, double b)
        {   return myCppClass->Multiply(a,b);   }

        double DivideWrapper (double a, double b)
        {   return myCppClass->Divide(a,b);   }

       // public variable
       double initVal;

        private:
           MyMathFuncs *myCppClass; // an instance of class in C++
    };

}

如果我评论

CWnd *pParent = (CWnd *)0;
    CESCppClientDlg dlg = new CESCppClientDlg();
从MathFuncs.cpp

然后一切正常但我真的需要使用CESCppClientDlg的对象来访问数据。这就是制作包装类的重点。 以下是我得到的错误:

错误1错误LNK2028:未解析的令牌(0A000613)&#34; public:__ thishisall CESCppClientDlg :: CESCppClientDlg(class CWnd *)&#34;函数&#34; public中引用了(?? 0CESCppClientDlg @@ $$ FQAE @ PAVCWnd @@@ Z):__ thishisall MyMathFuncs :: MyMathFuncs(void)&#34; (?? 0MyMathFuncs @@ $$ FQAE @ XZ)C:\ Programming \ C#\ LiecaClientLibrary \ ESCppClient Solution 13082015 - V2 \ ClassLibrary1 \ ClassLibrary1.obj ClassLibrary1错误2错误LNK2019:未解析的外部符号&#34; public:__ thiscall CESCppClientDlg: :CESCppClientDlg(CWnd *类)&#34;函数&#34; public中引用了(?? 0CESCppClientDlg @@ $$ FQAE @ PAVCWnd @@@ Z):__ thishisall MyMathFuncs :: MyMathFuncs(void)&#34; (?? 0MyMathFuncs @@ $$ FQAE @ XZ)C:\ Programming \ C#\ LiecaClientLibrary \ ESCppClient Solution 13082015 - V2 \ ClassLibrary1 \ ClassLibrary1.obj ClassLibrary1错误3错误LNK1120:2个未解析的外部C:\ Programming \ C#\ LiecaClientLibrary \ ESCppClient解决方案13082015 - V2 \ Debug \ ClassLibrary1.dll ClassLibrary1

非常感谢提前

0 个答案:

没有答案