Callback function pointer on CF 2.0 from unmanaged C DLL -> NotSupportedExceptionGetFunctionPointerF

  • Thread starter Thread starter Marcel Ruff
  • Start date Start date
M

Marcel Ruff

Hi,

i'm not sure if this is a bug in the CF2, so here are the details:

I have
One Windows Mobile CE 5.1.195 (IPAQ hw6910)
One Windows CE 4.2 PDA with Arm XScale (Psion Teklogix)

On both i have installed compact framework .net 2.0 SP1
(cgacutil.exe shows 1.0.4292.2 and 2.0.6129)

I have compiled the C# exe and C dll code with VC++ 2005.
When i want to call a native unmanaged C dll with a callback
function pointer i get:

----------
NotSupportedException:
System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegateInternal
----------

During startup my System.Environment.Version.ToString()
reports CF 2.0.6129

Here is the code:
// C#
public delegate bool FPtr(int value);
public class LibWrap
{
[DllImport("test.dll")]
public static extern void TestCallBack(IntPtr cb, int value);
}
public static bool DoSomething( int value )
{
Console.WriteLine( "\n[C#]: Callback called: {0}", value );
return true;
}


And i call it like this:

// C#
FPtr cb = new FPtr(DoSomething);
IntPtr cbForDelegate = Marshal.GetFunctionPointerForDelegate(cb);
LibWrap.TestCallBack(cbForDelegate, 99); // throws exception!


The C test.dll header:
extern "C" {
typedef bool (CALLBACK *FPTR)( int i );
__declspec (dllexport) extern void TestCallBack( FPTR pf, int value );
}

The C test.dll source:
extern "C" void TestCallBack( FPTR pf, int value )
{
bool res;
printf( "\ndll: Received value: %i", value );
printf( "\ndll: Passing to callback..." );
res = (*pf)(value);

if( res )
printf( "dll: Callback returned true.\n" );
else
printf( "dll: Callback returned false.\n" );
}


I have tried to compile the dll with /TC or /TP (c++),
same result.

Can anybody shed some light on this?

Thanks
Marcel
 
Why does this sound so familiar? Let's finish the thread in the other group
before you start another one, OK?

Paul T.
 
Paul said:
Why does this sound so familiar? Let's finish the thread in the other group
before you start another one, OK?
Sorry, i just thought this group is more appropriate,
so i transfered the thread to here with more details.
(usually i avoid cross posting)

Marcel
Paul T.

Marcel Ruff said:
Hi,

i'm not sure if this is a bug in the CF2, so here are the details:

I have
One Windows Mobile CE 5.1.195 (IPAQ hw6910)
One Windows CE 4.2 PDA with Arm XScale (Psion Teklogix)

On both i have installed compact framework .net 2.0 SP1
(cgacutil.exe shows 1.0.4292.2 and 2.0.6129)

I have compiled the C# exe and C dll code with VC++ 2005.
When i want to call a native unmanaged C dll with a callback
function pointer i get:

----------
NotSupportedException:

System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegateInternal
----------

During startup my System.Environment.Version.ToString()
reports CF 2.0.6129

Here is the code:
// C#
public delegate bool FPtr(int value);
public class LibWrap
{
[DllImport("test.dll")]
public static extern void TestCallBack(IntPtr cb, int value);
}
public static bool DoSomething( int value )
{
Console.WriteLine( "\n[C#]: Callback called: {0}", value );
return true;
}


And i call it like this:

// C#
FPtr cb = new FPtr(DoSomething);
IntPtr cbForDelegate = Marshal.GetFunctionPointerForDelegate(cb);
LibWrap.TestCallBack(cbForDelegate, 99); // throws exception!


The C test.dll header:
extern "C" {
typedef bool (CALLBACK *FPTR)( int i );
__declspec (dllexport) extern void TestCallBack( FPTR pf, int value );
}

The C test.dll source:
extern "C" void TestCallBack( FPTR pf, int value )
{
bool res;
printf( "\ndll: Received value: %i", value );
printf( "\ndll: Passing to callback..." );
res = (*pf)(value);

if( res )
printf( "dll: Callback returned true.\n" );
else
printf( "dll: Callback returned false.\n" );
}


I have tried to compile the dll with /TC or /TP (c++),
same result.

Can anybody shed some light on this?

Thanks
Marcel
 
Back
Top