Solved

Current Directory in ActiveX EXE?

Posted on 2004-09-13
6
311 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

895 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

13 Experts available now in Live!

Get 1:1 Help Now