Re: Fruit basket program in C++/CLI

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Tue, 20 Nov 2007 11:38:50 -0500 (EST)

I guess I find the use of the word "pure" in /clr:pure to be a bit
misleading, since the target executable is not a stand-alone .NET
assembly without other dependencies.  Since it is with /clr:safe,
however, there is no problem once one understands the syntax.

FYI -- Here is the manifest created by the /clr option:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1'
manifestVersion='1.0'>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC80.CRT'
version='8.0.50608.0' processorArchitecture='x86'
publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
</assembly>


Here is the manifest created by the /clr:pure option:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1'
manifestVersion='1.0'>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC80.CRT'
version='8.0.50608.0' processorArchitecture='x86'
publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
</assembly>

Jamal

On Tue, 20 Nov 2007,
Will Pearson
wrote:

> Date: Tue, 20 Nov 2007 08:40:36 -0000
> From: Will Pearson <will@xxxxxxxxxxxxx>
> Reply-To: programmingblind@xxxxxxxxxxxxx
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: Fruit basket program in C++/CLI
>
> Hi Jamal,
>
> The error is because the system can't find msvcrt80.dll or one of the other
> CRT DLL's.  The first error message you mentioned is one that I've come
> across before, although in a different context.  There's probably a bit more
> information regarding that error in one of the system logs, and I suspect it
> would be logged as a Win SXS error.
>
> The manifest tells the system that the application uses side by side
> assemblies.  This effectively adds c:\windows\winsxs to the DLL search path,
> which is the folder where side by side assemblies are installed to.  The
> manifest also tells the loader which version to load.  If that version
> cannot be located in the winsxs folder then you'll also get an error.  This
> is an important point because Visual Studio 2005 and Visual Studio 2005 SP1
> ship different versions of the CRT.
>
> The manifests for side by side assemblies can either be embedded into a
> binary, such as an exe or DLL, or left as standalone XML files.  What you
> seem to have is a standalone XML file for your application.  I think the IDE
> takes a few extra steps to embed the manifest into the application.  As you
> are using command line tools then you will have to do this extra work by
> hand using the manifest tool mt.exe.
>
> I don't think you can avoid a manifest if you create mixed native/managed
> code.  The /clr and /clr:pure options require msvcm80.dll.  As this is a DLL
> associated with the CRT then it will be installed into the winsxs folder.
> When I took a look at the list of CRT libraries and DLL's that Microsoft
> provide for Visual C++ 2005 I couldn't find a static link alternative for
> msvcm80.dll.  The only way to get the necessary functionality is to use
> msvcm80.dll.
>
> Will
> ----- Original Message -----
> From: "Jamal Mazrui" <empower@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Monday, November 19, 2007 7:36 PM
> Subject: Re: Fruit basket program in C++/CLI
>
>
> Hi Will,
> Unlike the /clr:safe option, I found that both the /clr and /clr:pure
> options produce a .manifest file that is required for the program to
> run.
>
> If I delete the .manifest file after compiling with the /clr option, I
> get the following error in a message box:
>
> cli_fruit.exe - Application Error
> The application failed to initialize properly (0x80000003). Click on OK
> to terminate the application.
>
> If I delete the .manifest file after compiling with the /clr:pure
> option, I get the following error in a message box:
>
> Microsoft Visual C++ Runtime Library
> Runtime Error! Program: c:\cli_fruit\cli_fruit.exe
> R6034
> An application has made an attempt to load the C runtime library
> incorrectly.
> Please contact the application's support team for more information.
>
> With the /clr:pure option, after clearing the message box, I get the
> following error printed to the console by the .NET runtime:
>
> Unhandled Exception: System.TypeInitializationException: The type
> initializer for '<Module>' threw an exception. --->
> System.DllNotFoundException: Unable to load DLL 'msvcm80.dll': A dynamic
> link library (DLL) initialization routine failed.
>  (Exception from HRESULT: 0x8007045A)
> at <CrtImplementationDetails>.ThrowModuleLoadException(String ,
> Exception )
> at
> <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
> at .cctor()
> --- End of inner exception stack trace ---
>
> Jamal
>
> On
> Mon, 19 Nov 2007, Will
> Pearson wrote:
>
> > Date: Mon, 19 Nov 2007 18:17:11 -0000
> > From: Will Pearson <will@xxxxxxxxxxxxx>
> > Reply-To: programmingblind@xxxxxxxxxxxxx
> > To: programmingblind@xxxxxxxxxxxxx
> > Subject: Re: Fruit basket program in C++/CLI
> >
> > Hi Jamal,
> >
> > What was the dependancy?  /clr will also require the c run-time as you are
> > using native code.
> >
> > If the dependancy that you got was the CRT then it explains why you might
> > need another manifest.  In Visual Studio 2005 the VC team decided to
> > deploy
> > the DLL versions of the CRT as side by side assemblies.  These are not
> > assemblies in the .Net sense of the term but they do contain manifests
> > just
> > like .Net assemblies.  Windoes XP introduced a new way of deploying DLL's
> > to
> > try to decrease DLL hell, and this new deployment method is known as side
> > by
> > side assemblies or sxs for short.  SXS uses a manifest to specify a DLL
> > version, if the assembly is a DLL, any dependancies that the DLL or exe
> > has,
> > and a bit of COM information, such as GUID's, if the assembly uses COM.
> > The
> > manifest can store more meta data but those are the common things that you
> > find.    The manifest schema is the same one that .Net assemblies use and
> > it
> > is documented in the MSDN library.  Just as with the .Net framework
> > assemblies, any native exe that uses an sxs assembly needs to include a
> > manifest to specify that dependancy and version information.  So, you
> > would
> > need to include this if you were using the CRT.  Other example of an sxs
> > assembly is the common controls v6.
> >
> > It might be that the two manigests failed to merge, weren't created, or
> > otherwise got messed up if your dependancy error was on the CRT.
> >
> > Will
> > ----- Original Message -----
> > From: "Jamal Mazrui" <empower@xxxxxxxxx>
> > To: <programmingblind@xxxxxxxxxxxxx>
> > Sent: Monday, November 19, 2007 5:41 PM
> > Subject: Re: Fruit basket program in C++/CLI
> >
> >
> > FYI -- I was unable to create a stand-alone fruit basket executable with
> > the /clr or /clr:pure parameters.  Dependencies to other files remained,
> > which had to be available on the existing search paths, specified in a
> > seperate manifest file, or included in the same directory as the
> > executable.  The /clr:safe parameter, however, did create a stand-alone,
> > .NET-based executable.
> >
> > Jamal
> > On Mon, 19 Nov 2007, Will Pearson wrote:
> >
> > > Date: Mon, 19 Nov 2007 16:49:58 -0000
> > > From: Will Pearson <will@xxxxxxxxxxxxx>
> > > Reply-To: programmingblind@xxxxxxxxxxxxx
> > > To: programmingblind@xxxxxxxxxxxxx
> > > Subject: Re: Fruit basket program in C++/CLI
> > >
> > > Hi,
> > >
> > > cl.exe has thre modes for compiling C++/CLI:
> > > - /clr
> > > This is the C++ interop mode.  It enables native and managed code to
> > > coexist
> > > together.  Importantly, it is the only clr option that allows you to
> > > still
> > > use pointers in your code.  This means you can use callbacks and other
> > > places where pointers are typically found in native API's.  As both
> > > native
> > > and managed code can coexist together you can create a project that uses
> > > both the Windows API and the .Net Framework.  These are known as mixed
> > > assemblies in .Net terminology.
> > >
> > > - /clr:pure
> > > Will compile all the code to IL and produce a pure .Net assembly.  This
> > > means that you can't use native API's from within your code unless you
> > > use
> > > the interop methods provided by the .Net Framework, such as P/Invoke or
> > > COM
> > > interop.
> > >
> > > - /clr:safe
> > > Produces a .Net assembly that is verifiable.
> > >
> > > Will
> > > ----- Original Message -----
> > > From: "jaffar" <jaffar@xxxxxxxxxxxxx>
> > > To: <programmingblind@xxxxxxxxxxxxx>
> > > Sent: Monday, November 19, 2007 4:29 PM
> > > Subject: Re: Fruit basket program in C++/CLI
> > >
> > >
> > > Hi Marlon.  At least for the other editions of Visual Studio apart from
> > > the
> > > express which i cannot be sure off, you can actually make changes to
> > > your
> > > compiler options so that it can compile either native c++ code or
> > > microsoft's cli version of c++ or both.  For example, You can turn off
> > > the
> > > _T identifier needed to compile character sequences in your code and
> > > revert
> > > to the standard CHAR used by native C++.  Cheers!
> > > ----- Original Message -----
> > > From: "Marlon Brandão de Sousa" <splyt.lists@xxxxxxxxx>
> > > To: <programmingblind@xxxxxxxxxxxxx>
> > > Sent: Monday, November 19, 2007 10:38 PM
> > > Subject: Re: Fruit basket program in C++/CLI
> > >
> > >
> > > hmm Jamal, correct me if I am wrong, but my understanding is that one
> > > can't compile binary, native win32 executable if they use the cli
> > > part.
> > > Sure visual C can generate binaries for win32, but if you use the
> > > extensions, at least based on what I have understood, the .net
> > > dependencies will be kept ...
> > > In other words I can use visual C to develope binaries in raw c++ but
> > > not in the cli version, using visual c.
> > > Marlon
> > >
> > > 2007/11/19, Jamal Mazrui <empower@xxxxxxxxx>:
> > > > Yes, my undrstanding is that C++/CLI is essentially for C++ developers
> > > > who want to take advantage of the .NET Framework with the language and
> > > > associated features to which they have become accustomed.  Microsoft
> > > > submitted the language for international standardization, and this has
> > > > occurred, so theoretically other software publishers and platforms
> > > > could
> > > > develop compilers for C++/CLI besides Microsoft Visual C++.  It is
> > > > unlikely that will happen practically speaking, however, because of
> > > > the
> > > > inherent relation to .NET 2.0.
> > > >
> > > > It is noteworthy that Microsoft's compiler can be used to create
> > > > native
> > > > Win32 executables in standard C++ without any .NET dependencies.  In
> > > > other words, the CLI aspect adds language extensions, but not
> > > > requirements for a traditional C++ developer.
> > > >
> > > > Jamal
> > > > On Mon, 19 Nov 2007, Marlon
> > > > Brandão de Sousa wrote:
> > > >
> > > > > Date: Mon, 19 Nov 2007 09:32:13 -0200
> > > > > From: Marlon Brandão de Sousa <splyt.lists@xxxxxxxxx>
> > > > > Reply-To: programmingblind@xxxxxxxxxxxxx
> > > > > To: programmingblind@xxxxxxxxxxxxx
> > > > > Subject: Re: Fruit basket program in C++/CLI
> > > > >
> > > > > Only to clarify, Lamar, this isn't c or c++. This is c Cli, which
> > > > > means it is a c++ modified language which allows the use of the .net
> > > > > stuff. If you want to develope for anything portable or non windows
> > > > > keep away from this for now and go learn the c++ language.
> > > > > This version of c++, the cli one, introduces some sintactical
> > > > > modifications (e.e the ^ symbol which seen to be a kind of pointer),
> > > > > and some other new things, but it won't compile out of microsoft
> > > > > compilers and it won't run out of windows ... well it won't run even
> > > > > on windows , if the .net is not installed on it.
> > > > >
> > > > > 2007/11/19, jaffar <jaffar@xxxxxxxxxxxxx>:
> > > > > > Hi Lamar.  No.  You'll need at least the .net 2.0 runtime to be
> > > > > > able
> > > > > > to
> > > > run
> > > > > > it.  Cheers!
> > > > > > ----- Original Message -----
> > > > > > From: "Lamar Upshaw" <lupshaw@xxxxxxxxxxxxxx>
> > > > > > To: <programmingblind@xxxxxxxxxxxxx>
> > > > > > Sent: Monday, November 19, 2007 4:30 PM
> > > > > > Subject: Re: Fruit basket program in C++/CLI
> > > > > >
> > > > > >
> > > > > > > Just to clarify, I should be able to run this using minGW,
> > > > > > > correct?
> > > > > > >
> > > > > > > With All Respect,
> > > > > > > Upshaw, Lamar T
> > > > > > > ----- Original Message -----
> > > > > > > From: "Jamal Mazrui" <empower@xxxxxxxxx>
> > > > > > > To: <programmingblind@xxxxxxxxxxxxx>
> > > > > > > Sent: Sunday, November 18, 2007 8:14 PM
> > > > > > > Subject: Fruit basket program in C++/CLI
> > > > > > >
> > > > > > >
> > > > > > >> From the archive at
> > > > > > >> http://www.EmpowermentZone.com/cli_fruit.zip
> > > > > > >>
> > > > > > >> This fruit basket program is written in C++/CLI:  the C++
> > > > > > >> language
> > > > with
> > > > > > >> extensions to support the Common Language Infrastructure of the
> > > > > > >> .NET
> > > > > > >> Framework.  C++/CLI can create native Win32 executables or
> > > > > > >> libraries,
> > > > > > >> .NET-based ones, or a combination of both.  Related development
> > > > resources
> > > > > > >> that are freely available from Microsoft.com include the
> > > > > > >> following:
> > > > the
> > > > > > >> .NET Framework 2.0 SDK, the Microsoft Platform SDK for Windows
> > > > > > >> Server
> > > > > > >> 2003, and Visual C++ 2005 Express Edition.
> > > > > > >>
> > > > > > >> The archive includes a batch file, compile.bat, which invokes
> > > > > > >> the
> > > > > > >> command-line compiler to create an executable, cli_fruit.exe,
> > > > > > >> which
> > > > is
> > > > > > >> about 5K in size.  The batch file initially sets environmental
> > > > variables
> > > > > > >> that may need to be tweaked on another computer so that
> > > > > > >> appropriate
> > > > > > >> directories are referenced.
> > > > > > >>
> > > > > > >> Besides the resulting executable, No other files are needed to
> > > > > > >> run
> > > > the
> > > > > > >> program -- as long as .NET 2.0 is installed.   The included
> > > > > > >> Source
> > > > code
> > > > > > >> is
> > > > > > >> also pasted below.
> > > > > > >>
> > > > > > >> Jamal
> > > > > > >>
> > > > > > >> /*;
> > > > > > >> content of cli_fruit.cpp;
> > > > > > >> Fruit Basket program in C++/CLI
> > > > > > >> //public domain by Jamal Mazrui
> > > > > > >> */;
> > > > > > >>
> > > > > > >> // Reference libraries
> > > > > > >> #using <System.dll>
> > > > > > >> #using <System.Windows.Forms.dll>
> > > > > > >>
> > > > > > >> // Import namespaces
> > > > > > >> using namespace System;
> > > > > > >> using namespace System::Windows::Forms;
> > > > > > >>
> > > > > > >> // Define class
> > > > > > >> ref class FruitBasket : public Form {
> > > > > > >> public :
> > > > > > >> //Define constructor
> > > > > > >> FruitBasket() {
> > > > > > >> // Initialize controls and set properties
> > > > > > >> tlp = gcnew TableLayoutPanel();
> > > > > > >> tlp->ColumnCount = 3;
> > > > > > >> tlp->RowCount = 2;
> > > > > > >>
> > > > > > >> lblFruit = gcnew Label();
> > > > > > >> lblFruit->Text = "&Fruit:";
> > > > > > >> tlp->Controls->Add(lblFruit);
> > > > > > >>
> > > > > > >> txtFruit = gcnew TextBox();
> > > > > > >> tlp->Controls->Add(txtFruit);
> > > > > > >>
> > > > > > >> btnAdd = gcnew Button();
> > > > > > >> btnAdd->Text = "&Add";
> > > > > > >> btnAdd->Click += gcnew EventHandler(this,
> > > > &FruitBasket::Button_Click);
> > > > > > >> tlp->Controls->Add(btnAdd);
> > > > > > >>
> > > > > > >> lblBasket = gcnew Label();
> > > > > > >> lblBasket->Text = "&Basket:";
> > > > > > >> tlp->Controls->Add(lblBasket);
> > > > > > >>
> > > > > > >> lstBasket = gcnew ListBox();
> > > > > > >> tlp->Controls->Add(lstBasket);
> > > > > > >>
> > > > > > >> btnDelete = gcnew Button();
> > > > > > >> btnDelete->Text = "&Delete";
> > > > > > >> btnDelete->Click += gcnew EventHandler(this,
> > > > &FruitBasket::Button_Click);
> > > > > > >> tlp->Controls->Add(btnDelete);
> > > > > > >>
> > > > > > >> Text = "Fruit Basket";
> > > > > > >> AcceptButton = btnAdd;
> > > > > > >> StartPosition = FormStartPosition::CenterScreen;
> > > > > > >> AutoSize = true;
> > > > > > >> AutoSizeMode =
> > > > > > >> System::Windows::Forms::AutoSizeMode::GrowAndShrink;
> > > > > > >> Controls->Add(tlp);
> > > > > > >> } // FruitBasket constructor
> > > > > > >>
> > > > > > >> // Define destructor
> > > > > > >> virtual ~FruitBasket() {
> > > > > > >> } // FruitBasket destructor
> > > > > > >>
> > > > > > >> // Define event handler;
> > > > > > >> void Button_Click(Object^ sender, EventArgs^ e) {
> > > > > > >> if (sender == btnAdd) {
> > > > > > >> String^ sFruit = txtFruit->Text->Trim();
> > > > > > >> if (sFruit->Length == 0) {
> > > > > > >> MessageBox::Show("No fruit to add!", "Alert");
> > > > > > >> return;
> > > > > > >> }
> > > > > > >>
> > > > > > >> lstBasket->Items->Add(sFruit);
> > > > > > >> txtFruit->Clear();
> > > > > > >> lstBasket->SelectedIndex = lstBasket->Items->Count - 1;
> > > > > > >> }
> > > > > > >> else if (sender == btnDelete) {
> > > > > > >> int iFruit = lstBasket->SelectedIndex;
> > > > > > >> if (iFruit == -1) {
> > > > > > >> MessageBox::Show("No fruit to delete->", "Alert");
> > > > > > >> return;
> > > > > > >> }
> > > > > > >>
> > > > > > >> lstBasket->Items->RemoveAt(iFruit);
> > > > > > >> if (iFruit == lstBasket->Items->Count) iFruit--;
> > > > > > >> lstBasket->SelectedIndex = iFruit;
> > > > > > >> }
> > > > > > >> } // Button_Click event handler
> > > > > > >>
> > > > > > >> // Declare controls;
> > > > > > >> TableLayoutPanel^ tlp;
> > > > > > >> Label^ lblFruit;
> > > > > > >> TextBox^ txtFruit;
> > > > > > >> Button^ btnAdd;
> > > > > > >> Label^ lblBasket;
> > > > > > >> ListBox^ lstBasket;
> > > > > > >> Button^ btnDelete;
> > > > > > >> }; // FruitBasket class
> > > > > > >>
> > > > > > >> // Define entry point of program
> > > > > > >> int main() {
> > > > > > >> Application::Run(gcnew FruitBasket());
> > > > > > >> return 0;
> > > > > > >> } // main method
> > > > > > >>
> > > > > > >> // End of cli_fruit.cpp
> > > > > > >>
> > > > > > >> __________
> > > > > > >> View the list's information and change your settings at
> > > > > > >> //www.freelists.org/list/programmingblind
> > > > > > >>
> > > > > > >
> > > > > > > __________
> > > > > > > View the list's information and change your settings at
> > > > > > > //www.freelists.org/list/programmingblind
> > > > > > >
> > > > > >
> > > > > > __________
> > > > > > View the list's information and change your settings at
> > > > > > //www.freelists.org/list/programmingblind
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > When you say "I wrote a program that crashed Windows," people just
> > > > > stare at you blankly and say "Hey, I got those with the system, for
> > > > > free."
> > > > > Linus Torvalds
> > > > > __________
> > > > > View the list's information and change your settings at
> > > > > //www.freelists.org/list/programmingblind
> > > > >
> > > > __________
> > > > View the list's information and change your settings at
> > > > //www.freelists.org/list/programmingblind
> > > >
> > > >
> > >
> > >
> > > --
> > > When you say "I wrote a program that crashed Windows," people just
> > > stare at you blankly and say "Hey, I got those with the system, for
> > > free."
> > > Linus Torvalds
> > > __________
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/programmingblind
> > >
> > > __________
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/programmingblind
> > > __________
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/programmingblind
> > >
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
> >
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: