Solved

Current Directory in ActiveX EXE?

Posted on 2004-09-13
6
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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