Solved

Current Directory in ActiveX EXE?

Posted on 2004-09-13
6
313 Views
Last Modified: 2012-08-13
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
Comment
Question by:riceman0
6 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 75 total points
ID: 12050569
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
 
LVL 76

Expert Comment

by:David Lee
ID: 12050580
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
 
LVL 3

Assisted Solution

by:aParser
aParser earned 50 total points
ID: 12054037
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:riceman0
ID: 12060217

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
 
LVL 3

Expert Comment

by:aParser
ID: 12064086
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12065102
>>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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question