Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / April 2004

Tip: Looking for answers? Try searching our database.

Calling C++ DLL from J#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mads Pedersen - 09 Apr 2004 15:46 GMT
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
Mads Pedersen
Lars-Inge T?nnessen - 11 Apr 2004 17:34 GMT
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
Mads Pedersen - 11 Apr 2004 18:11 GMT
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

/Mads
Lars-Inge T?nnessen - 13 Apr 2004 16:34 GMT
> 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
Bob LaCasse [MSFT] - 23 Apr 2004 01:11 GMT
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?
[quoted text clipped - 5 lines]
| Lars-Inge T?nnessen
| www.larsinge.com
Lars-Inge T?nnessen - 23 Apr 2004 18:18 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.