eVC4 DLL Interop Problem with double ????

S

Sagaert Johan

System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
M

Maarten Struys, eMVP

Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by reference. If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.
 
C

Chris Tacke, eMVP

I've not tried it, but you might be able to pass the double as a byte array.
It would only take a minute to test with the code you already have.

-Chris



Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by reference. If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

Sagaert Johan said:
System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
P

Peter Foot [MVP]

I think this would only work if the native dll expected a pointer rather
than a double by value. A byte[] will be marshalled as a pointer to a memory
buffer, if your dll expects a pointer to a double you can use a .net double
by reference e.g.

If your native function is
fnLocators4 (double * a)

your P/Invoke would be
public static extern void fnLocators4(ref double a)

If you can't change the native dll yourself, you'll need a wrapper dll
(again written in eVC++4) which acts as a go between.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org


Chris Tacke said:
I've not tried it, but you might be able to pass the double as a byte array.
It would only take a minute to test with the code you already have.

-Chris



Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by
reference.
If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

Sagaert Johan said:
System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
S

Sagaert Johan

Thanks for replying

I modified my DLL for using pointers

Peter Foot said:
I think this would only work if the native dll expected a pointer rather
than a double by value. A byte[] will be marshalled as a pointer to a memory
buffer, if your dll expects a pointer to a double you can use a .net double
by reference e.g.

If your native function is
fnLocators4 (double * a)

your P/Invoke would be
public static extern void fnLocators4(ref double a)

If you can't change the native dll yourself, you'll need a wrapper dll
(again written in eVC++4) which acts as a go between.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org


Chris Tacke said:
I've not tried it, but you might be able to pass the double as a byte array.
It would only take a minute to test with the code you already have.

-Chris



Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by
reference.
If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double
*
b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
S

Sagaert Johan

I suppose i have the same problem with function returing a double ?

i think i should modify the functions so the result is returned via the
parameter list. Right ?

Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by reference. If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

Sagaert Johan said:
System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
A

Alex Feinman [MVP]

Right
Sagaert Johan said:
I suppose i have the same problem with function returing a double ?

i think i should modify the functions so the result is returned via the
parameter list. Right ?

Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by
reference.
If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

Sagaert Johan said:
System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
P

Peter Foot [MVP]

Yes have a function which takes a pointer to a double and return the value
that way e.g.

GetDouble(double* a)


Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

Sagaert Johan said:
I suppose i have the same problem with function returing a double ?

i think i should modify the functions so the result is returned via the
parameter list. Right ?

Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by
reference.
If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

Sagaert Johan said:
System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 
G

Geoff Schwab [MSFT]

Hi,

Here is a FAQ item that should help you determine how to pass parameters
to/from native code:

6.10. What are the limitations on marshalling types via P/Invoke?
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx#6.10

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
Sagaert Johan said:
I suppose i have the same problem with function returing a double ?

i think i should modify the functions so the result is returned via the
parameter list. Right ?

Maarten Struys said:
Passing value types that are greater than 32 bits is not supported, therefor
you can't pass a double by value. You can only pass doubles by
reference.
If
you are the owner of fnLocators4 (double a) as well, you might be able to
modify it to int fnLocators4(double *a). Otherwise you need to write a C
wrapper in which you pass a double by reference from managed code and call
the original fnLocators4 from that wrapper function.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

Sagaert Johan said:
System.NotSupportedException

In short:
i am calling functions from a CF application that reside in a DLL created
with eVC4
through interop services i use these in my CF app.

When i call the function Locators4(double a) i get an
System.NotSupportedException.
All other functions work, except this one (where i pass a double)

Any idea about this problem or is this a CF limitation ?


in my eVC4 DLL i have these declared functions:

extern "C" __declspec(dllexport) int fnLocators(void);
extern "C" __declspec(dllexport) int fnLocators2(int a);
extern "C" __declspec(dllexport) int fnLocators3(double * a,double * b);
extern "C" __declspec(dllexport) int fnLocators4(double a);





in my C# CF app i have declared these in a class :

public class myclass

{

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators")]

public static extern int Locators();

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators2")]

public static extern int Locators2(int a);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators3",
CharSet=CharSet.Auto)]

public static extern int Locators3(ref double a,ref double b);

[DllImport(@"\windows\locators.dll", EntryPoint="fnLocators4",
CharSet=CharSet.Auto)]

public static extern int Locators4(double a);



}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top