I created a DLL in Visual Embedded C++ 3.0, to use with .NET. It works with
callback functions.
But, on the running occurs the exception 'NotSupported'. The CF don't
support callback functions ?
What can I do ?

Thanx for all. Sorry about my english, isn't very good.
Luciano.


MyDLL.CPP
=========
#include "stdafx.h"
#include "MyDLL.h"

typedef int (__stdcall * FunctionCallback)( int i );

extern "C" __declspec(dllexport) int __stdcall FunctionDLL( FunctionCallback
pFunc ) {
return pFunc( 123 );
}



TestDLL.CS
==========
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Reflection;
using System.IO;
using System.Text;

namespace TestDLL
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MainMenu mainMenu1;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code

private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button1.Location = new System.Drawing.Point(8, 8);
this.button1.Text = "button1";
this.button1.Click += new
System.EventHandler(this.button1_Click);
this.label1.Location = new System.Drawing.Point(16, 64);
this.label1.Size = new System.Drawing.Size(216, 80);
this.label1.Text = "label1";
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion

// typedef int (__stdcall * FunctionCallback)( int i );
public delegate int FunctionCallback( int i );

[DllImport("DLL.DLL")]
public static extern int FunctionDLL( FunctionCallback pFunc );

public static void Main()
{
Application.Run(new Form1());
}

public delegate int DelegateFunction( int iVal );

public int MyFunction( int iVal ) {
return iVal + 456;
}

private void button1_Click(object sender, System.EventArgs e)
{
int iRet;
FunctionCallback pFunc = new FunctionCallback( MyFunction );
try
{
iRet = FunctionDLL( pFunc ); // <<<<<<<<<
ExceptionNotSupported
}
catch( NotSupportedException E )
{
label1.Text = E.Message;
return;
}
}
}
}

Re: Callback functions by Kevin

Kevin
Mon Feb 09 09:13:38 CST 2004

Alex Feinman (http://www.alexfeinman.com/Callbacks/Callbacks.htm)
has an implementation of of callback functions, using the MessageWindow
class.

Alternatively, you could write your own C++ implementation using messages
and wrap the callback.

Other than that, we appear to be out of luck!

- K.


"Luciano" <luciano@microton.com.br> wrote in message
news:e%23Ake2x7DHA.2736@TK2MSFTNGP10.phx.gbl...
> I created a DLL in Visual Embedded C++ 3.0, to use with .NET. It works
with
> callback functions.
> But, on the running occurs the exception 'NotSupported'. The CF don't
> support callback functions ?
> What can I do ?
>
> Thanx for all. Sorry about my english, isn't very good.
> Luciano.
>
>
> MyDLL.CPP
> =========
> #include "stdafx.h"
> #include "MyDLL.h"
>
> typedef int (__stdcall * FunctionCallback)( int i );
>
> extern "C" __declspec(dllexport) int __stdcall FunctionDLL(
FunctionCallback
> pFunc ) {
> return pFunc( 123 );
> }
>
>
>
> TestDLL.CS
> ==========
> using System;
> using System.Drawing;
> using System.Collections;
> using System.Windows.Forms;
> using System.Data;
> using System.Runtime.InteropServices;
> using System.Reflection;
> using System.IO;
> using System.Text;
>
> namespace TestDLL
> {
> public class Form1 : System.Windows.Forms.Form
> {
> private System.Windows.Forms.Button button1;
> private System.Windows.Forms.Label label1;
> private System.Windows.Forms.MainMenu mainMenu1;
>
> public Form1()
> {
> InitializeComponent();
> }
>
> protected override void Dispose( bool disposing )
> {
> base.Dispose( disposing );
> }
> #region Windows Form Designer generated code
>
> private void InitializeComponent()
> {
> this.mainMenu1 = new System.Windows.Forms.MainMenu();
> this.button1 = new System.Windows.Forms.Button();
> this.label1 = new System.Windows.Forms.Label();
> this.button1.Location = new System.Drawing.Point(8, 8);
> this.button1.Text = "button1";
> this.button1.Click += new
> System.EventHandler(this.button1_Click);
> this.label1.Location = new System.Drawing.Point(16, 64);
> this.label1.Size = new System.Drawing.Size(216, 80);
> this.label1.Text = "label1";
> this.Controls.Add(this.label1);
> this.Controls.Add(this.button1);
> this.Menu = this.mainMenu1;
> this.Text = "Form1";
> }
> #endregion
>
> // typedef int (__stdcall * FunctionCallback)( int i );
> public delegate int FunctionCallback( int i );
>
> [DllImport("DLL.DLL")]
> public static extern int FunctionDLL( FunctionCallback pFunc );
>
> public static void Main()
> {
> Application.Run(new Form1());
> }
>
> public delegate int DelegateFunction( int iVal );
>
> public int MyFunction( int iVal ) {
> return iVal + 456;
> }
>
> private void button1_Click(object sender, System.EventArgs e)
> {
> int iRet;
> FunctionCallback pFunc = new FunctionCallback( MyFunction );
> try
> {
> iRet = FunctionDLL( pFunc ); // <<<<<<<<<
> ExceptionNotSupported
> }
> catch( NotSupportedException E )
> {
> label1.Text = E.Message;
> return;
> }
> }
> }
> }
>
>