however, i don't see the changes on screen, that was made in the code.
I want it to reload during runtime.
If i restart the app the changes work, so the problem is just that it doesn't reload during runtime.
I am also using a 3rd party lib (SFML)
any ideas why this problem might occur?
CJsfml_002.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #define SFML_STATIC #define WIN32_LEAN_AND_MEAN #include <windows.h> #include "SFML\Graphics.hpp" #include <iostream> float vel = 7.0f; typedef void (*rectFP)(sf::RectangleShape *); int main() { sf::RenderWindow window(sf::VideoMode(960, 540), "SFML works!"); window.setFramerateLimit(60); sf::RectangleShape mRect(sf::Vector2f(40.0f, 40.0f));; mRect.setPosition(sf::Vector2f(30.0f, 30.0f)); mRect.setFillColor(sf::Color::Green); // Getting pointer to the rect sf::RectangleShape *rect = &mRect; while (window.isOpen()) { int count = 125; // Loading DLL CopyFile("gameCode.dll", "temp_gameCode.dll", false); HMODULE hm = LoadLibrary("temp_gameCode.dll"); if(hm) { std::cout << "LOAD LIB SUCCESS!\n"; } // Loading DLL function rectFP rfp = (rectFP)GetProcAddress(hm, "CreateRect"); if(rfp) { std::cout << "load func SUCCESS!\n"; } // Using the DLL function rfp(rect); } // Unloads DLL FreeLibrary(hm); sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); // Drawing the rect that was changed by the DLL-function window.draw(*rect); window.display(); } return 0; } |
gameCode.h
1 2 3 4 5 6 7 | #define SFML_STATIC #include "SFML\Graphics.hpp" extern "C" { __declspec(dllexport) void CreateRect(sf::RectangleShape *RS); } |
gameCode.cpp
1 2 3 4 5 6 7 8 | #include "gameCode.h" __declspec(dllexport) void CreateRect(sf::RectangleShape *RS) { RS->setSize(sf::Vector2f(100.0f, 200.0f)); RS->setFillColor(sf::Color::Blue); RS->setPosition(sf::Vector2f(100.0f, 100.0f)); } |
build.bat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | @echo off :: IMPORTANT! "=" has to come IMMEDIATLEY after VARIABLE NAME SET compilerSwitches= /MD /EHsc -Zi -nologo SET winLibs= user32.lib gdi32.lib winmm.lib Opengl32.lib ws2_32.lib advapi32.lib SET sfmlDependLibsX64= /LIBPATH:"C:\SFML\SFML-2.5.1_x64\lib" freetype.lib openal32.lib flac.lib vorbisenc.lib vorbisfile.lib vorbis.lib ogg.lib SET sfmlDependLibsX86= /LIBPATH:"C:\SFML\SFML-2.5.1_x86\lib" freetype.lib openal32.lib flac.lib vorbisenc.lib vorbisfile.lib vorbis.lib ogg.lib SET sfmlLibsX64= sfml-system-s.lib sfml-graphics-s.lib sfml-window-s.lib sfml-audio-s.lib sfml-network-s.lib SET sfmlLibsX86= sfml-system-s.lib sfml-graphics-s.lib sfml-window-s.lib sfml-audio-s.lib sfml-network-s.lib If NOT EXIST ..\buildx64 mkdir ..\buildx64 If NOT EXIST ..\buildx86 mkdir ..\buildx86 If NOT EXIST ..\assets mkdir ..\assets pushd ..\buildx64 cl %compilerSwitches% /I ..\include ..\src\CJsfml_002.cpp %winLibs% /link %sfmlDependLibsX64% %sfmlLibsX64% cl %compilerSwitches% /I ..\include ..\src\gameCode.cpp /LD %winLibs% /link %sfmlDependLibsX64% %sfmlLibsX64% popd @echo x64 build Done! ::------------------ x86 BUILD (set vcvarsx86) ----------------- ::pushd ..\buildx86 ::cl /MD /EHsc -Zi -nologo /I ..\include ..\src\CJsfml_002.cpp %winLibs% /link %sfmlDependLibsX86% %sfmlLibsX86% ::popd :: ::@echo x86 build Done! del *.~ *.cpp~ *.bat~ *.un~ *.h~ |