all groups > vj# > april 2004 >
You're in the

vj#

group:

Calling C++ DLL from J#


Calling C++ DLL from J# Mads Pedersen
4/9/2004 7:46:05 AM
vj#:
Hi

I hava a C++ Class Library (.NET) with a method
void compute(no1, &no2, &no3

From J# I would like to call this C++ method. I have a problem, though, that I do not know how to handle the two reference parameters (&no2 and &no3). Of course I could make two methods, each returning an answer, but the first solution is the smartest
I have seen other examples with som "ref" parameters (I thinkt it was an ActiveX control), so I guess it is possible

Thanks in advance
Re: Calling C++ DLL from J# Mads Pedersen
4/11/2004 10:11:03 AM
Yes, that's right. That's a possibility - it works, I've just testet it
Thanks a lot :-

It's correct, though, that there is no possibility to fetch reference parameters from J#, right

Re: Calling C++ DLL from J# Lars-Inge Tønnessen
4/11/2004 6:34:09 PM

You could use an array. Here is an example:

This is the managed C++ code. We want 'Compute' to return 2 and 3.

#pragma once
using namespace System;
namespace DLLManagedRef
{
public __gc class test
{
public:
void Compute( int no1, int no2 __gc[], int no3 __gc[] )
{
no2[0] = 2;
no3[0] = 3;
}
};
}


In J#.net, add a reference to the managed C++ DLL, and write:

public class Class1
{
public Class1()
{
int two[] = new int[1];
int three[] = new int[1];

DLLManagedRef.test test = new DLLManagedRef.test();
test.Compute( 1, two, three );

System.Console.WriteLine("Param two: "+two[0]);
System.Console.WriteLine("Param three: "+three[0]);
}

/** @attribute System.STAThread() */
public static void main(String[] args)
{
new Class1();
}
}


Lars-Inge Tønnessen
www.larsinge.com

Re: Calling C++ DLL from J# Lars-Inge Tønnessen
4/13/2004 5:34:04 PM
[quoted text, click to view]
parameters from J#, right?

Yes, as far as I know. Java can't do that. I have seen MSFT programmers
talking about a /** @Ref */, but I have never seen any examples in .net 1.0
or 1.1. (Maybe J# 1.2 will include this?)


Lars-Inge Tønnessen
www.larsinge.com

Re: Calling C++ DLL from J# rlacas NO[at]SPAM online.microsoft.com
4/23/2004 12:11:10 AM
Hi - You are allowed to pass J# parameters to byref methods. There is no
special syntax. The change will be reflected in the caller. What you
can't do, at least not yet, is define byref method parameters in J#.

For example, the output of the following psuedo code would be 10, not 0,
but the reverse would not work because you can't define the method in J# as
taking the param byref. You would not see the change in the caller with a
C# caller to J# method.

J#:
{
int data = 0;
ReturnByRef(data);
System.out.println(data);
}

C#:
public void ReturnByRef(ref int data)
{
data = 10;
}

|
| > It's correct, though, that there is no possibility to fetch reference
| parameters from J#, right?
|
| Yes, as far as I know. Java can't do that. I have seen MSFT programmers
| talking about a /** @Ref */, but I have never seen any examples in .net
1.0
| or 1.1. (Maybe J# 1.2 will include this?)
|
|
| Lars-Inge Tønnessen
| www.larsinge.com
|
|
|
Re: Calling C++ DLL from J# Lars-Inge Tønnessen
4/23/2004 7:18:23 PM
And in Managed C++: =:o)

void ReturnByRef( int __gc *data )
{
*data = 10;
};


I'm really looking forward to the next release of J# VS. Looks like you have
included everything we have been waiting for.

Lars-Inge Tønnessen
www.larsinge.com


AddThis Social Bookmark Button