Hi,
I am a new comer in C++/CLI programming. I am reading CLI/C++ in action trying to do the program in C++/CLI. I am using Windows XP and Visual studio 2008, framework 3.5. My problem is that, I had try to create the sample program " Using C++/CLI to write a WPF application " ( in chapter 7 ). In this chapter, you had describe Three ways to write WPF apps using c++, the first two programs is working, but the third one is not working properly ( may be my mistake. ) .
My program is like this,
I create a C# WPF Custom Control Library project and delete the default .xaml file and add a new .xaml file into the new project and the code is like this,
<Window x:Class="CSXamlLibrary.BaseWindow"
>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns

="http://schemas.microsoft.com/winfx/2006/xaml"
Title="First Avalon App ( dynamically load XAML)" Height="400" Width="400" ResizeMode="NoResize">
<Canvas>
<ListBox Canvas.Left="10" Canvas.Top="10" Width="180" Height="350"
>
Name="listbox" x:FieldModifier="protected" />
<TextBox Canvas.Left="200" Canvas.Top="10" Width="180" Height="25"
>
Name="textbox" x:FieldModifier="protected" />
<Button Canvas.Left="200" Canvas.Top="45" Width="80" Height="25"
>
Name="addbutton" x:FieldModifier="protected">Add</Button>
</Canvas>
</Window>
and save the file and build it. Then VS-2008 create a .dll file.
After that I create a new C++/CLI project and apply the settings, add assemblies and add the referance to that .dll file, and my code is like
AppMainwindow.cpp
===============
using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;
ref class AppMainWindow : CSXamlLibrary::BaseWindow
{
public:
AppMainWindow(void)
{
addbutton->Click += gcnew RoutedEventHandler(
this, &AppMainWindow::OnAddButtonClick);
}
void OnAddButtonClick(Object^ sender, RoutedEventArgs^ e)
{
listbox->Items->Add(textbox->Text);
textbox->Text = "";
textbox->Focus();
}
};
FirstAppDerive.cpp
==============
#include "AppMainWindow.cpp"
ref class FirstAppDerive : Application
{
protected:
virtual void OnStartup(StartupEventArgs^ e) override
{
Application::OnStartup(e);
AppMainWindow^ mainwnd = gcnew AppMainWindow();
mainwnd->Show();
}
};
App.cpp
=======
#include "FirstAppDerive.cpp";
using namespace System;
using namespace System::Windows;
[STAThread]
int main( array<String^>^ args)
{
return ( gcnew FirstAppDerive())->Run();
}
and build the project, then it successfully build and display the output like this
=====================================================
1>------ Build started: Project: clr3, Configuration: Debug Win32 ------
1>Copying 'e:VisualStudioTestingCSXamlLibraryCSXamlLibraryinDebugCSXamlLibrary.dll' to target directory...
1>Copying 'e:VisualStudioTestingCSXamlLibraryCSXamlLibraryinDebugCSXamlLibrary.pdb' to target directory...
1>Compiling...
1>AppMainWindow.cpp
1>FirstAppDerive.cpp
1>App.cpp
1>.App.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>Generating Code...
1>Linking...
1>Embedding manifest...
1>Caching metadata information for c:windowsassemblygac_msilwindowsbase3.0.0.0__31bf3856ad364e35windowsbase.dll...
1>Caching metadata information for e:visualstudiotestingcsxamllibrarycsxamllibraryindebugcsxamllibrary.dll...
1>Caching metadata information for c:windowsassemblygac_32presentationcore3.0.0.0__31bf3856ad364e35presentationcore.dll...
1>Caching metadata information for c:windowsassemblygac_msilpresentationframework3.0.0.0__31bf3856ad364e35presentationframework.dll...
1>Build log was saved at "file://e:VisualStudioTestingclr3clr3DebugBuildLog.htm"
1>clr3 - 0 error(s), 1 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
==============================================================
But when I try to run the program, the program open a file like "BaseWindow.xaml.cs" ( it is in my case, my first program name is BaseWindow.xaml ) and pointing to " InitializeComponent(); " and display a message like this.
=======================================================
An unhandled exception of type 'System.Exception' occurred in PresentationFramework.dll
Additional information: The component 'AppMainWindow' does not have a resource identified by the URI '/CSXamlLibrary;component/basewindow.xaml'.
========================================================
How can I solve this problem. Please help me
Thankyou,
Sabeesh