0

SOLVED: Thanks to Casey Price for their answer. I then ran into 2 other errors: BadImageFormatException and FileNotFoundException, the former was solved by matching the platform target (x64 or x86) for each project and the latter was solved by setting the output directory of the C# project to the directory containing the dll file.

I'm working on a game 'engine' which currently has a working graphics subsystem that draws/textures movable models. I'm trying to write a C++/CLR wrapper so I can use the engine in a C# program (as a designer tool).

My wrapper project is a C++/CLR class library and contains the following 2 files (as well as resource.h/cpp and Stdafx.h/cpp)

// pEngineWrapper.h

#pragma once
#define null NULL

#include "..\pEngine\pEntry.h"

using namespace System;

namespace pEngineWrapper
{
    public ref class EngineWrapper
    {
        public:
        EngineWrapper();
        ~EngineWrapper();
        bool Initialise();

    private:
        pEntry* engine;
    };
}

and the .cpp file

// This is the main DLL file.

#include "stdafx.h"

#include "pEngineWrapper.h"

pEngineWrapper::EngineWrapper::EngineWrapper()
{
    engine = null;
}

pEngineWrapper::EngineWrapper::~EngineWrapper()
{
    delete engine;
    engine = null;
}

bool pEngineWrapper::EngineWrapper::Initialise()
{
    bool result;

    engine = new pEntry;

    result = engine->Initialise();
    if( result == false )
    {
        return false;
    }

    return true;
}

When I go to build this project however I get 14 errors: LNK2028, LNK2019, and LNK2001 which points to some classes within the engine. I have included the errors in the file below.

https://www.dropbox.com/s/ewhaas8d1te7bh3/error.txt?dl=0

I also get a lot of warnings regarding XMFLOAT/XMMATRIX which you may notice.

In all of the engine classes I use the dllexport attribute

class __declspec(dllexport) pEntry

I feel like I'm missing the point and doing it all wrong seeing all of these errors but I haven't found any documents telling me anything considerably different than what I'm doing here

Dom W
  • 49
  • 5

1 Answers1

0

you have to add a reference to the static .lib files for the game engine you are using as well as it's dll's or load the dll's manually

to add the references to the .lib files right click your project->Properties->Linker->input add the lib file to the additional dependencies

See also: DLL References in Visual C++

Community
  • 1
  • 1
Casey Price
  • 768
  • 7
  • 16
  • Thankyou! This solved the building errors I was getting. So what I was doing was right phew. – Dom W Nov 26 '15 at 05:14