views:

1619

answers:

5

I want to put my dependent files in the app directory.

I seem to remember that you can force VB6 to use the files in the local directory only.

Any hints?

+2  A: 

Found it myself:

Windows does look in the App Directory first: If SafeDllSearchMode is enabled, the search order is as follows:

  1. The directory from which the application loaded.
  2. The system directory. Use the GetSystemDirectory function to get the path of this directory.
  3. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
  4. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  5. The current directory.
  6. The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.

If SafeDllSearchMode is disabled, the search order is as follows:

1. The directory from which the application loaded. 2. The current directory. 3. The system directory. Use the GetSystemDirectory function to get the path of this directory. 4. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. 5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 6. The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.

according to : http://msdn.microsoft.com/en-us/library/ms682586.aspx

But you can redirect where it looks for .dll's using a Manifest:

http://msdn.microsoft.com/en-us/library/aa375365(VS.85).aspx

Clay Nichols
+4  A: 

It can be sort of confusing because every version of windows, the rules change. Older versions of Windows search the path before the current directory.

A simple solution without manifests:

If your executable file is A.EXE, add a (0-byte, empty) file in the same directory named A.EXE.local -- for older versions of Windows this puts the app directory ahead of the path in the search order.

Joel Spolsky
This is the correct answer on Win2k+.Please be aware, however, that if A.EXE has an embedded manifest, or if A.EXE.manifest exists (such as to enable reg-free COM, make your program DPI aware, etc), the .local file is ignored, as manifests are meant to be a replacement technology.If that is the case, in your manifest, you can simply list the files that you want to be used from your app directory to force them to be loaded from there:<file name="my.dll" />
Eugene Talagrand
+7  A: 

You may also want to try setting up Reg-Free COM for your project. There's a freeware called Make My Manifest that will do most of the work for you

rpetrich
+2  A: 

Clay Nichol's answer about the search order is not quite correct. That search order only applies to non-COM components. I.e. only some DLLs, and not OCXs. If you register your COM objects, they will be used from the directory where they are registered regardless of what's in the local directory, unless you use reg-free COM or a .local file.

EDIT:

MakeMyManifest is well spoken of as an automatic tool for creating manifests for VB6 projects, haven't tried it myself. DirectCOM also has fans, again I haven't tried it.

There is a semi-automatic technique to generate reg-free COM manifests. You can create the manifests with Visual Studio 2008 (you can use a free version like Visual Basic Express Edition). Then make a couple of edits by hand to make the manifests suitable for use from VB6. See this section of this MSDN article for step-by-step instructions - ignore the rest of the article which is about ClickOnce.

MarkJ
+3  A: 

Placing component libraries in the EXE folder (with or without .local files) can be deleterious to the hygiene of target machines too.

VB6 programs will register the components here via the self-reg entrypoint behind your back if they are not previously registered. Then if the application is moved or removed you leave the user with a broken reigistration - possibly fatal to subsequently installed applications using some of the same components. This is probably fine though for application specific components, i.e. your own DLL or OCX that will never be needed by another application.

The .local trick was really not meant for use with VB6 programs and if it is used your installer needs to be aware and properly install and register the components if they are not already on the machine. It was meant as a manual hack to get around DLL version compatibility problems on individual machines, not a deployment strategy.

Move up to SxS application and assembly manifests (Reg-Free COM and more) for a better solution. DLL/COM Redirection (.local) was a good try but it has many warts.

Bob