I have a program and it worked just fine, but when I compiled my MainDLL.dll
file, my program won't find it. It returns (0x7E)
(The specified module could not be found). The .dll
file is in the same folder as the .exe
file. But when I tried to open a different .dll
file from the same folder, it works just fine.
The main entry program code looks like this:
#include "WinMain.hpp"
int APIENTRY wWinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst,
_In_ LPWSTR lpCmdLine, _In_ int nShowCmd) {
dbg::SetDebugState(true);
mf::InitMF(L"MainDLL.dll");
int iResult = mf::MainFunc(hInst, hPrevInst, lpCmdLine, nShowCmd);
mf::UninitMF();
return iResult;
}
It runs my .lib
library that should load the MainDLL.dll
file via mf::InitMF(L"MainDLL.dll");
function call.
The .lib
library code looks like this:
#include "../Libs/MainLib.hpp"
mf::MainFuncPtr mf::MainFunc = nullptr;
namespace __mf {
HMODULE hmLib = nullptr;
}
void mf::InitMF(LPCWSTR Path) {
HRESULT hr = 0l;
__mf::hmLib = LoadLibraryW(Path);
if (__mf::hmLib == nullptr) {
hr = (HRESULT)GetLastError();
dbg::ErrorWnd(L"load main dll func error", L"Chyba", hr, __LINE__, __FILEW__);
ExitProcess(13u);
}
mf::MainFunc = (mf::MainFuncPtr)GetProcAddress(
__mf::hmLib, "__MainFunc");
if (mf::MainFunc == nullptr) {
hr = (HRESULT)GetLastError();
dbg::ErrorWnd(L"get main proc error", L"Chyba", hr, __LINE__, __FILEW__);
ExitProcess(13u);
}
}
void mf::UninitMF(void) {
FreeLibrary(__mf::hmLib);
}
Since any other .dll
file loads just fine, I think it's something with the MainDLL.dll
file, but when I compile it, it compiles without any problem.
Last thing I did in MainDLL.dll
was that I included my other DLL for drawing using D2D1, and after that I cannot load it.
I am using Microsoft Visual Studio 2022.
Since any other
.dll
file loads just fine, I think it's something with theMainDLL.dll
file... Last thing I did inMainDLL.dll
was that I included my other DLL for drawing using D2D1, and after that I cannot load it.
This is likely the root of your problem. It is not that MainDLL.dll
itself can't be found, as you claim, but rather that another DLL that MainDLL.dll
depends on can't be found. Make sure all relevant DLLs are in your EXE's folder (or at least on the system search path).