473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Compiler bug in VC++ .Net 2003

Hi

I have very strange situations.
The following code always crashes any .Net appication that uses it.

What I have:
1. The Managed C++ code (test.h and test.cpp) that defines enumeration "Els" and function that returns an array of values of this enum "Els" as output parameter "outParam".

-------------------------------- test.h --------------------------
#pragma once

using namespace System::Runtime::InteropServices;

#define V_OK 17235968
#define V_HALT 17235969
#define V_CRASH 17235970

namespace managedC
{
public __value enum Els : unsigned int
{
Ok = V_OK,
Halt = V_HALT,
Crash = V_CRASH
};
public __gc class testClass
{
public:
static void TestMethodEnum([OutAttribute] Els (*outParam)[]);
};
}
-------------------------------- test.h --------------------------
-------------------------------- test.cpp --------------------------
#include "test.h"

#using <mscorlib.dll>

namespace managedC
{
void testClass::TestMethodEnum([OutAttribute] Els (*outParam)[])
{
*outParam = new Els[2];

for(int i = 0; i < (*outParam)->Length; i++)
(*outParam) = Els::Crash;
}
}
-------------------------------- test.cpp --------------------------
2. The C# code that has infinite loop and calls method "TestMethodEnum" inside.
-------------------------------- test.cs --------------------------
using System;
using System.Collections;

using managedC;

namespace marshalBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
for(int i = 0; ; i++)
{
Els[] paramEnum;
testClass.TestMethodArray(out paramEnum);

foreach(Els t in paramEnum)
Console.WriteLine(t);

GC.Collect();
}
}
}
}
-------------------------------- test.cs --------------------------
This code works only one circle until GC.Collect(). The CG crashes.

Who can me say what is this ? Is this a bug in compiler ?
Are there anybody who have the same situalion ?

Thanks

ps:
Are there any fixes or SP for VC 2003 ?

--------------------------------
From: Sergey Golovkin

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>ctyYzdnzsEG6y3RYxEOvLA==</Id>
Nov 17 '05 #1
2 1056
Hi Sergey!
void testClass::TestMethodEnum([OutAttribute] Els (*outParam)[])
{
*outParam = new Els[2];

for(int i = 0; i < (*outParam)->Length; i++)
(*outParam) = Els::Crash;
}


You should replace the line
(*outParam) = Els::Crash;
with
(*outParam)[i] = Els::Crash;

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Hi Jochen

Of course this line is :
(*outParam)[i] = Els::Crash;

BUT FORUM WEB UI REPLACES IT TO SMILE :-((

-------------------------------- test.h --------------------------
#pragma once

using namespace System::Runtime::InteropServices;

#define V_OK 17235968
#define V_HALT 17235969
#define V_CRASH 17235970

namespace managedC
{
public __value enum Els : unsigned int
{
Ok = V_OK,
Halt = V_HALT,
Crash = V_CRASH
};
public __gc class testClass
{
public:
static void TestMethodEnum([OutAttribute] Els (*outParam)[]);
};
}
-------------------------------- test.h --------------------------
-------------------------------- test.cpp --------------------------
#include "test.h"

#using <mscorlib.dll>

namespace managedC
{
void testClass::TestMethodEnum([OutAttribute] Els (*outParam)[])
{
*outParam = new Els[2];

for(int i = 0; i < (*outParam)->Length; i++)
(*outParam)[i] = Els::Crash;
}
}
-------------------------------- test.cpp --------------------------
-------------------------------- test.cs --------------------------
using System;
using System.Collections;

using managedC;

namespace marshalBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
for(int i = 0; ; i++)
{
Els[] paramEnum;
testClass.TestMethodArray(out paramEnum);

foreach(Els t in paramEnum)
Console.WriteLine(t);

GC.Collect();
}
}
}
}
-------------------------------- test.cs --------------------------

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin | last post by:
The original question is at the bottom: > What OS are you using? Windows 2000 Server SP3 with VS.NET 2003 > How much memory do you have? 512MB, of which typically at least half is...
2
by: | last post by:
I first thought I had some compiler setting wrong in VC# 2003 but it turns out that it has something to do with .NET framework v1.1 itself. If I understand correctly, .NET installer also installs a...
5
by: Mark | last post by:
The following code works with gnu compilers (ISO compliant declaration of the variable "i") void foo() { for (int i = 0; i < length; i++) { loop code.... } for (int i = 0; i < length; ...
0
by: Vijay Chegu | last post by:
Hi All, I am trying to port a perfectly working 32bit COM module developed in VC++ from 64bit. I am not able to generate .tlb file through midl compiler. I set the property thru the...
3
by: Martin | last post by:
Is there a reason for (and hopefully a work-around to) the VC++.NET's compiler "flushing" each output file to disk before compiling the next one? I've noticed this in both the 2002 and 2003...
5
by: Robert A Riedel | last post by:
I have a class that is intended to be exported in a DLL that uses another class that is in a static library. All clients that use the DLL will also link with the same static library. In summary,...
5
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and...
0
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing'...
2
by: Harry Whitehouse | last post by:
I'm porting an application from Borland C++ to VS .NET 2003. The VC++ compiler doesn't want to deal with declarations like this in my code: LONG FAR PASCAL _export StdPVDlgProc(HWND hWnd, UINT...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.