 |
 |

03-16-2004, 12:28 PM
|
|
Regular
|
|
Join Date: Mar 2003
Location: Canada
Posts: 70
|
|
How to force a program to use DLL in App.Path
|
I'm trying to run my program that I made from Windows XP, in Windows 98. When I do it doesn't work properly because 98 is using an older version of msimg32.dll than XP was. I replaced the file with the newer one but then Windows got mad at me and said I screwed up msimg32, so I had to put the old one back. I put a copy of the new msimg32 right in the program directory so the program would use it instead, but then it seems to get confused that they are two of this file and says that it can't find it ...? I tried putting Lib App.Path + "msimg32.dll" in the Declare statement but it won't let me. How can I get this to work?
|
__________________
Taz
|

03-16-2004, 02:27 PM
|
 |
Martian In Disguise
Retired Moderator * Guru *
|
|
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
|
|
You can hardcode the path in the Lib argument of the API declarations, but I don't think that you can assign this dynamically.
For example:
Code:
Private Declare ... Lib "C:\Foo\msimg32.dll" ...
|
__________________
The only stupid question is the one that goes un-asked.
|

03-16-2004, 03:34 PM
|
|
Regular
|
|
Join Date: Mar 2003
Location: Canada
Posts: 70
|
|
|
Yes,
But I'm going to give this program to some different people and I want them to be able to put it wherever they want... isn't there any way to do this?
|
__________________
Taz
|

03-16-2004, 08:25 PM
|
 |
Martian In Disguise
Retired Moderator * Guru *
|
|
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
|
|
|
The only other way that I know of is to place the DLL file in a directory that is in the PATH of the computer that it is running on and make sure that the directory appears in the PATH before the System or System32 directories.
The Lib argument of an API prototype cannot be made dynamic by using a variable value to specify the path to the library.
|
__________________
The only stupid question is the one that goes un-asked.
|

03-17-2004, 05:47 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Simply place this line before the first call to any DLL functions:
|
|

03-18-2004, 12:49 PM
|
|
Freshman
|
|
Join Date: Sep 2003
Posts: 47
|
|
I have the same problem but with a slight difference...
My program uses Flash.ocx that exists in WinXP... on Win98 when I run the program (though Flash.ocx is in Application path) the program tries to use SWFLASH.ocx and makes an illegal error..
actually I didn't place any code for the flash object I just put it on the form the same we put a textbox(I mean I didn't make a call to a Dll)...
another thing. "Squirm" said that I should place the ChDir before the Dll call.I have some questions about that:
1- Does the ChDir make the program use App.path for Dlls then(if not found) the system directory or it makes the program use only Dlls in App.path (and if not found an error occurs)??
2- if I'm using an OCX as I've already mentioned where should I place the ChDir code??
3- if the answer to the 1st question is that the program uses only Dlls in App.path how can swich the directory back to original after using ChDir(so I can call the system Dlls)??
the summary of these questions is that I want the program to use flash.ocx in the app.path on win98... 
|
|

03-18-2004, 01:15 PM
|
|
Regular
|
|
Join Date: Mar 2003
Location: Canada
Posts: 70
|
|
|
00100b, I put the DLL in C:\ (root). Is that what you meant by "before" the system directory? - it hasn't made any difference.
Squirm, I tried what you said - I put that line right before where it calls the API in msimg32.dll... but it just acts the same as it does without it.
Does anyone have any more ideas? ...I'm thinking I'm just going to hardcode it and tell everyone where to put it.
|
__________________
Taz
|

03-18-2004, 01:39 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Strange, I guess VB's DLL loading procedure is not the same as that of LoadLibrary which searches both the application directory and the current directory before the system directory.
However, be that as it may, I can only really think of a workaround, not a solution. That would be to rename the DLL. Then, if you do what I suggested in my last post, it should definitely work, if the DLL name is unique.
Of course, I don't know what you're using it for, but it seems plausible that the newer version of msimg32.dll is being loaded, but it just acts like the older one because it is on the older OS. This would be quite trivial to test for using GetModuleHandle and then GetModuleFileName.
|
|

03-19-2004, 02:47 AM
|
 |
Algorithms 'R' Us
Forum Leader * Guru *
|
|
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
|
|
Quote: Originally Posted by Squirm Strange, I guess VB's DLL loading procedure is not the same as that of LoadLibrary which searches both the application directory and the current directory before the system directory.
Hmm, I'm not sure I'd go along with that ........
BTW: I saw "XP" mentioned somewhere above, and I've heard somewhere that XP takes some liberties with the DLL search order we know and love
I found this link: http://msdn.microsoft.com/library/de...re06122003.asp Check out this paragraph:
DLL Search Order Has Changed
No longer is the current directory searched first when loading DLLs! This change was also made in Windows XP SP1.
|
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!
At first, I was iridescent. Then, I became transparent. Finally, I was absent.
|

03-19-2004, 03:06 AM
|
 |
Algorithms 'R' Us
Forum Leader * Guru *
|
|
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
|
|
|
I believe that the non-standard search order on Win XP and Win Server 2003 I mentioned above can be reverted to the normal order by changing the "SafeDllSearchMode" flag in the Registry - it defaults to "1", which causes the non-standard order to be used - by changing it to "0" you should get the normal order that you get on other systems
|
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!
At first, I was iridescent. Then, I became transparent. Finally, I was absent.
|

04-08-2004, 11:59 PM
|
|
Newcomer
|
|
Join Date: Sep 2003
Posts: 22
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|