DLL Not Found

Is there any way to not have to copy the DLL my C++ program uses (and is linked to) to the system32 folder? Why won't it run even when the DLL is right next to the EXE that uses it? If there is a solution, here is my code to modify:

Prog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include "dll.h"          // DLL Header

using namespace std;

int main()
{
    SetColor(10); // Function inside the DLL
    cout << "Hello world!";
    system("PAUSE>NUL");
}


dll.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef CT_DLL_H
#define CT_DLL_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef BUILDING_CT_DLL
#define CT_DLL __declspec(dllexport)
#else
#define CT_DLL __declspec(dllimport)
#endif

void SetColor(unsigned short color);

#ifdef __cplusplus
}
#endif

#endif 


Suggestions?
Last edited on
It should work when the DLL is in the working directory. Make sure you are executing it so that its working directory is the directory it itself is in.
Visual Studio? Place the .dll file in the same folder as all your code.
Topic archived. No new replies allowed.