473,397 Members | 1,950 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,397 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 17 '05 #1
3 986
> 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 17 '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 17 '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 17 '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). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.