Click here to Skip to main content
15,902,635 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
Generaldelete question Pin
Yaakov Davis12-Jan-05 1:08
Yaakov Davis12-Jan-05 1:08 
GeneralRe: delete question Pin
Steve Maier1-Feb-05 10:18
professionalSteve Maier1-Feb-05 10:18 
GeneralFlash and MFC HELP! Pin
FayezElFar11-Jan-05 11:00
FayezElFar11-Jan-05 11:00 
GeneralRe: Flash and MFC HELP! Pin
Christian Graus11-Jan-05 14:35
protectorChristian Graus11-Jan-05 14:35 
GeneralRe: Flash and MFC HELP! Pin
Uwe Keim23-Jan-05 1:48
sitebuilderUwe Keim23-Jan-05 1:48 
GeneralRe: Flash and MFC HELP! Pin
Christian Graus23-Jan-05 9:58
protectorChristian Graus23-Jan-05 9:58 
GeneralObject disposed in Finalize method Pin
Member 134623511-Jan-05 6:24
Member 134623511-Jan-05 6:24 
GeneralAccessing Unmanaged C++ from C# Pin
jstedman11-Jan-05 5:54
jstedman11-Jan-05 5:54 
The problem I am having deals with wrapping an unmanaged C++ class which uses iostream and sends output to cout and then using the managed class in C#. When I make a method call on this class, I get the following error:

*** Exception! ***
Method: std.basic_ostream<char,std::char_traits<char> >* std.operator<<<struct std::char_traits<char=""> >(std.basic_ostream<char,std::char_traits<char> >*, SByte*)
Message: Object reference not set to an instance of an object.

When I replace the cout call with a call to printf, I do not get an error.

Here is the corresponding code. Thanks for the help or direction where I can get help.

USimple.h

#pragma once

__nogc
class USimple
{
public:
void PrintIt( );
};

USimple.cpp

#include "stdafx.h"

#include <iostream>
//#include <stdio.h>
#include "MSimple.h"
#include "USimple.h"

void USimple::PrintIt()
{
std::cout << "Hello, World" << std::endl;
// printf( "Hello, World\n" );
}

MSimple.h

#pragma once

#include "USimple.h"

using namespace System;

public __gc class MSimple
{
private:
USimple __nogc* m_pUSimp;

public:
MSimple( );
~MSimple();

void PrintIt( );
};

MSimple.h

#include "stdafx.h"

#include "USimple.h"
#include "MSimple.h"

MSimple::MSimple( )
{
m_pUSimp = new USimple( );
}

MSimple::~MSimple()
{
delete m_pUSimp;
}

void MSimple::PrintIt( )
{
m_pUSimp->PrintIt( );
}

Class1.cs

using System;

namespace CsSimple
{
///
/// Summary description for Class1.
///

class Class1
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
try
{
MSimple simple = new MSimple( );
simple.PrintIt( );
}
catch( Exception e )
{
Console.WriteLine( "\n*** Exception! ***" );
Console.WriteLine( "Method: {0}", e.TargetSite );
Console.WriteLine( "Message: {0}", e.Message );
}

Console.WriteLine( "Press enter to exit" );
Console.Read(); // Wait for enter pressed to end programme
}
}
}


Thanks again,

John Stedman
Generalrtf help Pin
Mohammad Daba'an10-Jan-05 22:28
Mohammad Daba'an10-Jan-05 22:28 
GeneralRe: rtf help Pin
Christian Graus11-Jan-05 14:37
protectorChristian Graus11-Jan-05 14:37 
Generaladding to integers together... help please!!! Pin
alexy2u8-Jan-05 8:44
alexy2u8-Jan-05 8:44 
GeneralRe: adding to integers together... help please!!! Pin
Christian Graus8-Jan-05 16:00
protectorChristian Graus8-Jan-05 16:00 
GeneralRe: adding to integers together... help please!!! Pin
FayezElFar11-Jan-05 11:04
FayezElFar11-Jan-05 11:04 
GeneralRe: adding to integers together... help please!!! Pin
prophets_lie16-Jan-05 18:17
prophets_lie16-Jan-05 18:17 
GeneralRe: adding to integers together... help please!!! Pin
Anders Dalvander29-Jan-05 1:25
Anders Dalvander29-Jan-05 1:25 
Generalsetup wizard Pin
Boniolopez8-Jan-05 4:48
Boniolopez8-Jan-05 4:48 
GeneralC++ arrays Pin
Ail6-Jan-05 9:19
Ail6-Jan-05 9:19 
Generaloperator[] in 2.0 Pin
Yaakov Davis5-Jan-05 13:20
Yaakov Davis5-Jan-05 13:20 
GeneralRe: operator[] in 2.0 Pin
Bill Gafford19-Jan-05 9:46
Bill Gafford19-Jan-05 9:46 
GeneralDetecting the phone number from C++ Pin
Bharat Gidde5-Jan-05 6:20
Bharat Gidde5-Jan-05 6:20 
GeneralRe: Detecting the phone number from C++ Pin
Christian Graus5-Jan-05 11:45
protectorChristian Graus5-Jan-05 11:45 
GeneralRe: Detecting the phone number from C++ Pin
Maximilien6-Jan-05 9:42
Maximilien6-Jan-05 9:42 
GeneralMirror Text Pin
dado745-Jan-05 2:47
dado745-Jan-05 2:47 
GeneralRe: Mirror Text Pin
Christian Graus5-Jan-05 11:46
protectorChristian Graus5-Jan-05 11:46 
GeneralMCppWrapper example Pin
eusjmf4-Jan-05 7:54
eusjmf4-Jan-05 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.