AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Rizwan Muhammad Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience
Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > .NET and Visual Basic compatibility issue...

Topic: VB.NET



Expert: Syed Rizwan Muhammad Rizvi
Date: 1/23/2008
Subject: .NET and Visual Basic compatibility issue...

Question
QUESTION:   I have a C++ program that has a .NET wrapper.  That .NET wrapper's functions are being called by a Visual Basic program.  However, the Visual Basic code does not seem completely compatible with the C++ .NET code.  I talked with the C++ experts here and they referred me to the Visual Basic section.  

I have a class that returns data both in it's return and as pointers through it's arguments.  Here is a sample class:



namespace TestNamespace

{

  public ref class Status

    {

    int StatusResult;

    String StatusResultDescription;

    };



  public ref class MyClass

    {

    MyClass();

    ~MyClass();

    private:

      double  my_double_val;



    public:

      Status ^GetDoubleVal(double *DoubleVal, double TimeOut);

    };

}



How do I properly access the function GetDoubleVal from an instance of the class in Visual Basic?  Here is what I

have tried:



Dim TestClass As New TestNameSpace.MyClass

Dim StatusResult As New TestNameSpace.Status

Dim DoubleValue As Long



StatusResult = TestClass.GetDoubleVal(DoubleValue, 0.0)



Unfortunately, Visual Basic doesn't recognize the pointer argument or something for GetDoubleVal.  It gives the following error:



"'GetDoubleVal' has a return type that is not supported or parameter types that are not suported."



I have looked at the call:

Private Declare Function GetDoubleValVB Lib "TestClass.dll" Alias "TestNameSpace.GetDoubleVal" _

(ByRef DoubleVal As Long, _

 ByVal TimeOut As Long) As TestNameSpace.Status



But this won't connect to the class function and even if

it did, it wouldn't properly reference the class instance.



I would really appreciate any help you can provide.

   - Donner

ANSWER: Is this code written in C++ .Net?

---------- FOLLOW-UP ----------

QUESTION:      Yes, the .NET code is written in C++.NET.
    - Donner

ANSWER: If you add your vb.net project and C++.net in the same project, and create references to the c++ project in your vb.net project. Assuming that you classes are public in C++ you should be able to access all the methods using the typical Object Oriented way.

Try that and let me know what happens.

---------- FOLLOW-UP ----------

QUESTION:      There is no VB.NET project.  There's only the VB code
and the C++.NET code.  The Visual Basic includes the
name-spaces and can recognize all the commands that don't
have pointer arguments, but the ones that have pointer arguments it doesn't recognize as valid functions.
    - Donner

Answer
I dont know if it changes anything the way you want it to work, but can you try using & instead * and see if that works? VB.Net by design is not very good with pointers. Also if you really really want to use pointers then I would suggest a dual wrapper, i.e. one in C# to normalize it to .net sanity and then calling C# methods in Vb.net.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.