Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Respected reader,

We developed a project using the MFC Appwizard. A project contains 80 .cpp files and .h files.
The Project was so big and hard to maintain and also build.
So according to the suggestion of Andrew Brok (author of code project) we break up whole project into small .dll project. We used technique of static __declspec(dllexport).


Now the project is sorted into small .dll projects but the number of .dll files has increased. So while creating the setup, all the .dll files must be present in the current .exe folder project or sytsem32/ folder.

If we want all dll in separate folder /dll.

It's not working. While the application running has an error that says "-----.dll not fount please reinstall application."

I have also tried SelDllDirectory() function but its gives an error: function not found. Then I included the file window.h for the given function and it gives an error on Windows 2003 server.


Please help us for separation of dll files from project
Posted
Updated 22-Feb-11 13:05pm
v3
Comments
Dalek Dave 22-Feb-11 19:05pm    
Edited for readability.

santoshmaruti wrote:
I have also tried SelDllDirectory() function but its gives an error: function not found.

The function's name is SetDllDirectory[^], anyway it is helpful just for explicit DLL loading (i.e. via LoadLibrary).

You might be interested in Dynamic-Link Library Search Order[^] and in Dynamic-Link Library Redirection[^].
:)
 
Share this answer
 
Comments
[no name] 21-Feb-11 22:20pm    
can you give me another simple method for implementation
CPallini 22-Feb-11 2:56am    
The easiest way is putting the DLLs in the same folder your executable is.
Espen Harlinn 25-Feb-11 8:23am    
That's good advice if he doesn't want to modify the PATH environment variable
[no name] 22-Feb-11 3:22am    
That exactly i doesn't want.

if my application folder is \MyApp\SELPRO.exe

then

i want to make saparate folder called MyApp\DLL\
and in this folder i want to keep all dlls

please can you gives any clue on this.
CPallini 22-Feb-11 4:30am    
This link http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/3e82b658-e070-4b88-aaf2-0649ddb222d2 may interest you.
A simple solution is to just add your dll directory to the system path.
 
Share this answer
 
Comments
Hans Dietrich 21-Feb-11 13:14pm    
Unless you're dealing with a tightly-controlled in-house app, this is almost always a bad idea. Also bad is putting DLLs in system32. Application DLLs should be put in the app's directory. If you pollute the system path or system32 with non-system DLLs, you could easily end up with a destabilized system with random app crashes. Don't do it. Microsoft says not to.
[no name] 22-Feb-11 3:41am    
I'm not thinking of placing dll in system32 and i also not want dll in current application folder
i want dll from saparate dll folder please note and gives reply
Ok there are a number of issues with your approch.

1. You stated that the number of dlls have increased. I have it is not by magnitude. Maybe you have created a bunch of them, not more.
2. Please don't install your dlls into System files. That is not the solution and you will run into a problem.
3. I don't understand what is the issue placing your dlls with your .exe file. Not only it simplifies your install it will prevent you from headaches down the line.
4. Finally, if you want to install then in separate folder, I want you to ask yourself why does it work if your put it in the system directory. The simple answer is because it is in the search path. When your dll needs to be loaded there are a number of places the loader looks before it gives up.

So, the short answer is you need to add the folder in which your dll resides into the system path.

Open command window and type path. what do you see? that is your secret ingredient. Your install needs to append the full path into the PATH
 
Share this answer
 
Comments
[no name] 22-Feb-11 3:26am    
Can give more information about PATH variable
Yusuf 22-Feb-11 8:59am    
Look here http://vlaurie.com/computers2/Articles/environment.htm

Of course you will need to do it programmability . I don't know how you are installing your application, so that makes it hard to suggest a way.
Respected all

Here I want more modulation in project.

when i tries my project on PC that doesn't have visualstudio.then we must add All required dll of the Visualstudio like
msvcr71.dll,msvcp71d.dll etc.
but i want to keep my dll in saparate folder.
please provide any method that runs on
windowserver 2003
and Visual studio 2003
used of RegSvr32.exe not uderstand.
 
Share this answer
 
Comments
SenAPI 22-Feb-11 8:10am    
"Use MFC in a Static Library" option to avoid distributing msvcr71.dll,msvcp71d.dll
In your case no need to register DLL using RegSvr32.exe because it is not a COM dll.
[no name] 28-Feb-11 0:24am    
Thanks but i don't have problem with msvcr71.dll,msvcp71d.dll
i just want saparation of own dlls
I think you should load the dlls by your own.
Take a look:
unsigned int scopy(TCHAR* dst,const unsigned int len,const unsigned int pos,const TCHAR* cat)
{
  unsigned int  i,n = min(len-1,pos+_tcslen(cat));
  for(i=pos;i<len;i++) dst[i]=cat[i-pos]; dst[i]=0;
  return i;
}

HINSTANCE DllLoad(const TCHAR* dll,const TCHAR* dllpath=__TEXT("DLL\\"))
{
  TCHAR          mod[MAX_PATH];
  unsigned int  len = GetModuleFileName(__hinst,mod,sizeof(mod)/sizeof(mod[0]));
  for(;(0<len)&&('\\'!=mod[len-1]);len--);
  len = scopy(mod,sizeof(mod)/sizeof(mod[0]),len,dllpath);
  len = scopy(mod,sizeof(mod)/sizeof(mod[0]),len,dll);
  return LoadLibrary(mod);
}

int FAR PASCAL WinMain(HINSTANCE h,HINSTANCE p,LPSTR c,int sw)
{
  __hinst = h;

  HINSTANCE  hdll = DllLoad(__TEXT("first.dll"));
  if(32<(unsigned int)hdll)
  {
    void (FAR PASCAL *myfunc)() = (void (FAR PASCAL *)())GetProcAddress(hdll,"first_func");
    myfunc();
    FreeLibrary(hdll);
  }
  return 42;
}
 
Share this answer
 
Comments
[no name] 28-Feb-11 0:10am    
have you implement this because editing winmain in mfc is hard speciallly when we used AppWizard
mbue 28-Feb-11 6:43am    
this is an example how to do that. i only posting code thats fully working (no useless fragments). i think, if you're using mfc and import your dlls by import library all this dont work.
The best way to do this is:
* make your dlls
* export the needed functions
* better you make interfaces of your code
* load the dlls manually (as shown above)
why is this the best way - using interfaces or exported functions?
* you never must recompile the other code on changes
encapsulate the load library into a small class you can use everywhere. indeed you should not make the loading in winmain you can do it in InitInstance of your application. And freelibrary at ExitInstance - thats the same.
[no name] 1-Mar-11 2:39am    
thanks but its not uderstandable
Hey,
May I know the reason for the seperate folder for dlls. You better add the dll's in your exe folder or to the system folder. Or I shall say a method which I think may be of some help to you.
Try the following steps:

HINSTANCE hDLL = AfxLoadLibrary(Path Name);
lpLoadDll = (LPLOADDLL) GetProcAddress ( hDLL, Fn Name);
lpLoadDll();
AfxFreeLibrary(hDLL);
 
Share this answer
 
Comments
[no name] 28-Feb-11 0:12am    
Thanks for reply dear but i doesn't want dll in same folder or in system folder i want in saparate dll folder.
and above method not working i also tries it.

plese can you give me more advice on this.
Hi santoshmaruti,

If you are placing all the dll in System32 or Application folder it will work fine as you said, because your application exe will find that dll in this folder. ( By default your application exe will search required dll in your application folder and System32 folder)

But,If you are placing required Dll into seprate file then you have to register them using RegSvr32.exe. So your application will get the required dll.

I recommend you to register all require dll in last phase of application installation.
 
Share this answer
 
Comments
CPallini 21-Feb-11 7:58am    
regsvr32 is a tool for registering/unregistering COM DLLs.
[no name] 21-Feb-11 22:18pm    
cant understand about RegSrv32.exe

i want saparate dll folder in my application folder thats it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900