Ответить на сообщение
Вернуться к теме
Вы отвечаете на сообщение:
Автор: evilive (08.09.2012 в 13:32) Всем привет! Проблема в следующем: есть dll-ка, в ней 3 простых функции: 1. Sum - сложение 2х целых чисел. 2. Concat - соединяет 2 строки. 3. GetFirst - возвращает 1й элемент вектора, переданного ей в качестве параметра. Далее эта длл динамически загружается, и первые две функции отлично определяются и работают. А вот 3я - нет, программа ее не видит. Как это исправить? Причем интересует случай, когда подключается .dll-файл без хэдэра. Написано все на Visual С++ 2008. dll, header:
#include <iostream> #include <vector> using namespace std; extern "C" __declspec(dllexport) int Sum(int val1, int val2); extern "C" __declspec(dllexport) string Concat(string str1, string str2); extern __declspec(dllexport) int GetFirst(vector<int> SomeVector);
#include "SmthStpd.h" extern "C" __declspec(dllexport) int Sum(int val1, int val2) { return val1 + val2; } extern "C" __declspec(dllexport) string Concat(string str1, string str2) { return str1.append(str2); } extern __declspec(dllexport) int GetFirst(vector<int> SomeVector) { return SomeVector[0]; }
#include <windows.h> #include <iostream> #include <vector> #include <string> using namespace std; void main() { HINSTANCE hLib = LoadLibrary(L"universal.dll"); if (hLib == NULL) { cout << "Unable to load library!" << endl; system("pause"); return; } /*----функция Sum----*/ typedef int(*function1Dll)(int, int); function1Dll Sum = (function1Dll)GetProcAddress(hLib, "Sum"); if (Sum == NULL) { cout << "Unable to load Sum." << endl; system("pause"); return; } cout << Sum(4, 6) << endl; /*----функция Concat----*/ typedef string(*funcDll)(string, string); funcDll Concat = (funcDll)GetProcAddress(hLib, "Concat"); if (Concat == NULL) { cout << "Unable to load Concat." << endl; system("pause"); return; } cout << Concat("a", "b") << endl; /*----функция GetFirst----*/ typedef int (*function2Dll)(vector<int>); // собственно здесь GetFirst и не находится, она равна NULL function2Dll GetFirst = (function2Dll)GetProcAddress(hLib, "GetFirst"); if (GetFirst == NULL) { cout << "Unable to load GetFirst." << endl; system("pause"); return; } vector<int> Vec; Vec.push_back(1); Vec.push_back(2); Vec.push_back(3); cout << GetFirst(Vec) << endl; system("pause"); }
Ваше имя:
Пароль:
Цитировать Используйте тэги для выделения текста: Код: [code][/code] Жирный: [b][/b] Наклонный: [i][/i] URL: [url][/url]
Сообщение:
Прикрепить: