Solved

Current Directory in ActiveX EXE?

Posted on 2004-09-13
6
309 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 115
VBA color chart bars 12 67
Excel VBA, find a string in a column, update a cell 7 51
How to Add / Edit Windows Menu 4 29
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now