
Question:
I want to create a program that produces an executable slideshow.
So I need it to output an EXE with some required code and certain embedded resources (pictures) in it.
Does .NET provide such capability?
Answer1:You can use CSharpCodeProvider class to compile code at runtime and add embedded resources. Have a look at this article where I explain how to do it: <a href="http://www.codeproject.com/Articles/19288/SlideShowBuilder" rel="nofollow">SlideShow Builder</a>
Answer2:This is easy to accomplish.
You can add pictures as embedded resources and then use the technique of Reflection to discover and retrieve the embedded pictures.
So the program you write is independent of the list of pictures, which are just embedded resources. You can embed pictures as resources using Visual Studio, or create a custom program to do it.
You can find some examples at <a href="http://msdn.microsoft.com/en-us/library/aa287676(v=VS.71).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa287676(v=VS.71).aspx</a> and <a href="http://www.java2s.com/Code/CSharp/Development-Class/Saveandloadimagefromresourcefile.htm" rel="nofollow">http://www.java2s.com/Code/CSharp/Development-Class/Saveandloadimagefromresourcefile.htm</a>.
Good luck!
Answer3:Like what SK-Logic said there is
<a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx</a>
here is example of that
<a href="http://olondono.blogspot.com/2008/02/creating-code-at-runtime.html" rel="nofollow">http://olondono.blogspot.com/2008/02/creating-code-at-runtime.html</a>
You could also create a the project file and create the code files and use the Process class to call the compiler if you want help doing this I can give an example
Answer4:this will generate a process for you with the specified name (you'll still need to add code for the pictures):
public static Process GenerateRuntimeProcess(string processName, int aliveDuration, bool throwOnException = true)
{
Process result = null;
try
{
AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName() { Name = processName }, AssemblyBuilderAccess.Save);
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(processName, processName + ".EXE");
TypeBuilder typeBuilder = moduleBuilder.DefineType("Program", TypeAttributes.Public);
MethodBuilder methodBuilder = typeBuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, null, null);
ILGenerator il = methodBuilder.GetILGenerator();
il.UsingNamespace("System.Threading");
il.EmitWriteLine("Hello World");
il.Emit(OpCodes.Ldc_I4, aliveDuration);
il.Emit(OpCodes.Call, typeof(Thread).GetMethod("Sleep", new Type[] { typeof(int) }));
il.Emit(OpCodes.Ret);
typeBuilder.CreateType();
assemblyBuilder.SetEntryPoint(methodBuilder.GetBaseDefinition(), PEFileKinds.ConsoleApplication);
assemblyBuilder.Save(processName + ".EXE", PortableExecutableKinds.Required32Bit, ImageFileMachine.I386);
result = Process.Start(new ProcessStartInfo(processName + ".EXE")
{
WindowStyle = ProcessWindowStyle.Hidden
});
}
catch
{
if (throwOnException)
{
throw;
}
result = null;
}
return result;
}
you can findmore info on System.Reflection.Emit on MSDN <a href="http://msdn.microsoft.com/en-us/library/3y322t50.aspx" rel="nofollow">here</a> or a tutorial <a href="http://drdobbs.com/184416570" rel="nofollow">here</a> or <a href="http://blog.alxandr.me/2010/10/16/an-introduction-to-system-reflection-emit-and-opcodes/" rel="nofollow">here</a>.
if I were you I'd also look into just using powerpoint and/or the viewer app and some command line options as detailed <a href="http://office.microsoft.com/en-us/powerpoint-help/command-line-switches-for-powerpoint-2007-and-the-powerpoint-viewer-2007-HA010153889.aspx" rel="nofollow">here</a>. maybe you don't need to "make an app that makes another app that is a slideshow" at all..