Я пытаюсь создать простую DLL HelloWorld на С++, чтобы впервые освоить использование библиотек DLL С++. Но когда я пытаюсь собрать свой проект, содержащий мой метод, я всегда получаю сообщение об ошибке error LNK1107: invalid or corrupt file: cannot read at 0x2B8 C:\Users\octavio\Documents\Visual Studio 2013\Projects\UseOfDll\UseOfDll\HelloWorldDll.dll
.
В моем проекте UseOfDll
я добавил C:\Users\octavio\Documents\Visual Studio 2013\Projects\UseOfDll\UseOfDll\HelloWorldDll.dll
к Project > UseOfDll Properties > Linker > Input > Additional Dependecies
. Я также добавил HelloWorldDll.dll
и HelloDll.h
в каталог проекта UseOfDll
.
Это основной метод программы (называемой UseOfDll
), который использует DLL:
// UseOfDll.cpp ----------------------------------------------------
#include "stdafx.h"
#include "HelloDll.h"
int _tmain(int argc, _TCHAR* argv[]) {
HelloDll helloDll;
helloDll.hello();
HelloDll::helloStatic();
getchar();
return 0;
}
В моем отдельном проекте Visual Studio для DLL у меня есть:
// HelloDll.h ------------------------------------------------------
#pragma once
#ifdef DLLDIR_EX
#define DLLDIR __declspec(dllexport) // export DLL information
#else
#define DLLDIR __declspec(dllimport) // import DLL information
#endif
class HelloDll {
public:
HelloDll();
~HelloDll();
void hello();
static void helloStatic();
};
// HelloDll.cpp ----------------------------------------------------
#include "stdafx.h"
#include "HelloDll.h"
#include <iostream>
using namespace std;
HelloDll::HelloDll() {}
HelloDll::~HelloDll() {}
void HelloDll::hello() {
cout << "Hello World of DLL" << endl;
}
void HelloDll::helloStatic() {
cout << "Hello World of DLL static" << endl;
}
#ifdef DLLDIR_EX
? - person roscioli   schedule 22.05.2014.lib
? И должен ли я добавить файл.lib
в Linker › Input › Additional Dependencies, только не файл.dll
)? Наконец, когда я компилирую свой проект DLL, я не получаю файл.lib
. Я что-то неправильно настраиваю? - person roscioli   schedule 22.05.2014__declspec(dllexport)
и куда? - person roscioli   schedule 22.05.2014