473,396 Members | 1,998 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,396 software developers and data experts.

Error Returning Float from C dll

A am receiving an error when attempting to return a float from a C function.

The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();

float temp = testfloat();

Any help is appreciated.
Nov 16 '05 #1
5 2228
beto <be*****@excite.com> wrote:
A am receiving an error when attempting to return a float from a C function.


What error are you receiving? I would also suggest that the interop
group might well give you useful answers, if no-one here knows.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
> A am receiving an error when attempting to return a float from a C function.

The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();


try specifying the "__stdcall" calling convention for the C++ function
ex.

DLL float __stdcall testfloat()
Nov 16 '05 #3
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MP************************@msnews.microsoft. com>...
beto <be*****@excite.com> wrote:
A am receiving an error when attempting to return a float from a C function.


What error are you receiving? I would also suggest that the interop
group might well give you useful answers, if no-one here knows.


A managed NotSupportedException occurred at Application::Fun+0xf
Nov 16 '05 #4
"Steve Waggoner" <steve (nospam) waggoner@anysite (nospam) com> wrote in message news:<#o*************@TK2MSFTNGP10.phx.gbl>...
A am receiving an error when attempting to return a float from a C function.

The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();


try specifying the "__stdcall" calling convention for the C++ function
ex.

DLL float __stdcall testfloat()


Still received the same error message.
Nov 16 '05 #5
The solution that ended up working was to return just an integer that
reported the final status of the dll. To return the float, a reference
was passed to the dll and then used by the C# application.

Example:
[DllImport(".\\testfloat.dll")]
static extern int testfloat([In, Out] float[] returnf);

float[] returnf = new float[] {0,0,0,0};
int status = testfloat(returnf);

be*****@excite.com (beto) wrote in message news:<7d**************************@posting.google. com>...
A am receiving an error when attempting to return a float from a C function.

The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();

float temp = testfloat();

Any help is appreciated.

Nov 16 '05 #6

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

Similar topics

9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
3
by: James Phillips | last post by:
can anyone tell me how to correct the error in this code snippet: ? #include <iostream> #include <stdlib.h> #include <cmath> #include <float.h> using namespace std;
7
by: Richard | last post by:
I got 2 error in the program code below, but I don't know what they are and how to fix it. Can anyone put it in compile and tell me what is wrong? I am new to c++ #include <iostream> #include...
4
by: yanyo | last post by:
hi, im trying to figure out whats the problem with this program i get a runtime error but i dont see where the problem is i tried changing declaration but nothing if somrbody can try this on their...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
10
by: randomtalk | last post by:
hello, i have another problem i feel that i have to be missing something.. Basically, i've written a recursive function to find all the prime up to a number (lim).. here is the function: The...
3
by: ehabaziz2001 | last post by:
When I rename the variables d,p TO : do,po in all the module of : void convert_meter(float *me,float *d,float *p) I got an error of that line of : void convert_meter(float *me,float *d,float *p)...
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
11
by: Peter | last post by:
I have written this small app to explain an issue I'm having with a larger program. In the following code I'm taking 10 ints from the keyboard. In the call to average() these 10 ints are then...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.