Witam, mam taki o to problem:
Importuje DLL do programu, mam w niej 3 funkcję które przy wywoływaniu wyrzucają błąd
Kod:
DLL:
// PlanyLekcji.h
#pragma once
#ifdef PLANYLEKCJI_EXPORTS
#define PLANYLEKCJI_API __declspec(dllexport)
#else
#define PLANYLEKCJI_API __declspec(dllimport)
#endif
#undef min
#undef max
#include <iostream>
#include <SFML/Graphics.hpp>
// EXPORT PLUGIN
extern "C" PLANYLEKCJI_API int TEST();
extern "C" PLANYLEKCJI_API sf::RenderTexture* initPlugin(int width, int height);
extern "C" PLANYLEKCJI_API void update();
// PlanyLekcji.cpp
#include "stdafx.h"
#include "PlanyLekcji.h"
sf::RenderTexture *screen = nullptr;
int width, height;
int TEST() {
return 16;
}
sf::RenderTexture* initPlugin(int width, int height)
{
std::cout << "createPlugin()" << std::endl;
screen = new sf::RenderTexture();
screen->setSmooth(true);
screen->create(width, height);
return screen;
}
void update()
{
sf::RectangleShape bg;
bg.setSize(sf::Vector2f(width, height));
bg.setFillColor(sf::Color::Blue);
screen->draw(bg);
}
Moja aplikacja:
// Globalnie
typedef int(_stdcall *TEST)();
typedef sf::RenderTexture*(__stdcall *plugin_init)(int, int);
typedef void(__stdcall *plugin_update)();
// W definicji klasy
plugin_init init = nullptr;
plugin_update update = nullptr;
HINSTANCE DLL = nullptr;
bool SingleSlide::loadFromJSON(JSON j)
{ /* NIE WAŻNE W PROBLEMIE
try {
this->json = j;
this->title = j["title"];
this->author = j["author"];
this->date = j["date"];
this->duration = j["duration"];
this->arg = j["arg"];
if (json["type"] == "TEXT")
this->type = Type::TEXT;
else if (json["type"] == "PLUGIN") {
this->type = Type::PLUGIN; */
std::cout << "Loading " << arg << "..." << std::endl;
std::string pluginPath = "plugins/" + arg;
DLL = LoadLibrary(pluginPath.c_str());
if (!DLL) {
std::cout << "Cannot load " << pluginPath << std::endl;
return false;
}
this->init = (plugin_init)GetProcAddress(DLL, "initPlugin");
this->update = (plugin_update)GetProcAddress(DLL, "update");
if (!init || !update) {
std::cout << "Could not locate all plugin funcions. (init: " << init << ") (update: " << update << ")" << std::endl;
return false;
}
std::cout << "TEST: " << TEST(GetProcAddress(DLL, "TEST"))() << std::endl;
}
/* NIE WAŻNE W PROBLEMIE
}
catch (JSON::exception &e) {
std::cerr << e.what() << std::endl;
return false;
} */
return true;
}
Kod powyżej działa bez zarzutów oraz wyświetla TEST: 16
ALE
Kiedy wykonuję się ta intrukcja, już po wywołaniu loadFromJSON()
this->screen = this->init(1280, 720);
i późniejszym używaniu screen
dostaję błąd:
Exception thrown: Access violation executing location 0x0F4913FC.
Moje pytanie brzmi: dlaczego?
Obstawiam że to dlatego że nie wolno mi zapisać i potem używać adresu sf::RenderTexture ale w takim razie jak wykonać system pluginów, które będą coś dla mnie rysować, a ja potem będe to coś wyświetlał?