我希望将我的DLL放在可执行文件所在目录的子目录中。我当前的目录如下:
Main Folder: [Folder]
Program.exe
sfml.dll
Assets [Folder]
Picture.png
Music.wav
当我真的希望它看起来像:
Main Folder: [Folder]
Program.exe
Assets [Folder]
Picture.png
Music.wav
MyDlls[Folder]
sfml.dll
当我尝试将它们(DLL)放在一个文件夹中时,我收到错误消息:
程序无法启动,因为您的计算机缺少sfml-system-d-2.dll。尝试重新安装该程序以解决此问题。
所以,然后我查看了显式链接,并按照这里的教程: http://www.dreamincode.net/forums/topic/118076-dlls-explicit-linking/
如果显式链接不是我需要使用的,那么请告诉我我需要做什么。另外,请告诉我下面的代码有什么问题:(另外,我不知道这是静态还是动态链接...... ??)
// Startup.h
#ifndef STARTUP_H
#define STARTUP_H
#include <iostream>
#include <windows.h>
class Startup
{
private:
HINSTANCE hDLL;
public:
// Explicitly link SFML DLL's
typedef int(*funcAdd) (int, int);
typedef int(*funcSubtract) (int, int);
void LoadDLLs()
{
// Retrieve DLL handle.
vector<LPCSTR> libraries = {"openal32.dll",
"sfml-audio-2.dll",
"sfml-audio-d-2.dll",
"sfml-graphics-2.dll",
"sfml-graphics-d-2.dll",
"sfml-system-2.dll",
"sfml-system-d-2.dll",
"sfml-window-2.dll",
"sfml-window-d-2.dll"};
for (int i = 0; i < libraries.size(); i++)
{
hDLL = LoadLibrary(libraries[i]);
if (hDLL == NULL)
{
std::cout << "Failed to load library.\n";
}
else
{
funcAdd Add = (funcAdd)GetProcAddress(hDLL, "Add");
funcSubtract Subtract = (funcSubtract)GetProcAddress(hDLL, "Subtract");
if (Add)
std::cout << "10+10=" << Add(10, 10) << std::endl;
if (Subtract)
std::cout << "50-10=" << Subtract(50, 10) << std::endl;
FreeLibrary(hDLL);
}
std::cin.get();
}
};
#endif
答案 0 :(得分:1)
您可以注册App Path (see link),确保将应用程序备用DLL文件夹位置添加到应用程序路径PATH值。
答案 1 :(得分:0)
你无法直接做你想做的事。您附加的代码仅适用于动态加载dll,但情况并非如此。
您想要做的是特定于平台的,您需要在执行程序之前设置库的路径。