473,799 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call a C function that has parameter of float got NotSupportedExc eption?

Dear All:

I create a very simple DLL by using EVC to test the problem. (The platform I
am working for those program is WinCE.NET)

*************** *************** *************** **********
The header looks like:

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

TESTDLL_API LONG fnTestF(FLOAT var1);

*************** *************** *************** **********
The C source looks like:
#include "stdafx.h"
#include "TestDll.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
switch (ul_reason_for_ call)
{
case DLL_PROCESS_ATT ACH:
case DLL_THREAD_ATTA CH:
case DLL_THREAD_DETA CH:
case DLL_PROCESS_DET ACH:
break;
}
return TRUE;
}
TESTDLL_API LONG fnTestF(FLOAT var1)
{
return 0;
}

*************** *************** *************** **********
The DEF file look like:
LIBRARY TestDll
EXPORTS
fnTestF
*************** *************** *************** **********

After build up this DLL, I try to write a C# program to call this function.
The C# program looks like:

[DllImport("test dll.dll")]
private static extern Int32 fnTestF
(
Single fPeriod
);

When I call this function likes bellow:
Single fVal = 0.1f;
Int32 i32Ret;

try
{
i32Ret = fnTestF(fVal);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Exception! ");
}

I always get an exception called "NotSupportedEx ception".

Any idea about this?

Thanks!

Tony Liu

Nov 16 '05 #1
3 2108
Tony, if you're code is in a .CPP file, you may be generating a mangled name
function. Open your DLL in in the "Depends" utility and look in the
exports section to see what the name look likes. If it is mangled, just add
the following to your .H file.

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

// ---- new code ----
#ifdef __cplusplus
extern "C"{
#endif
// ----------------------

TESTDLL_API LONG fnTestF(FLOAT var1);

// ---- new code ----
#ifdef __cplusplus
};
#endif
// ----------------------
Gary ...
"Tony Liu" <he******@ms21. hinet.net> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Dear All:

I create a very simple DLL by using EVC to test the problem. (The platform I am working for those program is WinCE.NET)

*************** *************** *************** **********
The header looks like:

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

TESTDLL_API LONG fnTestF(FLOAT var1);

*************** *************** *************** **********
The C source looks like:
#include "stdafx.h"
#include "TestDll.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
switch (ul_reason_for_ call)
{
case DLL_PROCESS_ATT ACH:
case DLL_THREAD_ATTA CH:
case DLL_THREAD_DETA CH:
case DLL_PROCESS_DET ACH:
break;
}
return TRUE;
}
TESTDLL_API LONG fnTestF(FLOAT var1)
{
return 0;
}

*************** *************** *************** **********
The DEF file look like:
LIBRARY TestDll
EXPORTS
fnTestF
*************** *************** *************** **********

After build up this DLL, I try to write a C# program to call this function. The C# program looks like:

[DllImport("test dll.dll")]
private static extern Int32 fnTestF
(
Single fPeriod
);

When I call this function likes bellow:
Single fVal = 0.1f;
Int32 i32Ret;

try
{
i32Ret = fnTestF(fVal);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Exception! ");
}

I always get an exception called "NotSupportedEx ception".

Any idea about this?

Thanks!

Tony Liu


Nov 16 '05 #2
Finally, I found a document in MSDN 2003:
The topic of the document is "Non Blittable Types and Marshaling Support"
A section of this document:
Visual C and Visual C++ Marshaling Results
The following table lists Visual C and Visual C++ types used by the
marshaler for managed types, with Windows CE .NET as the operating system
hosting the unmanaged code. This list is not comprehensive.

Managed Code
Visual C# Types
Managed Code
Visual Basic Types
Unmanaged Code
ByVal
Unmanaged Code
ByRef

bool
Boolean
BYTE
BYTE *

int
Integer
INT32
INT32 *

short
Short
SHORT
SHORT *

long
Long
Not supported
INT64 *

char
Char
WCHAR
WCHAR *

float
Single
Not supported
FLOAT *

double
Double
Not supported
DOUBLE *

String
String
WCHAR *
Not supported

StringBuilder
StringBuilder
WCHAR *
Not supported

DateTime
DateTime
Not supported
Not supported

int[]
Integer()
INT32 *, INT32[]
Not supported

I think that is the reason why I cannot pass a "FLOAT" by value.

Tony

"Gary James" <ga***@iotech.c om> ???
news:e6******** *****@tk2msftng p13.phx.gbl ???...
Tony, if you're code is in a .CPP file, you may be generating a mangled name function. Open your DLL in in the "Depends" utility and look in the
exports section to see what the name look likes. If it is mangled, just add the following to your .H file.

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

// ---- new code ----
#ifdef __cplusplus
extern "C"{
#endif
// ----------------------

TESTDLL_API LONG fnTestF(FLOAT var1);

// ---- new code ----
#ifdef __cplusplus
};
#endif
// ----------------------
Gary ...
"Tony Liu" <he******@ms21. hinet.net> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Dear All:

I create a very simple DLL by using EVC to test the problem. (The
platform I
am working for those program is WinCE.NET)

*************** *************** *************** **********
The header looks like:

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

TESTDLL_API LONG fnTestF(FLOAT var1);

*************** *************** *************** **********
The C source looks like:
#include "stdafx.h"
#include "TestDll.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
switch (ul_reason_for_ call)
{
case DLL_PROCESS_ATT ACH:
case DLL_THREAD_ATTA CH:
case DLL_THREAD_DETA CH:
case DLL_PROCESS_DET ACH:
break;
}
return TRUE;
}
TESTDLL_API LONG fnTestF(FLOAT var1)
{
return 0;
}

*************** *************** *************** **********
The DEF file look like:
LIBRARY TestDll
EXPORTS
fnTestF
*************** *************** *************** **********

After build up this DLL, I try to write a C# program to call this

function.
The C# program looks like:

[DllImport("test dll.dll")]
private static extern Int32 fnTestF
(
Single fPeriod
);

When I call this function likes bellow:
Single fVal = 0.1f;
Int32 i32Ret;

try
{
i32Ret = fnTestF(fVal);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Exception! ");
}

I always get an exception called "NotSupportedEx ception".

Any idea about this?

Thanks!

Tony Liu

Nov 16 '05 #3
Finally, I found a document in MSDN 2003:
The topic of the document is "Non Blittable Types and Marshaling Support"
A section of this document:
Visual C and Visual C++ Marshaling Results
The following table lists Visual C and Visual C++ types used by the
marshaler for managed types, with Windows CE .NET as the operating system
hosting the unmanaged code. This list is not comprehensive.

Managed Code
Visual C# Types
Managed Code
Visual Basic Types
Unmanaged Code
ByVal
Unmanaged Code
ByRef

bool
Boolean
BYTE
BYTE *

int
Integer
INT32
INT32 *

short
Short
SHORT
SHORT *

long
Long
Not supported
INT64 *

char
Char
WCHAR
WCHAR *

float
Single
Not supported
FLOAT *

double
Double
Not supported
DOUBLE *

String
String
WCHAR *
Not supported

StringBuilder
StringBuilder
WCHAR *
Not supported

DateTime
DateTime
Not supported
Not supported

int[]
Integer()
INT32 *, INT32[]
Not supported

I think that is the reason why I cannot pass a "FLOAT" by value.

Tony

"Gary James" <ga***@iotech.c om> ???
news:e6******** *****@tk2msftng p13.phx.gbl ???...
Tony, if you're code is in a .CPP file, you may be generating a mangled name function. Open your DLL in in the "Depends" utility and look in the
exports section to see what the name look likes. If it is mangled, just add the following to your .H file.

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

// ---- new code ----
#ifdef __cplusplus
extern "C"{
#endif
// ----------------------

TESTDLL_API LONG fnTestF(FLOAT var1);

// ---- new code ----
#ifdef __cplusplus
};
#endif
// ----------------------
Gary ...
"Tony Liu" <he******@ms21. hinet.net> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Dear All:

I create a very simple DLL by using EVC to test the problem. (The
platform I
am working for those program is WinCE.NET)

*************** *************** *************** **********
The header looks like:

#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dlle xport)
#else
#define TESTDLL_API __declspec(dlli mport)
#endif

TESTDLL_API LONG fnTestF(FLOAT var1);

*************** *************** *************** **********
The C source looks like:
#include "stdafx.h"
#include "TestDll.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
switch (ul_reason_for_ call)
{
case DLL_PROCESS_ATT ACH:
case DLL_THREAD_ATTA CH:
case DLL_THREAD_DETA CH:
case DLL_PROCESS_DET ACH:
break;
}
return TRUE;
}
TESTDLL_API LONG fnTestF(FLOAT var1)
{
return 0;
}

*************** *************** *************** **********
The DEF file look like:
LIBRARY TestDll
EXPORTS
fnTestF
*************** *************** *************** **********

After build up this DLL, I try to write a C# program to call this

function.
The C# program looks like:

[DllImport("test dll.dll")]
private static extern Int32 fnTestF
(
Single fPeriod
);

When I call this function likes bellow:
Single fVal = 0.1f;
Int32 i32Ret;

try
{
i32Ret = fnTestF(fVal);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Exception! ");
}

I always get an exception called "NotSupportedEx ception".

Any idea about this?

Thanks!

Tony Liu

Nov 16 '05 #4

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

Similar topics

6
1971
by: komal | last post by:
hi all basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is calling function can be anything. for example.suppose my function is function2. then when i call function1(int i ,char j,float d) { function2()
28
15395
by: Michael B. | last post by:
I tend to use rather descriptive names for parameters, so the old style of declaration appeals to me, as I can keep a declaration within 80 chars: void * newKlElem (frame_size,num_blocks,num_frames,frame_locator) size_t frame_size; unsigned short num_blocks; unsigned short num_frames; Kl_frame_locator *locator; { /* code goes here */
20
10764
by: spasmous | last post by:
main() { float * f; initialize_f(f); // ...use f for processing free(f); }
6
7614
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
6
2298
by: Martin Bootsma | last post by:
I have a C question, which looks very easy, but no one here seems to know an easy answer. I have a function "powell" (from Numerical Recipes) which takes an argument of the type "double (*f)(float)" But I want to be able to pass a
3
2391
by: pyramid | last post by:
Hello. My lab compiles with no problems, but the results are inconsistent. Using 2,2,2, as test data, the result is correct, perimeter of 6.000, and area of 1.732. However, when I try to use 8,5,12, the result is perimeter of 24 (should be 25), and area of 0.000 (should be 14.52 The lab specifies that we store the result of "s" and '"area" in reference parameters s and area. Any input would be greatly appreciated. Thank you...
4
2090
by: Sheldon | last post by:
Hi Everybody, I am having trouble with a fairly simple problem, I am sure. I have a structure that contains 2D arrays: struct S { float array; ..... snip
9
2380
by: Yannick | last post by:
Hi everyone - I am not quite sure to understand what is really going on when a function defined in one translation unit calls a function defined in a different translation unit without knowing its prototype. Let's say for instance : foo.c #include <stdio.h>
1
5610
by: natvarara | last post by:
#include <stdio.h> #include <string.h> #include <conio.h> #include <ctype.h> void print_line(); /*function line*/ void show_menu(); /*function menu*/ void circle(float); /*function circle*/ void triangle(float,float); /*function triangle*/ void trapezoid(float,float,float); /*function trapazoid*/
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.