DLL in diferent directory

Started by
7 comments, last by pjcast 19 years, 4 months ago
Yes, I have searched, and I found stuff about LoadLibrary() and FreeLibrary().... Here is my code:

#include <windows.h>
#include "gamex86/CGame.h"

#pragma comment(lib, "gamex86.lib")

using namespace Narcotik;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)	{
	char szBuff[MAX_PATH+64];

	GetModuleFileName(NULL,szBuff,MAX_PATH);
	char* psz = strrchr(szBuff,'\\');
	if(psz) psz[1] = '\0';
	strcat(szBuff,"/base/gamex86.dll");

	HMODULE hm = LoadLibrary(szBuff);

	CGame game;
	game.run();

	FreeLibrary(hm);
	return 0;
}

But I still get "cannot find DLL gamex86.dll" message.... Waht have I done wrong?
Advertisement
Interesting. Try replacing / with \\.

Kuphryn
nope, that didnt work

but thanks for the suggestion!
Try to replace
strcat(szBuff,"/base/gamex86.dll");

with
strcat(szBuff,"base\\gamex86.dll");
Society's never gonna make any progress until we all learn to pretend to like each other.
"\" is an escape character, which means whatever cmoes after it is treated as ascii and not some inbuilt command, so \\ will result in compiler putting in \ ...
I'm sure he knows that, I do as well... I just wanted to remove the initial slash.

Also, try putting MessageBox(NULL, szBuff, NULL, 0); before loading the library, it will show you the exact path it's trying to load it from. Maybe you'll see what's wrong this way.
Society's never gonna make any progress until we all learn to pretend to like each other.
I did strcat(szBuff,"base\\gamex86.dll"); and the directory shows up the way it is supposed to be on the MessageBox()

But it still doesnt work?
strcat(szBuff,".\\base\\gamex86.dll");

Who knows? :)
You appear to be linking to that dll statically:
#pragma comment(lib, "gamex86.lib")

In which case you cannot change the path. It must be in the working directory or system directories, or path directories.

edit - Remove that line and just load the dll dynamically.

This topic is closed to new replies.

Advertisement