Simcoder Posted May 28, 2003 Posted May 28, 2003 Ok Heres the problem, I have 2 Files File 1) We will call it Application_ONE File 2) We will call it TextFile_TWO Now I want to embedd these 2 files into the executable. I have an idea of how to do that. I believe I add an existing item to the project and choose Embedded Resource. Next I want to copy both of those files to a path... example Path = C:\ProgramFiles How do I code a button that will copy both the application and the text file to the designated path. I would really appreciate any help from anyone! Thanx -=Simcoder=- Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Madz Posted May 29, 2003 Posted May 29, 2003 Hello this might help you while copying file Imports System Imports System.IO Public Class Test Public Shared Sub Main() ' Specify the directories you want to manipulate. Dim path As String = "c:\Program Files\MyTest.txt" Dim path2 As String = path + "temp" Try Dim fs As FileStream = File.Create(path) fs.Close() ' Ensure that the target does not exist. File.Delete(path2) ' Copy the file. File.Copy(path, path2) Console.WriteLine("{0} copied to {1}", path, path2) ' Try to copy the same file again, which should succeed. File.Copy(path, path2, True) Console.WriteLine("The second Copy operation succeeded, which was expected.") Catch Console.WriteLine("Double copying is not allowed, which was not expected.") End Try End Sub End Class Quote The one and only Dr. Madz eee-m@il
Simcoder Posted May 29, 2003 Author Posted May 29, 2003 Thanks, that helps me understand how the copy process is set up! Do you think you could tell me how to reference an object that does not have a path? Say an embedded project image, application or text file, How would I copy this from the embedded .exe file to the specified path. Thanks -=Simcoder=- Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Madz Posted May 29, 2003 Posted May 29, 2003 there are several methods for this. images and other strings are stored in EXE Resources Section. An EXE File has severel parts , The analysis of the managed EXE file structure employs the following common definitions: File pointer The location of an item within the file itself, before it is processed by the loader. This location is a position (an offset) within the file as it is stored on disk. Relative virtual address (RVA) The address of an item once it has been loaded into memory, with the base address of the image file subtracted from it�in other words, the offset of an item within the image file loaded into memory. The RVA of an item almost always differs from its position within the file on disk (the file pointer). Virtual address (VA) The same as the RVA except that the base address of the image file is not subtracted. The address is referred to as virtual because the operating system creates a distinct virtual address space for each process, independent of physical memory. For almost all purposes, a virtual address should be considered as simply an address. A virtual address is not as predictable as an RVA because the loader might not load the image at its preferred location if a conflict exists with any image file already loaded�a so-called base address conflict. Section The basic unit of code or data within a PE/COFF file. In addition to code and data sections, an image file can contain a number of sections, such as .tls (thread local storage) or .reloc (relocations), that have special purposes. All the raw data in a section must be loaded contiguously You need to work with SYSTEM.REFLECTION namespace which provide access to almost all things in this . If you want to get some resources from EXE files please just open that exe file in Visual Studio IDE it will show you all resources located in that PE File ( we use PE for Portable Executeable ) Please Check This Link Dot net Reflection Quote The one and only Dr. Madz eee-m@il
Simcoder Posted May 29, 2003 Author Posted May 29, 2003 Thanks alot Madz, I'm going to have to play around with it until I get it working. You've been a big help! :) Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Simcoder Posted May 29, 2003 Author Posted May 29, 2003 Hmm, I'm still having a problem, getting the exe file to be copied :( I used the System.Reflection, but I'm still not sure, what is the actual code to copy something that is embedded to a specific path! Can someone give me an example? For Instance, I embedded an exe file called App_One.exe How do I copy the file to my C:\ Drive. Some sample code would be nice so I could understand it. Thanks -=Simcoder=- Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Madz Posted May 29, 2003 Posted May 29, 2003 Oh Dear, some where i have searched about C# Resources Editor code in which you might get some good example of how to extract resources from EXE files and so on Quote The one and only Dr. Madz eee-m@il
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.