473,385 Members | 2,004 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,385 software developers and data experts.

Mapping int out to managed C++ (now failing?)

Hello,

In the MC++ FAQ, we can find how to map a C# "out int" argument to managed
C++. The following solution used to work, in previous version of VS, but
fails with VC# and VC++ Express:

// TestOutInt.h

#pragma once

using namespace System;
using namespace System::Runtime::InteropServices;

namespace TestOutInt {

public ref class Class1
{
public:
void SomeFunc( [Out]Int32 * arg)
{
*arg = 2;
}
};
}

// C# code
using System;
using System.Collections.Generic;
using System.Text;
using TestOutInt;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int test;
Class1 c = new Class1();
c.SomeFunc(out test);
Console.WriteLine(test.ToString());
}
}
}

It splits out the error: Argument '1': cannot convert from 'out int' to 'int*'

As mentioned the equivalent code used to work in previous version.
What am I misssing here?

-daniel

Sep 5 '06 #1
3 1574
Have you tried a 'managed pointer' (I'm not sure if that's the correct term...)
e.g.,
void SomeFunc( [Out]Int32 % arg)
{
arg = 2;
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"danielp" wrote:
Hello,

In the MC++ FAQ, we can find how to map a C# "out int" argument to managed
C++. The following solution used to work, in previous version of VS, but
fails with VC# and VC++ Express:

// TestOutInt.h

#pragma once

using namespace System;
using namespace System::Runtime::InteropServices;

namespace TestOutInt {

public ref class Class1
{
public:
void SomeFunc( [Out]Int32 * arg)
{
*arg = 2;
}
};
}

// C# code
using System;
using System.Collections.Generic;
using System.Text;
using TestOutInt;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int test;
Class1 c = new Class1();
c.SomeFunc(out test);
Console.WriteLine(test.ToString());
}
}
}

It splits out the error: Argument '1': cannot convert from 'out int' to 'int*'

As mentioned the equivalent code used to work in previous version.
What am I misssing here?

-daniel
Sep 5 '06 #2
Ray
danielp wrote:
Hello,

In the MC++ FAQ, we can find how to map a C# "out int" argument to managed
C++. The following solution used to work, in previous version of VS, but
fails with VC# and VC++ Express:
<snip>

Hi Daniel,

Instead of this:
void SomeFunc( [Out]Int32 * arg)
{
*arg = 2;
}
you should do this:

void SomeFunc([Out] Int32% arg)
{
arg = 123456;
}

(Note, not Int32^%, because Int32 is a ValueType)

Then you'll C# code will work perfectly.

Cheers
Ray
Sep 5 '06 #3
you should do this:
>
void SomeFunc([Out] Int32% arg)
{
arg = 123456;
}

(Note, not Int32^%, because Int32 is a ValueType)

Then you'll C# code will work perfectly.
Thanks guys,

I guess I'll have to study the new syntax more carefully.

-daniel
Sep 5 '06 #4

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

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
21
by: Mike MacSween | last post by:
Had some trouble with Word automation. Sorted it, in the process thought I would try late binding. Some people reccomend it. So this: *********************************************************...
0
by: Groove | last post by:
(repost!) I have a simple and common scenario. I'm developing pages in VWD and FTP-ing them over to a test servr running Window 2003, NET2 Framework. On my page, I have a DDL that causes a...
1
by: Stan Maydan. from NY | last post by:
Hello, I am having difficulty mapping Managed C++ hashtable into native C++ map (string to double). Somehow the double value is not mapped properly (istead of value of 75 something like...
1
by: DanInTacoma | last post by:
Have a couple of Access MDB based applications that pull some of their data from SQL2K tables via ODBC. All the sudden we've been noticing failures. When we step through, it looks like intermediate...
4
by: MLH | last post by:
I have the following saved UNION query named qryPeople2NameInNPaperAd: SELECT & " " & & " " & & " " & & ", " & & " " & AS Item, tblVehicleJobs.VehicleJobID FROM tblVehicleJobs INNER...
3
by: RvGrah | last post by:
I seem to have acquired a strange issue here, some of my programs are now failing silently, resuming without notification that anything went wrong, both on my development machine and (I think) on...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.