Click here to Skip to main content
15,912,837 members
Home / Discussions / C#
   

C#

 
QuestionVS2005 IDE design view problem Pin
Glen Harvy21-Nov-07 17:26
Glen Harvy21-Nov-07 17:26 
AnswerRe: VS2005 IDE design view problem Pin
Michael Sync21-Nov-07 18:41
Michael Sync21-Nov-07 18:41 
QuestionC# XML De-Serialization Array Questions Pin
alewis2721-Nov-07 16:58
alewis2721-Nov-07 16:58 
QuestionDragDrop from application to Windows Explorer Pin
atregent21-Nov-07 16:35
atregent21-Nov-07 16:35 
AnswerRe: DragDrop from application to Windows Explorer Pin
Michael Sync21-Nov-07 18:38
Michael Sync21-Nov-07 18:38 
Questionc#.net Pin
kmraina21-Nov-07 16:18
kmraina21-Nov-07 16:18 
AnswerRe: c#.net Pin
Christian Graus21-Nov-07 16:54
protectorChristian Graus21-Nov-07 16:54 
QuestionSystem.AccessViolationException due to throwing a std::runtime_error and catching the exception in managed C++ Pin
hiyowe21-Nov-07 15:57
hiyowe21-Nov-07 15:57 
compiler: visual c++ 2005
platform: WINDOWS2000 or Xp


My code does things as follows:

In unmanaged C++
1.the iterator of std::map
2.call std::map::find
3.assign the find result to a local variable in std::map::iterator
4.throw std::runtime_error exception
In managed C++
1.catch the std::runtime_error
2.throw the .NET System.Exception
In C#
1.catch the exception

When the C# program terminated, an exception occured:

Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.

Note:
1.When the compiler is Visual C++ 2003, the mentioned exception does NOT occur.
2.When I use the STLport library to take the place of the Stl library boundled with Visual C++
2005, the mentioned exception does NOT occur.
3.If the returned value from std::map::find is not assigned to any variable, the mentioned
exception does NOT occur.

The code is as follows:

Unmanaged C++ .cpp code:

#include "test.h"
#include <stdexcept>

using namespace std;

void AA::GetA()
{
map<string, string>::iterator iter = a.begin();

// If this statement is a.find("a"), that is, iter is not assigned, the mentioned exception
does NOT occur.

iter = a.find("a");
throw runtime_error("I am a C++ error!!!");
}

void AA::SetA()
{
a["test1"] = "testtest1";
a["a"] = "testtest2";
a["c"] = "testtest3";
a["b"] = "testtest4";
a["d"] = "testtest5";
}

Unmanaged C++ .h code:

#ifndef _TEST_H_
#define _TEST_H_

#ifdef _USRDLL
#define DllEXPORT __declspec( dllexport )
#else
#define DllEXPORT __declspec( dllimport )
#endif

#include <map>
#include <string>

class AA
{
public:

AA() : b(0)
{
}

~AA()
{
b = 0;
}

DllEXPORT void GetA();
DllEXPORT void SetA();

private:
std::map<std::string, std::string> a;
int b;
};
#endif // _TEST_H_


Managed C++ code:

#include "test.h"
#include <stdexcept>

#using <mscorlib.dll>

using namespace std;
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;

namespace GC {
public __gc class Test {
public:
Test() : mpAA(0)
{
mpAA = new AA;
}

~Test()
{
delete mpAA;
mpAA = 0;
}

void GetA()
{
try {
mpAA->GetA();
}
catch (exception& e) {
throw new Exception(e.what());
}
}

void SetA()
{
mpAA->SetA();
}

private:
AA* mpAA;
};
};


C# code:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
GC.Test a = new GC.Test();
a.SetA();
try
{
a.GetA();
}
catch (Exception e)
{
}
}
}
}

I don't know how to slove this problem.
Thanks for your help!!
QuestionStoring named data without a database Pin
gauzer21-Nov-07 15:29
gauzer21-Nov-07 15:29 
AnswerRe: Storing named data without a database Pin
Pankaj - Joshi21-Nov-07 16:20
Pankaj - Joshi21-Nov-07 16:20 
GeneralRe: Storing named data without a database Pin
gauzer21-Nov-07 16:35
gauzer21-Nov-07 16:35 
QuestionMultiple entries per row in a datagrid Pin
falles0121-Nov-07 14:30
falles0121-Nov-07 14:30 
AnswerRe: Multiple entries per row in a datagrid Pin
Vikram A Punathambekar21-Nov-07 16:53
Vikram A Punathambekar21-Nov-07 16:53 
GeneralRe: Multiple entries per row in a datagrid Pin
falles0121-Nov-07 17:04
falles0121-Nov-07 17:04 
GeneralRe: Multiple entries per row in a datagrid Pin
Vikram A Punathambekar22-Nov-07 4:24
Vikram A Punathambekar22-Nov-07 4:24 
GeneralRe: Multiple entries per row in a datagrid Pin
falles0122-Nov-07 12:06
falles0122-Nov-07 12:06 
GeneralRe: Multiple entries per row in a datagrid Pin
falles0122-Nov-07 14:03
falles0122-Nov-07 14:03 
GeneralRe: Multiple entries per row in a datagrid Pin
Vikram A Punathambekar22-Nov-07 15:25
Vikram A Punathambekar22-Nov-07 15:25 
GeneralRe: Multiple entries per row in a datagrid Pin
falles0122-Nov-07 16:25
falles0122-Nov-07 16:25 
GeneralRe: Multiple entries per row in a datagrid Pin
falles0122-Nov-07 18:54
falles0122-Nov-07 18:54 
QuestionHow can I select a whole when I click on CheckBox in DataGridView? Pin
T4AMD21-Nov-07 13:56
T4AMD21-Nov-07 13:56 
AnswerRe: How can I select a whole when I click on CheckBox in DataGridView? Pin
Michael Sync21-Nov-07 15:51
Michael Sync21-Nov-07 15:51 
QuestionDelete Key Trapping? Pin
jasper01821-Nov-07 13:16
jasper01821-Nov-07 13:16 
AnswerRe: Delete Key Trapping? Pin
Anthony Mushrow21-Nov-07 14:28
professionalAnthony Mushrow21-Nov-07 14:28 
GeneralRe: Delete Key Trapping? Pin
jasper01827-Nov-07 4:04
jasper01827-Nov-07 4:04 

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.