BoxedApp Blog

BoxedApp: Tips'n'Tricks, Examples, Use Cases etc.

Launching .NET Applications From Memory


Share this post Bookmark and Share

We’ve issued new update of the BoxedApp SDK and BoxedApp Packer, which includes new function BoxedAppSDK_ExecuteDotNetApplication:

DWORD BoxedAppSDK_ExecuteDotNetApplication(LPCTSTR szPath, LPCTSTR szArgs);

[ Download demo version ]

You can launch .net applications from a virtual location (from a real file too, of course). One customer needed to launch FxCop from a memory. We’ve fixed a issue related with FxCop and… and we decided to provide a special function that runs a .net application within current process, BoxedAppSDK_ExecuteDotNetApplication.

Here a simple example of how to launch FxCop from a virtual location in C++:

   BoxedAppSDK_Init();

   HANDLE
   hFile = 
   BoxedAppSDK_CreateVirtualFile( 
      _T("Z:\\FxCop\\FxCop.exe"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_ALWAYS, 
      0, 
      NULL 
   );
#define DEF_COPY(name) CopyFileA("C:\\Program Files\\Microsoft FxCop 1.36\\" #name ,\
"Z:\\FxCop\\" #name , FALSE);
   DEF_COPY(CustomDictionary.xml);
   DEF_COPY(FxCop.exe);
   DEF_COPY(FxCop.exe.config);
   DEF_COPY(FxCopCmd.exe);
   DEF_COPY(FxCopCmd.exe.config);
   DEF_COPY(FxCopCommon.dll);
   DEF_COPY(FxCopSdk.dll);
   DEF_COPY(FxCopUI.dll);
   DEF_COPY(Microsoft.Cci.dll);
   DEF_COPY(MSSp3en.lex);
   DEF_COPY(MSSp3ena.lex);
   DEF_COPY(MSSpell3.dll);

   hFile = 
   BoxedAppSDK_CreateVirtualFile( 
      _T("Z:\\FxCop\\Engines\\IntrospectionAnalysisEngine.dll"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_ALWAYS, 
      0, 
      NULL 
   );
#define DEF_COPY(name) \ 
CopyFileA("C:\\Program Files\\Microsoft FxCop 1.36\\Engines\\" #name ,\
 "Z:\\FxCop\\Engines\\" #name , FALSE);
   DEF_COPY(IntrospectionAnalysisEngine.dll);
   DEF_COPY(IntrospectionForms.dll);

   hFile = 
   BoxedAppSDK_CreateVirtualFile( 
      _T("Z:\\FxCop\\Repository\\system32.bin"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_ALWAYS, 
      0, 
      NULL 
   );
#define DEF_COPY(name) \
CopyFileA("C:\\Program Files\\Microsoft FxCop 1.36\\Repository\\" #name ,\
 "Z:\\FxCop\\Repository\\" #name , FALSE);
   DEF_COPY(system32.bin);

   hFile = 
   BoxedAppSDK_CreateVirtualFile( 
      _T("Z:\\FxCop\\Repository\\Compatibility\\Desktop2.0.xml"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_ALWAYS, 
      0, 
      NULL 
   );
#define DEF_COPY(name) \
CopyFileA("C:\\Program Files\\Microsoft FxCop 1.36\\Repository\\Compatibility\\" #name ,\
 "Z:\\FxCop\\Repository\\Compatibility\\" #name , FALSE);
   DEF_COPY(Desktop2.0.xml);
   DEF_COPY(Desktop2.0SP1.xml);
   DEF_COPY(Desktop2.0SP2.xml);
   DEF_COPY(Desktop3.0.xml);
   DEF_COPY(Desktop3.0SP1.xml);
   DEF_COPY(Desktop3.0SP2.xml);
   DEF_COPY(Desktop3.5.xml);
   DEF_COPY(Desktop3.5SP1.xml);

   hFile = 
   BoxedAppSDK_CreateVirtualFile( 
      _T("Z:\\FxCop\\Rules\\DesignRules.dll"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_ALWAYS, 
      0, 
      NULL 
   );
#define DEF_COPY(name) \
CopyFileA("C:\\Program Files\\Microsoft FxCop 1.36\\Rules\\" #name , "Z:\\FxCop\\Rules\\" #name , FALSE);
   DEF_COPY(DesignRules.dll);
   DEF_COPY(GlobalizationRules.dll);
   DEF_COPY(InteroperabilityRules.dll);
   DEF_COPY(MobilityRules.dll);
   DEF_COPY(NamingRules.dll);
   DEF_COPY(PerformanceRules.dll);
   DEF_COPY(PortabilityRules.dll);
   DEF_COPY(SecurityRules.dll);
   DEF_COPY(UsageRules.dll);

   hFile = 
   BoxedAppSDK_CreateVirtualFile( 
      _T("Z:\\FxCop\\Xml\\CodeAnalysisReport.xsl"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_ALWAYS, 
      0, 
      NULL 
   );
#define DEF_COPY(name) \
CopyFileA("C:\\Program Files\\Microsoft FxCop 1.36\\Xml\\" #name , "Z:\\FxCop\\Xml\\" #name , FALSE);
   DEF_COPY(CodeAnalysisReport.xsl);
   DEF_COPY(FxCopReport.xsd);
   DEF_COPY(FxCopReport.xsl);
   DEF_COPY(FxCopReportExcludes.xsl);
   DEF_COPY(FxCopRichConsoleOutput.xsl);
   DEF_COPY(VSConsoleOutput.xsl);

BoxedAppSDK_ExecuteDotNetApplication(_T("Z:\\FxCop\\FxCopCmd.exe"), _T("/o:out.txt /p:FxCopProject.FxCop"));

[ Download demo version ]

Share this post Bookmark and Share






Write a Comment

You must be logged in to post a comment. Log in