Solved

Resource file

Posted on 1998-04-19
14
307 Views
Last Modified: 2012-05-04
Can someone tell me how I can add a .avi file to my resource file? It keeps giving me errors.

Thanks.
0
Comment
Question by:DMM
  • 6
  • 5
  • 3
14 Comments
 

Author Comment

by:DMM
ID: 1425333
ok! I managed to add the avi to my resource file. But i am not able to use it in my program. Any help? Ta.
0
 
LVL 2

Expert Comment

by:chris_a
ID: 1425334
Sorry no answer. I am just spying on the answers you get, I think VB only handles pictures and sounds from resources, but it would be nice to use resource strings like C.

PS MS has an integrated resource editor in the VB owners area.

0
 

Expert Comment

by:bwoods
ID: 1425335
Use LoadResData (see VB help).  It returns an array of the actual bytes in the resource, and allows you to access menu resources, Accelarator table resources, etc, as well as user-defined resources.  You should be able to use it to get your avi information back out.  

Also, for chris_a,  you CAN use string resources in VB.  It even
has a specialized function for getting them out... LoadResString.

Also, I would suggest staying away from the integrated resource editor for VB. If you have access to it, use DevStudio's instead. You can still include the resource files in the VB project, you just can't double click on the resource file in the project explorer window and have it open automatically.  It's no problem to keep the resource file open in DS and switch back and forth between it and VB.  The one for VB isn't as powerful, and has other problems.

I'm commenting this in case someone else has had specific experience using AVI files and VB.  If LoadResData works for you, let me know, and I'll lock it for the points.  Good luck...
0
 
LVL 2

Expert Comment

by:chris_a
ID: 1425336
BWoods,

Thanks for the comments.

What I meant was the way that in C the menu editor automatically takes care of mapping menus to resource strings.

And yes, I do tend to avoid the built-in VB thingies, although the reseditor hasn't crashed on me yet.

Also DMM may have a problem with large AVI's I guess he needs a way to point the AVI player at the resource file.



0
 

Expert Comment

by:bwoods
ID: 1425337
Chris_a,
  Yes, he might have a problem pointing the AVI player at the resource file, but at worst, he could retrieve the actual bytes of the AVI file from the resource file using LoadResData.  Then, write the bytes retrieved to disk as a temporary AVI file, then point the AVI player at the temporary file.
0
 
LVL 2

Expert Comment

by:chris_a
ID: 1425338
I think the loadresdata fx is limited to 64K.
0
 

Expert Comment

by:bwoods
ID: 1425339
Yes, you're right, it is limited to 64K! hmmm, I had totally overlooked that point.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:bwoods
ID: 1425340
However, it can still be done.  Use the API calls FindResource, SizeofResource, LoadResource and LockResource to load the AVI file yourself.  If you can't find a way to point the AVI player at the Resource handle returned by LoadResource, then write it to a temporary AVI file and point the AVI player at that.  It's a simple process to covert it to an array of bytes and write it to disk.
0
 

Author Comment

by:DMM
ID: 1425341
Hi bwoods,

can you show me an example?

All I want to do is load the avi file and play it when the program starts.

Ta.
0
 

Author Comment

by:DMM
ID: 1425342
Hi,

I am prepared to double the points if someone can give me a solution.

Thanks.
0
 

Expert Comment

by:bwoods
ID: 1425343
Oh, I see you had posted a comment to me a couple of days ago... Sorry. I didn't get the mail message that you had posted it.  I got the one for your last comment, so something hickup'd I guess. Anyway, as for code...
  I have some code that uses LoadResource, etc. to extract custom resources from a resource file, and it should work in your situation. There is only one problem.  It is necessary to use EnumResourceNames and EnumResourceTypes.  These API calls require a callback (no prob under VB5 using AddressOf), but the callback requires you to get a string's data from a pointer.  VB doesn't give you an easy way of doing this.  I purchased Dan Appleman's VB5 Programmer's Guide to the WIN32 API, and the book provides a dll that contains API calls to do such things. Since I don't believe in reinventing the wheel, I used his GetStringFromPointer API call.  Thus, unless you have his dll, you wouldn't be able to use the code.  If you do have his dll, you SHOULD also have his book, as well as the CD rom that comes with it.  In that case, you have HIS sample code using these API calls.  It lives in CHAPTER_15, RESOURCE.VBP on the CD ROM.  

However, I think you might be missing the obvious... Sometimes resource files aren't of enough benefit to offset the hassle for making them work.  Is there any reason why you couldn't just distribute the avi file/s with your app?  Just include them in the install as a dependency of your app.  They'll be packaged right up with everything else in the install, and deposited in the application directory on the end-user's machine.  They will then already be on disk, and you can just point the AVI player at the AVI file you want, and you're in business.  Resource files are really only beneficial for things you might want to change due to international differences (strings, icons, etc).  Chances are, you will never change your AVI files for such reasons, so why put them in a resource file at all?
0
 

Author Comment

by:DMM
ID: 1425344
hhmmm! what u say makes sense. I havent used much of 'resource files'. So I keep experimenting with them.

One more question. How can I specify which directory the files - exe,etc,etc. - should be installed in? Will the user be able to specify the directory for the files? Post your response as answer and I will grade it.

Thanks.
0
 

Accepted Solution

by:
bwoods earned 50 total points
ID: 1425345
Yes, I agree they are interesting.  Sometimes the hardest thing to do is pick the easy way, when you want to do something the hard way just say you did it!  Anyway, as for installing...

The easiest way to specify which directory the files will be installed in is to let VB's Setup Wizard do it for you.  Go into
the Setup Wizard and begin.  It will try to detect all the dependencies it can.  First it will look for ActiveX Server components, then it will look for additional file dependencies. If you have included your AVI files in the project using PROJECT | ADD FILE  then it should list your AVI files now.  If it doesn't, don't worry about it, we will add them in a moment.  Next, it will generate dependencies.  When it finishes, you will be at a screen entitled  Setup Wizard - File Summary.  There will be a lot of stuff in this list.  If you don't know what some of it is, it's best to leave it, as VB must ship run-times both for your app, as well as for the setup program itself. If your files are not in this list, click Add and go find them and include them.  When you have all your AVI files in the list, highlight them one at a time and click file details. In the Destination Directory box, type the following:    $(AppPath)    This tells Setup to put the files in whatever directory the user chooses as the directory to install to.  (So yes, the user CAN specify the directory, but it's the directory for the entire app, not just for individual files) ... you can also put them in a directory under this directory.  Let's say you wanted to put them in a folder called \AVI\ under whatever directory the user installs in...   Put the following in the Destination Directory box:     $(AppPath)\AVI   Make sure you do this for every extra file you add.  (NOTE: if you included the files in the VB project, it should default to $(AppPath) for you.)  It's that simple.  There's still one touch to add.  When the Setup Wizard is finished creating your install, go to the directory you told it to place the install files in, and find SETUP.LST  Setup.lst allows you to edit most all the stuff the Setup Wizard does for you, then some.  Open it in Wordpad or Notepad.  (Don't double click it, as this will most like run the setup program, depending on the file extensions registered on your machine).  When you have it open in a text editor, scroll down to the following section:  
[Setup]
Title=
DefProgramGroup=
DefaultDir=
Setup=
AppExe=
AppToUninstall=
AppPath=

There will be some defaults after the = for some lines, based on what your VB project is called, etc.  Change the title to a real name, especially if it says something like vbpJoe'sApp.  It's OK to change AppExe and AppToUninstall, as long as you make sure AppToUninstall continues to match the AppExe.  The ones you will want to change are AppPath and DefaultDir (and maybe DefProgramGroup).  DefaultDir is the one that tells Setup what to show the user as the default installation directory... I suggest installing to your own directory under Program Files, as users have come to expect stuff to be located there.  The syntax for a DefaultDir in Program Files is    
      =$(ProgramFiles)\NameOfYourDirectory
You could hard code Program Files\NameofyourDir... etc, but that
will create a folder called Program Files if they don't have one.  Doing it with $(ProgramFiles) tells setup to use the directory that their windows installation has designated the Program Files folder (it's not guaranteed to be named Program Files!).  Unless you have a reason to, just make the AppDir match the DefaultDir, but if they differ, the DefaultDir is the one that Setup will show the user to be the default.
  Note, in the Setup.lst under the [FILES] section you can see where it is installing various files, such as the .exe, dlls, etc.  You can change these, but be very careful.  About the only time you don't want the location for app specific files (such as the exe) to be different from $(AppDir) and maybe some directory under that, is when you have a special case (such as a screensaver, which is a .scr which must be in the windows\system equivalent directory in order for windows to find it and list it as a screensaver option.)  Other than that, put stuff directly related to your app (your exe and other files, any proprietary dlls, etc in or under the $(AppDir), and leave system shared dlls (ones you didn't write yourself) wherever setup placed them by default.  
   That's all there is to it.  It's much longer typed than it is complicated!  I wanted to give you a good introduction, and it's hard to assume how much or how little someone knows, so it's easy to get long-winded.  The best thing for you to do is create a setup, and play with it.  Experiment.  One final tip: bear in mind that installing on a machine that has VB on it is NOT a valid test of your install.  If you are distributing your app (shareware, professionally, or however) you want to test it on as many machines, with as many different configurations and OS's as possible.  I guarantee you will find machines that you can't install to.  It's a fact of life.  Because of DLL's and the versioning problems they introduce, every installation of Windows must be considered unique (even clean installs can differ from machine to machine!).  You have to cross those bridges when you come to them (it's called Tech Support!)  All I can say is good luck!  If you have any other questions, let me know.
 
0
 

Author Comment

by:DMM
ID: 1425346
Great! That was the best answer I've ever got - explaining everything in detail. You will make a good teacher! :). I am sure to face lot of hurdles in my experiments with VB 5.0. If  I direct the questions to u, will u be notified?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now