Can't load DLL using LoadLibrary

I use this code, and it doesn't load the DLL for some reason

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
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
bool initdll();

bool main ()
{
	if ( initdll() == true )
	{
		std::cout << "Server started!" << std::endl;
	}
	else
	{
		std::cout << "DLL not found" << std::endl;
		return false;
	}
	while ( 1 == 1 )
	{
		std::cout << "..." << std::endl; // preform other dll releted actions
	}
}

bool initdll()
{
        HINSTANCE hInst = LoadLibrary("C:\\Users\\Joshua\\Documents\\Visual Studio 2008\\Projects\\server\\Debug\\39dll.dll")
	if( hInst != NULL )
        {
		FreeLibrary( hInst ); // temporary
		return true;
	}
	else
	{
		return false;
	}
}


It gives an error message saying:
.....server\main.cpp(26) : error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [77]' to 'LPCWSTR'
Last edited on
I really need this working
add #undef UNICODE before including windows.h or use _T macro:
1
2
3
// ...
HINSTANCE hInst = LoadLibrary(_T("C:\\Users\\Joshua\\Documents\\Visual Studio 2008\\Projects\\server\\Debug\\39dll.dll"));
//... 


EDIT: main should return int ( int main() )
Last edited on
Thanks man, it works :D
Topic archived. No new replies allowed.