为什么我不能从一个dll中包装方法,但可以为另一个dll进行包装?

时间:2019-02-13 01:57:42

标签: dll c++-cli

我试图用c ++ / cli为DLL写一个包装,我没有的代码,只有DLL文件和标头,但是我通过VS命令提示符创建了lib文件。当我尝试构建解决方案时,出现以下错误:

DotNetWrappOfAsterSdkDll.obj : error LNK2028: unresolved token (0A00002E) "void __stdcall MuteClearLastError(void)" (?MuteClearLastError@@$$FYGXXZ) referenced in function "public: void __clrcall DotNetWrappOfAsterSdkDll::WrapperClass2::doMuteClearLastError(void)" (?doMuteClearLastError@WrapperClass2@DotNetWrappOfAsterSdkDll@@$$FQ$AAMXXZ)
DotNetWrappOfAsterSdkDll.obj : error LNK2019: unresolved external symbol "void __stdcall MuteClearLastError(void)" (?MuteClearLastError@@$$FYGXXZ) referenced in function "public: void __clrcall DotNetWrappOfAsterSdkDll::WrapperClass2::doMuteClearLastError(void)" (?doMuteClearLastError@WrapperClass2@DotNetWrappOfAsterSdkDll@@$$FQ$AAMXXZ)

我试图创建自己的DLL并将其包含到包装器中,并且完美运行

我在这里创建的dll,可以在c ++ / cli包装器中使用:

//header file
#pragma once
#define DLLEXP   __declspec( dllexport )
namespace Computations {
    DLLEXP void someMethod(int number);
}

//cpp file
#include "Computations.h"
#include <iostream>
#include <time.h>
//#include "pnl/pnl_random.h"

using namespace std;


void Computations::someMethod(int number)
{
    std::cout << "something "<<number*number << endl;
}

这是我要使用的DLL标头的一部分:

#ifndef MUTEIFC_H
#define MUTEIFC_H

#include <Windows.h>

#ifdef MUTEIFC_LIBRARY
#  define MUTEAPI  extern "C"__declspec(dllexport)
#else
#  define MUTEAPI __declspec(dllimport)
#endif

#define MUTECALL __stdcall

/** \ingroup init */
/** Initialization of the ASTER SDK library
  * \returns TRUE - success, FALSE - failure (use \ref MuteLastErrorCode or/and \ref MuteLastErrorInfo to get
  *                 failure cause)
  * \note This function will require Administrative privileges on the first call on a given computer.
  */
MUTEAPI BOOL MUTECALL MuteIfcInitialize(VOID);


/** \ingroup init */
/** Finialization of the ASTER SDK library
  */
MUTEAPI VOID MUTECALL MuteIfcFinalize(VOID);

/** \ingroup errors*/
/** Clears the calling thread's last-error code and description.
  * The last-error is maintained on a per-thread basis. Multiple threads do not overwrite each other's last-error.
  */
MUTEAPI VOID MUTECALL MuteClearLastError(VOID);
#endif // MUTEIFC_H

和我的c ++ / cli代码:

//header file
#pragma once
#include "Computations.h"
#include "muteifc.h"

using namespace System;

namespace DotNetWrappOfAsterSdkDll
{
    public ref class WrapperClass2
    {
        public:
        void doMuteClearLastError();
    };

    public ref class WrapperClass
    {
    private:
    public:
        void getPriceCallEuro(int number);

    };

}

//cpp file
#include "DotNetWrappOfAsterSdkDll.h"

using namespace DotNetWrappOfAsterSdkDll;

using namespace Computations;

namespace DotNetWrappOfAsterSdkDll
{
        //this dont work
    void WrapperClass2::doMuteClearLastError() {
        MuteClearLastError();
    }
        //this works great
    void WrapperClass::getPriceCallEuro(int number) {
        someMethod(number);
        //MuteIfcFinalize();
    }
}

请告诉我我在做什么错

1 个答案:

答案 0 :(得分:0)

您可能没有添加包含链接器选项的函数引用的库。

库本身包含它自己的代码,或者它具有对必须加载的DLL的引用。链接器会将您的代码和DLL(或静态lib)代码放在一起...