Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

Current Directory in ActiveX EXE?

Hi.  I'm writing an ActiveX EXE in VB 6.0 that will be instantiated as an out-of-process COM server by a C++ application.  The VB EXE loads some graphics files during initialization.  This works fine in debug mode -- it looks for the graphics files in the project directory.  But when I start it up as an ActiveX object from the client, it can't find the graphics files -- I guess the current directory is no longer the project directory, which makes sense.

What's the most elegant and/or easy way to allow my ActiveX EXE to find the graphics files when invoked as a server?  The files will be installed along with the component, but I don't want to hard-code the location.  Hopefully this is a dumb question and I'm overlooking something simple.

Thanks for the help.
0
riceman0
Asked:
riceman0
2 Solutions
 
Erick37Commented:
The best way to add pictures (and other static data) to an application is to add a resource file to your project.  You can load bitmaps, strings, etc, into the res file and add it to your project using Project->Add File.  Resource files are created using ResEdit and saved with the file extension .res.

Once attached to your project, retrieve the bitmaps using the LoadResPicture call.  Note that only BMP, icon, and cursor picture formats are supported directly.  Other picture formats (jpg, gif) must be saved as binary data and retrieved using LoadResData.

For more help, ask here or search help for "loadrespicture" or "resource files"

References:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconresourcefiles.asp

Hope it helps!
0
 
David LeeCommented:
This may not be the most elegant way, but it is very simple and flexible.  Store the location of the graphics files either in the registry or in an ini file and have the process read the location in when it runs.
0
 
aParserCommented:
I think I'd prefer BlueDevilFan's approach, although if I were going to use Erick37's method, I would probably compile the resources into a seperate ActiveX DLL so that I could replace them easily.

If you're still interested in the directory issue, you might look at this DevX tip
http://www.devx.com/vb2themax/Tip/18377
as well as http:Q_21103227.html
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
riceman0Author Commented:

The problem with the INI is that the user can install it wherever he wants and I'd have to write a script to tailor the INI -- too much work.  I was not aware of the resource editor add-in for VB, that sounds great I will try to use that.

Out of curiosity aParser, why is an ActiveX DLL easier in this case than a resource file?

0
 
aParserCommented:
Well, you can't have a stand-alone resource file, per se.  Resources have to be compiled into something.  You *could* compile them into your ActiveX EXE, but then if you wanted to change your graphics, you would have to recompile your ActiveX EXE and redistribute.  And it may not be a big issue in your case, but in my environment, the users usually have the application that uses the ActiveX EXE up and running almost all the time -- meaning that the ActiveX EXE is in-use and won't allow you to replace it until you shut down the application.

If, on the other hand, you compile your resource file into an seperate ActiveX component, you should be able to replace that component as long as your application isn't in the middle of loading one of the resources.  As far as it being a DLL, I just prefer DLLs because of the relative size -- and resources are typically in DLLs by convention, rather than in EXEs.
0
 
Erick37Commented:
>>resources are typically in DLLs by convention, rather than in EXEs

Most exe applications have resources within the executable.  That is where the icons, custom cursors, menu bitmaps, string constants, etc. live.

If you have many large bitmaps then you may consider storing them in a separate file or DLL.  Or, as aParser pointed out, if you have the need to modify your graphics often, locating them outside the exe may be more convenient.

The bottom line is, once the resources are compiled inside your exe, you can access them directly and you do not have to worry about where they are located on disk.  If you opt to place the resources inside a separate DLL, there is a little more overhead involved in retrieving them, but if the DLL is registered correctly you will always be able to locate it.

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now