473,385 Members | 1,400 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.

Problem Calling C++ Lib function from VB.Net

I'm trying to call a Managed C++ library function from VB and cannot get it to return
the exponent paramater in Frexp(double floatValue, int* exponent). But I'm getting
the following compile error in the vb code:

'Frexp' has a return type that is not supported or parameter types that are not
supported, which is the passed e variable in frexp(d2, e).

Below is the relevant code from the C++ library. I'm very new to C++ and know its
something very simple. Whats wrong with this C++ code?
Thanks - JackRazz
------------------------------------------------
'This is the test VB code:
Dim d1 As Double
Dim e As Integer
Dim d2 As Double = 16.4
d1 = CLib.MyMath.Frexp(d2, e)

------------------------------------------------
// CLib.h

public:
static double Frexp(double floatValue, int* exponent);
------------------------------------------------
// This is the main DLL file.

double CLib::MyMath::Frexp(double floatValue, int* exponent)
{
return frexp( floatValue, exponent );
};


Nov 16 '05 #1
3 3580
> I'm trying to call a Managed C++ library function from VB and cannot get
it to return
the exponent paramater in Frexp(double floatValue, int* exponent). But I'm getting the following compile error in the vb code:

'Frexp' has a return type that is not supported or parameter types that are not supported, which is the passed e variable in frexp(d2, e).

Below is the relevant code from the C++ library. I'm very new to C++ and know its something very simple. Whats wrong with this C++ code?
Thanks - JackRazz
------------------------------------------------
'This is the test VB code:
Dim d1 As Double
Dim e As Integer
Dim d2 As Double = 16.4
d1 = CLib.MyMath.Frexp(d2, e)

------------------------------------------------
// CLib.h

public:
static double Frexp(double floatValue, int* exponent);


The exponent variable seems to be the problem. You'll need to declare it as
a __gc pointer, and, since it is probably an out only parameter, you'll
likely want something like this:

using namespace System::Runtime::InteropServices;

static double Frexp(double floatValue, [Out] int __gc* exponent)
{
int __pin* e = exponent;

return frexp( floatValue, e );
}

--
Tomas Restrepo
to****@mvps.org
Nov 16 '05 #2
Tomas,
Thanks for help. I got it working. I had a couple of problems.

First, I couldn't get the function to compile static on the C++ side:

Frexp: 'identifier' : 'static' should not be used on member functions defined at
file scope

From CLib.h
-------------
namespace CLib
{
public __gc class MyMath
{
public:
static double Frexp(double floatValue, int __gc* exponent);
};
}

From CLib.cpp
----------------
static double CLib::MyMath::Frexp(double floatValue, int __gc* exponent)
I'm confused in that the function is under 'public:' I don't mind non static, just
trying to understand. What am I doing wrong?
Second, I got the following for the out attribute. 'CLib.h(19): error C3108: 'out' :
this attribute may not be used in a managed context' I think this one is cut and
dry - don't use [out]. Just want to make sure.

Thanks for all the help. I would never have gotten this in my own.

JackRazz



"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
|
| The exponent variable seems to be the problem. You'll need to declare it as
| a __gc pointer, and, since it is probably an out only parameter, you'll
| likely want something like this:
|
| using namespace System::Runtime::InteropServices;
|
| static double Frexp(double floatValue, [Out] int __gc* exponent)
| {
| int __pin* e = exponent;
|
| return frexp( floatValue, e );
| }
|
| --
| Tomas Restrepo
| to****@mvps.org
|
|
Nov 16 '05 #3
Hi Jack,
Tomas,
Thanks for help. I got it working. I had a couple of problems.

First, I couldn't get the function to compile static on the C++ side:

Frexp: 'identifier' : 'static' should not be used on member functions defined at file scope From CLib.h
-------------
namespace CLib
{
public __gc class MyMath
{
public:
static double Frexp(double floatValue, int __gc* exponent);
};
}

From CLib.cpp
----------------
static double CLib::MyMath::Frexp(double floatValue, int __gc* exponent)
You should only put static on the method declaration, not the definition
(just remove it from CLib.cpp).
I'm confused in that the function is under 'public:' I don't mind non static, just trying to understand. What am I doing wrong?
Second, I got the following for the out attribute. 'CLib.h(19): error C3108: 'out' : this attribute may not be used in a managed context' I think this one is cut and dry - don't use [out]. Just want to make sure.


Case problem: It's [Out] not [out].
Also, make sure you add a using namespace System::Runtime::InteropServices;

--
Tomas Restrepo
to****@mvps.org
Nov 16 '05 #4

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

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
2
by: Pawan Aggarwal | last post by:
I'm having trouble with calling an exported function in a native DLL compiled with eMbedded Visual C++ in C# application in PocketPC 2002 OS. Problem Description follows: I have one exported...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: gzannd | last post by:
I have a problem with submitting a form to a PHP page through a dynamically created IFRAME in IE7. This code works fine in Firefox. However, IE7 submits an empty form--the correct PHP page is...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
1
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I want to give multiple native classes (in different mixed mode dlls) access to a managed output window (for error messages). Therefore I wrote a native singleton with __declspec...
3
by: ShambhuHubli | last post by:
Hi all!! .. I am New member to this group. And also new to C/PYTHON API coding. I am trying to have two way communication i,e i am calling from python to C and then from C to python. I have no...
47
by: mukeshrasm | last post by:
Hi I am calling two pages using Ajax Get_Pages.php and Get_Content.php from combo box. Both pages are displayed based on selection from combo box. Main problem is that it is not showing the...
1
by: JohnCox | last post by:
I have a simple Win32 DLL I wrote named "SimpleLib" that exports two functions. It is written in C++ and compiled with __stdcall (/Gz) and with the preprocessor definition _MBCS (not Unicode). ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.