Hello. I have a problem and I would love it if I could get some insight on it.
I have read the forums with many answers about the subject, but I'm still having problems so I'm writing here. Basically I was following this guide which is for creating Managed Wrapper from a static library LIB. I thought, static, dynamic, how different could it be.
I have a C program that allows me to do some functions, for simplicity, I am now only using a simple addition function; but the real thing I ultimately want to do is far more complex. For now I just want this simple thing to work.
I'm using MS Visual Studio 2010. I created a Blank Solution with the following three projects:
- AdditionDLL
- Wrapper
- MainCode
AdditionDLL project is a simple C program that has only one function which is to add two numbers together. It is exported as DLL. The code is as follows:
// AdditionClass.c
#include "AdditionClass"
#include <stdio.h>
#pragma once
double Add(double x, double y){
return x+y;
}
// AdditionClass.h
#pragma once
static double Add(double x, double y);
This compiles fine and the DLL is created.
Now the Wrapper project is a managed C++/CLR application that is supposed to use the Add
function from the AdditionDLL.dll. So I created the project as C++/CLR and change the properties to depend on the dll and also for the linker. Moreover, I have added the AdditionDLL as a reference. Here is the content of the files:
//ClrWrapper.cpp
#include "stdafx.h"
#include "ClrWrapper.h"
using namespace ClrWrapper;
extern "C" __declspec(dllimport)double Add(double x, double y);
//ClrWrapper.h
using namespace System;
namespace ClrWrapper{
public ref class AdditionClass{
public:
double Add(double x, double y);
};
}
This doesn't compile. It gives me error LNK1107 invalid or corrupt file cannot read at 0x2F0
I know I have a lot of mistakes because I'm trying to make things communicate which shouldn't be communicating. I'd appreciate any help.
The last project is just the C# code to use the Wrapper. I haven't worked on that yet because my wrapper still doesn't work.