Link to home
Start Free TrialLog in
Avatar of DMM
DMM

asked on

Resource file

Can someone tell me how I can add a .avi file to my resource file? It keeps giving me errors.

Thanks.
Avatar of DMM
DMM

ASKER

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.
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.

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...
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.



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.
I think the loadresdata fx is limited to 64K.
Yes, you're right, it is limited to 64K! hmmm, I had totally overlooked that point.
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.
Avatar of DMM

ASKER

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.
Avatar of DMM

ASKER

Hi,

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

Thanks.
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?
Avatar of DMM

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of bwoods
bwoods

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DMM

ASKER

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?