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 / C++ Libraries / February 2004

Tip: Looking for answers? Try searching our database.

How to export an array from VB .NET in VC++ .NET?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dr. Zharkov - 11 Feb 2004 19:31 GMT
We want to export myArrayVB (2000, 2) of VB .NET 2003 in myArrayV? [2000, 2]
of VC++ .NET 2003 on scheme "component -  client". But there is an error.

For development of a component in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Class Library, name of project: ComponentVB. We write
the code:

Public Function myFunction1(ByVal N_i As Integer, _

ByVal N_j As Integer) As Array

   N_i = 2000

   N_j = 2

   Dim myArrayVB As Array = _

   Array.CreateInstance(GetType(Single), N_i, N_j)

   For ii As Integer = 0 To N_i - 1

       For jj As Integer = 0 To N_j - 1

           myArrayVB(ii, jj) = 1

       Next

   Next

   Return myArrayVB(, )

End Function

For development of the client in VC++ .NET 2003 we make: File, New, Project,
Visual C++ Projects, (.NET), Windows Forms Application (.NET), name of
project: ClientVC. On Form1 we place control Panel (on which we want to
build a surface myArrayVB with the help of method DrawLine), and we write
the code:

#using <mscorlib.dll>

#using "Debug\ComponentVB.dll"

private:

System::Void panel1_Paint(System::Object *  sender,

System::Windows::Forms::PaintEventArgs *  e)

{

    ComponentVB::Class1* myObject =

    new ComponentVB::Class1();

    int N_i = 2000;

    int N_j = 2;

    float myArrayVC __gc[,] = new float __gc[N_i, N_j];

    for (int i = 0; i <= N_i - 1; i++)

          for (int j = 0; j <= N_j - 1; j++)

               myArrayVC[i, j] =

myArrayVC->SetValue(myObject->myFunction1(2000, 2), i, j);//Error.

}

Inform, please, how to correct this code, to export myArrayVB in myArrayVC?

Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
Emad Barsoum - 16 Feb 2004 01:00 GMT
Hi,

   For class library project in VB.Net, to add the namespace of
System.Drawing, you need to add reference to its assembly first, because it
is not included by default as normal winform application and to do that:

   Select the Solution explorer tree, and rigth clicl on references then
click add, and select the following assembly: System.Drawing.dll, double
click on it and click ok. After that the "Imports System.Drawing" will work
without any error.

In the C++, to create a managed array which will be compatible with the
VB.Net array, by the same way as you did in VB.Net as follow:

   Array* myArray=Array::CreateInstance( __typeof(float), 2000, 2);

Than about this command:

    for (int i = 0; i <= 2000; i++)
      for (int j = 0; j <= 1; j++){
       myArrayVC->SetValue(myObject->myFunction1(), i, j); //Error 2.
}

The "myObject->myFunction1()", return the entire array at once, so why you
make two for loops, according to this code at each elements of the Visual
C++ array you try to put the entire 2000 elements of VB.Net array which will
not work at all. So the code should be like the following:

       Array* myArray=Array::CreateInstance( __typeof(float), 2000, 2);

     for (int i = 0; i <= 2000; i++)
      for (int j = 0; j <= 1; j++){
       myArrayVC->SetValue(myObject->myFunction1()->GetValue(i,j), i, j); }

Or without any for loop you can do the following:

   Array* myArray = myObject->myFunction1(); // but in this case the array
in the VB.Net library need to be a member variable not defining inside the
class.

Also inside the member function "Public Function myFunction1() As Array",
you should not creat the Array, because when you return it, it can be delete
by the garbage collection, you should define the array as a member variables
of the class.

Regards,
Emad Barsoum
Dr. Zharkov - 17 Feb 2004 00:00 GMT
Dear Mr. Emad Barsoum.

Many thanks for your consultation. Following your guidelines, we have made:

We want to export myArrayVB (2000, 2) of VB .NET 2003 in myArrayV? [2000, 2]
of VC++ .NET 2003 on scheme "component -  client". But there is an error.

For development of a component in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Class Library, name of project: ComponentVB. We write
the code:

Public Function myFunction1()

   Dim i, j As Integer

   Dim N_x As Integer = 2000

   Dim N_y As Integer = 1

   Dim myArrayVB(N_x, N_y) As Single

   For i = 0 To N_x

       For j = 0 To N_y

           myArrayVB(i, j) = 1

       Next

   Next

   Return myArrayVB

End Function

For development of the client in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Windows Application, name of project: ClientVB. On
Form1 we place control PictureBox. We add: Project, Add Reference,
ComponentVB.dll. And we write the code:

Private Sub PictureBox1_Paint(ByVal sender As Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles PictureBox1.Paint

   Dim i, j As Integer

   Dim N_x As Integer = 2000

   Dim N_y As Integer = 1

   Dim myArrayVB_Client(N_x, N_y) As Single

   Dim myObject As New ComponentVB.Class1

   For i = 0 To N_x

       For j = 0 To N_y

           myArrayVB_Client(i, j) = myObject.myFunction1(i, j)

       Next

   Next

   MsgBox("myArrayVB_Client(0,0 ) = " _

   & myArrayVB_Client(0, 0)) ' = 1, ok.

   End Sub

Export of an array from VB in VB we have fulfilled without errors.

For development of the client in VC++ .NET 2003 we make: File, New, Project,
Visual C++ Projects, (.NET), Windows Forms Application (.NET), name of
project: ClientVC. On Form1 we place control PictureBox, and we write the
code:

#using <mscorlib.dll>

#using "Debug\ComponentVB.dll"

private:

System::Void pictureBox1_Paint(System::Object *  sender,

System::Windows::Forms::PaintEventArgs *  e)

{

   ComponentVB::Class1* myObject = new ComponentVB::Class1();

   int i, j;

   int N_x = 2001;

   int N_y = 2;

   float myArrayVC __gc[,] = new float __gc[N_x, N_y];

   for (int i = 0 ; i <= N_x - 1; i++)

   for (int j = 0 ; j <= N_y - 1; j++)

   myArrayVC[i, j] = myObject->myFunction1(i, j); //Error.

}

Inform, please, how to correct this code C++, to export myArrayVB in
myArrayVC?

Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
Emad Barsoum - 16 Feb 2004 18:51 GMT
Hi Dr. Zharkov,

   I test it, this code and it should work as follow:

   ComponentVB::Class1* myObject = newComponentVB::Class1();

   int i, j;

   int N_x = 2001;

   int N_y = 2;

   Array* myArray = (Array*)myObject->myFunction1();

   float myArrayVC __gc[,] = new float __gc[N_x, N_y];

   for (int i = 0 ; i <= N_x - 1; i++)

       for (int j = 0 ; j <= N_y - 1; j++)

           myArrayVC[i, j] =
System::Convert::ToSingle(myArray->GetValue(i,j));

Each array in .Net is of type "object*" So you need to convert them to
normal data type in this case float, in VB it is done automatic.

Regards,

Emad

> Dear Mr. Emad Barsoum.
>
[quoted text clipped - 109 lines]
>
> Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
Dr. Zharkov - 17 Feb 2004 21:15 GMT
Dear Mr. Emad Barsoum.

Now it's OK works.

Big many thanks. Dr. Zharkov V.A., Moscow, Russia.
Dr. Zharkov - 18 Feb 2004 17:32 GMT
Dear Mr. Emad Barsoum.

You are the superprofessional on C++.

Excuse me, please, but at me to you one more big request to answer following
my question.

How in VC++ .NET to see character of Microsoft Agent?

To see character of Microsoft Agent in Visual Basic .NET 2003, we create the
project: File, New, Project, Visual Basic Project, Windows Application. In
Form1 we place two controls: Button and Microsoft Agent Control 2.0. We
write down a code:

Dim myGenie As AgentObjects.IAgentCtlCharacterEx

Const DATAPATH_1 As String = "genie.acs"

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

   AxAgent1.Characters.Load("Genie", DATAPATH_1)

   myGenie = AxAgent1.Characters("Genie")

   myGenie.Show()

End Sub

After Start and click of button we see Genie.

To see character of Microsoft Agent in Visual C++ .NET 2003, similarly we
create the project: File, New, Project, Visual C++ Projects, (.NET), Windows
Forms Application (.NET). In Form1 we place two controls: button and
Microsoft Agent Control 2.0. We write down a code:

using namespace Interop;

static AgentObjects::AgentClass* myGenie =

new AgentObjects::AgentClass();

static String* DATAPATH_1 = "genie.acs";

private:

System::Void button1_Click(System::Object *  sender,

System::EventArgs *  e)

{

    myGenie->Characters->Load("Genie", DATAPATH_1);

    myGenie->add_Show(0);

}

After Start and click of button we do not see Genie.

How in VC++ .NET 2003 to write this code, to see character of Microsoft
Agent?

Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.

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.