EXCEPTION : Importing DLL from eVC with double type parameter

  • Thread starter Thread starter Kristijan Marin
  • Start date Start date
K

Kristijan Marin

Hi,

If I try to import a method that has 'double' as a return values or as
a parameter then when trying to call that method I get UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from the example
below,
if this "krispi.dll" exists or not i always get this exception. I also get
this exception is DLL file exists.
If changing double to int and DLL exists then MissingMethodException is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
8-bit types are not marshalled by CF. If you need to return double, rewrite
your unmanaged code to accept double* as a parameter and on the managed side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}
 
I can't use double as an input parameter like this in your
example :
static extern void M1( double dDeg, out double retVal );


If i leave dDeg to be declared as it is showen above , i still get
NotSupportedException.
Should all doubles be declared as pointers ?

Thx.


Alex Feinman said:
8-bit types are not marshalled by CF. If you need to return double, rewrite
your unmanaged code to accept double* as a parameter and on the managed side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}

--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Hi,

If I try to import a method that has 'double' as a return values or as
a parameter then when trying to call that method I get
UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from the
example
below,
if this "krispi.dll" exists or not i always get this exception. I also get
this exception is DLL file exists.
If changing double to int and DLL exists then MissingMethodException is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
Any clue how I should call functions declared in eVC DLL which declaration
is as follows :

__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

__declspec( dllexport ) int P2( int nType, double dLat, double dLon, TCHAR*
pzPos );

__declspec( dllexport ) double P3( double dDeg );

Thx a lot .

Krispi



Kristijan Marin said:
I can't use double as an input parameter like this in your
example :
static extern void M1( double dDeg, out double retVal );


If i leave dDeg to be declared as it is showen above , i still get
NotSupportedException.
Should all doubles be declared as pointers ?

Thx.


Alex Feinman said:
8-bit types are not marshalled by CF. If you need to return double, rewrite
your unmanaged code to accept double* as a parameter and on the managed side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}

--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Hi,

If I try to import a method that has 'double' as a return values or as
a parameter then when trying to call that method I get
UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from the
example
below,
if this "krispi.dll" exists or not i always get this exception. I also get
this exception is DLL file exists.
If changing double to int and DLL exists then MissingMethodException is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
Sorry, I was not thinking clearly. Of course *all* the doubles should be
passed as pointers.

--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
I can't use double as an input parameter like this in your
example :
static extern void M1( double dDeg, out double retVal );


If i leave dDeg to be declared as it is showen above , i still get
NotSupportedException.
Should all doubles be declared as pointers ?

Thx.


Alex Feinman said:
8-bit types are not marshalled by CF. If you need to return double, rewrite
your unmanaged code to accept double* as a parameter and on the managed side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}

--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Hi,

If I try to import a method that has 'double' as a return values or as
a parameter then when trying to call that method I get
UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from the
example
below,
if this "krispi.dll" exists or not i always get this exception. I also get
this exception is DLL file exists.
If changing double to int and DLL exists then MissingMethodException is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

extern static int P1(string pzPos, ref double pdLat, ref double pdLon)


__declspec( dllexport ) int P2( int nType, double dLat, double dLon, TCHAR*
pzPos );
This one cannot be invoked without changing its signature to pass doubles by
ref



__declspec( dllexport ) double P3( double dDeg );
Same here. Change the function prototype to look like this:

__declspec( dllexport ) void P3( double* pdDeg, double* retVal );

extern static void P3(ref double pdDeg, out double retVal)


--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Any clue how I should call functions declared in eVC DLL which declaration
is as follows :

__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

__declspec( dllexport ) int P2( int nType, double dLat, double dLon,
TCHAR*
pzPos );

__declspec( dllexport ) double P3( double dDeg );

Thx a lot .

Krispi



Kristijan Marin said:
I can't use double as an input parameter like this in your
example :
static extern void M1( double dDeg, out double retVal );


If i leave dDeg to be declared as it is showen above , i still get
NotSupportedException.
Should all doubles be declared as pointers ?

Thx.


Alex Feinman said:
8-bit types are not marshalled by CF. If you need to return double, rewrite
your unmanaged code to accept double* as a parameter and on the managed side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hi,

If I try to import a method that has 'double' as a return values or
as
a parameter then when trying to call that method I get
UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from the
example
below,
if this "krispi.dll" exists or not i always get this exception. I
also get
this exception is DLL file exists.
If changing double to int and DLL exists then MissingMethodException is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just
guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
Hi Alex, again ;)

Look.. Now I've tried this as you described and i still can't get this to
work.

My declaration in DLL :
__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

Your definition in c#
extern static int P1(string pzPos, ref double pdLat, ref double pdLon)


My results:

if my definition is extern static int P1(string pzPos, ref double pdLat, ref
double pdLon)
Then i get MissingMethodException

If setting string as REF so that declaration looks like this :extern static
int P1( REF string pzPos, ref double pdLat, ref double pdLon)

then i get NotSupportedException

IF your suggestion is correct, why do i get then this
MissingMethodException ?

IF my declaration is correct, do i get then this NotSupportedException
because of INT not beeing returned as a parameter from the method ?

Thanks a lot.
Kris








Alex Feinman said:
__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

extern static int P1(string pzPos, ref double pdLat, ref double pdLon)


__declspec( dllexport ) int P2( int nType, double dLat, double dLon, TCHAR*
pzPos );
This one cannot be invoked without changing its signature to pass doubles by
ref



__declspec( dllexport ) double P3( double dDeg );
Same here. Change the function prototype to look like this:

__declspec( dllexport ) void P3( double* pdDeg, double* retVal );

extern static void P3(ref double pdDeg, out double retVal)


--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Any clue how I should call functions declared in eVC DLL which declaration
is as follows :

__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

__declspec( dllexport ) int P2( int nType, double dLat, double dLon,
TCHAR*
pzPos );

__declspec( dllexport ) double P3( double dDeg );

Thx a lot .

Krispi



Kristijan Marin said:
I can't use double as an input parameter like this in your
example :
static extern void M1( double dDeg, out double retVal );


If i leave dDeg to be declared as it is showen above , i still get
NotSupportedException.
Should all doubles be declared as pointers ?

Thx.


8-bit types are not marshalled by CF. If you need to return double,
rewrite
your unmanaged code to accept double* as a parameter and on the managed
side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hi,

If I try to import a method that has 'double' as a return values or
as
a parameter then when trying to call that method I get
UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from the
example
below,
if this "krispi.dll" exists or not i always get this exception. I
also
get
this exception is DLL file exists.
If changing double to int and DLL exists then
MissingMethodException
is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just
guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
NotSupportedException is thrown by the marshaller if it detects that the
function signature contains unsupported types or references. This is done
*before* the DLL that contains the import is even attempted to load. The
MissingMethod exception is thrown when the DLL is not found or it is found
but the specified export is missing. Things to check - 1) dll is deployed to
the same directory as the app (make it a part of the project and set build
action to Content); 2) dll is built for the proper CPU (ARM4 for device, x86
for emulator); 3) DLL does not have references to another DLL that is ot
present; 4) Function is exported (use dumpbin /exports from Visual Studio);
5) Function name is not mangled (to make ssure that it is not, declare it
with extern "C" )

--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Hi Alex, again ;)

Look.. Now I've tried this as you described and i still can't get this to
work.

My declaration in DLL :
__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

Your definition in c#
extern static int P1(string pzPos, ref double pdLat, ref double pdLon)


My results:

if my definition is extern static int P1(string pzPos, ref double pdLat,
ref
double pdLon)
Then i get MissingMethodException

If setting string as REF so that declaration looks like this :extern
static
int P1( REF string pzPos, ref double pdLat, ref double pdLon)

then i get NotSupportedException

IF your suggestion is correct, why do i get then this
MissingMethodException ?

IF my declaration is correct, do i get then this NotSupportedException
because of INT not beeing returned as a parameter from the method ?

Thanks a lot.
Kris








Alex Feinman said:
__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat,
double*
pdLon );

extern static int P1(string pzPos, ref double pdLat, ref double pdLon)


__declspec( dllexport ) int P2( int nType, double dLat, double dLon, TCHAR*
pzPos );
This one cannot be invoked without changing its signature to pass doubles by
ref



__declspec( dllexport ) double P3( double dDeg );
Same here. Change the function prototype to look like this:

__declspec( dllexport ) void P3( double* pdDeg, double* retVal );

extern static void P3(ref double pdDeg, out double retVal)


--
Alex Feinman
---
Visit http://www.opennetcf.org
Kristijan Marin said:
Any clue how I should call functions declared in eVC DLL which declaration
is as follows :

__declspec( dllexport ) int P1( const TCHAR* pzPos, double* pdLat, double*
pdLon );

__declspec( dllexport ) int P2( int nType, double dLat, double dLon,
TCHAR*
pzPos );

__declspec( dllexport ) double P3( double dDeg );

Thx a lot .

Krispi



I can't use double as an input parameter like this in your
example :
static extern void M1( double dDeg, out double retVal );


If i leave dDeg to be declared as it is showen above , i still get
NotSupportedException.
Should all doubles be declared as pointers ?

Thx.


8-bit types are not marshalled by CF. If you need to return double,
rewrite
your unmanaged code to accept double* as a parameter and on the managed
side
declare it as [out]double

[DllImport("krispi.dll")]
static extern void M1( double dDeg, out double retVal );


__declspec(__dllexport) void M1( double dDeg, double* retVal )
{
*retVal = (dDeg -32) * 5 / 9;
}

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hi,

If I try to import a method that has 'double' as a return values
or
as
a parameter then when trying to call that method I get
UnSupportedException.
NO matter if the DLL I specified exists or not. So as seen from
the
example
below,
if this "krispi.dll" exists or not i always get this exception. I
also
get
this exception is DLL file exists.
If changing double to int and DLL exists then MissingMethodException
is
throwen which is correct.
Do I have to use UnsuportedTyle.R8 insted of double ??? Just
guessing.

Here an example:

[DllImport("krispi.dll")]
static extern double M1( double dDeg );
public unsafe int MyMethod (

try{
double d=0;

d = M1(0);

}catch(Exception exc){

exc -> UnSupportedException
}
 
Back
Top