The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

sabeeshcs (6) [Avatar] Offline
#1
I am trying to create a simple application in C++/CLI using WPF, using Deriving from a class in a C# DLL in VS-2008. Fro that I create a project in C# and compile it and the output is a .dll file.
The step is like this
File->new->Project->C#->WPF Custom Control Library
Delete the default .xaml file and add a new one and code is like this,

Window x:Class="wpflib.basewindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlnssmilie="http://schemas.microsoft.com/winfx/2006/xaml"
Title="basewindow" Height="400" Width="400" ResizeMode="NoResize">
<Grid>
<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>

</Grid>
</Window>


And build the project, and it create a .dll file.


My second project is like this

Open CLR Empty project
Set SubSystem to /SUBSYSTEM:WINDOWS
Set the entry point to main
Add these referance
System
PresentationCore
PresentationFramework
WindowsBase
And create a class “AppMainWindow”
Code :

AppMainWindow.h
--------------
#pragma once
using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;

ref class AppMainWindow : wpflib::basewindow
{

public:
AppMainWindow(void);
// void onAddButtonClick(Object^ sender, RoutedEventArgs^ e);

void onAddButtonClick(Object^ sender, RoutedEventArgs^ e)
{
listbox->Items->Add(textbox->Text);
textbox->Text="";
textbox->Focus();
}

};

AppMainWindow.cpp
--------------

#include "AppMainWindow.h"

AppMainWindow::AppMainWindow(void)
{
addbutton->Click += gcnew RoutedEventHandler( this, &AppMainWindow::onAddButtonClick);

}



AppMainWindow.h
---------------
ref class FirstAppDerived : Application
{
//public:
//FirstAppDerived(void);
protected:
virtual void OnStartup(StartupEventArgs^ e) override
{
Application::OnStartup(e);
AppMainWindow^ mainwnd = gcnew AppMainWindow();
mainwnd->Show();
}
};

App.cpp
---------
#include "FirstAppDerived.h"

using namespace System;
using namespace System::Windows;
[STAThread]

int main( array<String^>^ args)
{
return ( gcnew FirstAppDerived())->Run();


}

And successfully build the project. But at runtime it display an error like this

An unhandled exception of type 'System.NullReferenceException' occurred in PresentationCore.dll

Additional information: Object reference not set to an instance of an object.


How can I find this error. Please help me.

Thankyou
Sabeesh
ramaganesan (1) [Avatar] Offline
#2
Re: Object reference not set to an instance of an object
Dear Sir,
When working in core banking when such a command comes in your computer what is actually the problem in the main server?