Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > How to force a program to use DLL in App.Path


Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2004, 12:28 PM
Taz Taz is offline
Regular
 
Join Date: Mar 2003
Location: Canada
Posts: 70
Question 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
Reply With Quote
  #2  
Old 03-16-2004, 02:27 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

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.
Reply With Quote
  #3  
Old 03-16-2004, 03:34 PM
Taz Taz is offline
Regular
 
Join Date: Mar 2003
Location: Canada
Posts: 70
Default

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
Reply With Quote
  #4  
Old 03-16-2004, 08:25 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

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.
Reply With Quote
  #5  
Old 03-17-2004, 05:47 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Simply place this line before the first call to any DLL functions:

Code:
ChDir App.Path
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #6  
Old 03-18-2004, 12:49 PM
happyboy happyboy is offline
Freshman
 
Join Date: Sep 2003
Posts: 47
Default

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...
Reply With Quote
  #7  
Old 03-18-2004, 01:15 PM
Taz Taz is offline
Regular
 
Join Date: Mar 2003
Location: Canada
Posts: 70
Default

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
Reply With Quote
  #8  
Old 03-18-2004, 01:39 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

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.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #9  
Old 03-19-2004, 02:47 AM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

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.
Reply With Quote
  #10  
Old 03-19-2004, 03:06 AM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

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.
Reply With Quote
  #11  
Old 04-08-2004, 11:59 PM
Ark Ark is offline
Newcomer
 
Join Date: Sep 2003
Posts: 22
Default

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
lifting by your bootstraps: can I make a no-DLL vb program? Glade General 2 11-04-2003 09:24 AM
Connecting DLL and main program goosta General 0 07-01-2003 09:48 AM
call another program and obtain status code after program is closed cosito7777 General 1 01-06-2003 02:55 PM
The setup program doesn't rewrite the dll files if exists a previous version of them ejanakieff Installation / Documentation 3 10-07-2002 01:13 AM
VB Program AND DLL giang General 4 09-28-2001 03:08 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->