473,372 Members | 1,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Error 2664 "cannot convert parameter 1" - callback to managed from unmanaged

Hello.

I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code will call. I'm getting Error 2664: cannot convert parameter 1 from CallBack __gc * to CUSTOM_HOOK_CALLBACK_FUNCTION. Here's what I have...

In my unmanaged DLL -- Header file:
---------------------------------------------------
typedef VOID (__stdcall * CUSTOM_HOOK_CALLBACK_FUNCTION )();

extern "C" void __stdcall CUSTOM_HOOK(CUSTOM_HOOK_CALLBACK_FUNCTION callbackFunction);

In my unmanaged DLL -- Source file:
---------------------------------------------------
CUSTOM_HOOK_CALLBACK_FUNCTION pCustomHookCallbackFunction = NULL;

extern "C" void __stdcall CUSTOM_HOOK(CUSTOM_HOOK_CALLBACK_FUNCTION callbackFunction)
{

// . . . eventually

pCustomHookCallbackFunction = callbackFunction;
(pCustomHookCallbackFunction)();
}


In my managed C++ code -- the header file:
---------------------------------------------------------
namespace Wrappers
{
public __gc class MyWrapper
{
public:
void TestTheCallback();
static void DoCallback ( );
}
}

In my managed C++ code -- the source file:
---------------------------------------------------------
// System namespace.
using namespace System::Runtime::InteropServices;

// A delegate type.
__delegate void CallBack();

[DllImport("nr")]
extern "C" void __stdcall CUSTOM_HOOK(CUSTOM_HOOK_CALLBACK_FUNCTION callbackFunction);

namespace Wrappers
{

// ...

void MyWrapper::DoCallback ( )
{
// do something
}

void WrapperNonRealTimeAPI::TestTheCallback()
{
CallBack* myCallBack =
new CallBack(this, &MyWrapper::DoCallback);
CUSTOM_HOOK ( myCallBack );
}
} // namespace


----

I get the error on the last line: CUSTOM_HOOK ( myCallBack ); I think I understand why the error, but I don't know how to fix it. I've tried to do everything that I've read on the internet on this subject, but it's not working. Help...

(Note: since my hook function and the callback don't pass any parameters, I know the whole thing is pretty useless as a "custom" hook -- but I'm just trying to get this working right now).

-stillh2os
Sep 27 '06 #1
1 2856
Hi again... I found one other source (David Notario's blog: http://blogs.msdn.com/davidnotario/a...3/512436.aspx), which clued me in to the fact that you could put the delegate right in the declaration in the managed source, like so:

extern "C" void __stdcall CUSTOM_HOOK(CallBack* callbackFunction);

But now I get a linker error:

error C2733: second C linkage of overloaded function 'CUSTOM_HOOK' not allowed

Help...

-stillh2os
Sep 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
1
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to update the database, it gave me the error "cannot...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public ICustomTypeDescriptor { private: ...
0
by: Chun | last post by:
Dear All I am now facing a problem when i try to pass a custom datatable datatype value to a remote server. In the remote server, a method with System.Data.DataTable as input parameter is...
5
by: Dominiek | last post by:
Hi, I have a strange problem. during the developement of my program, while progressively writing more and more code, the callstack of my program gets deeper and deeper (7 levels). Then, all...
2
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific table in my database. Here is the tables...
0
by: mvdkwong | last post by:
I am trying to run a macro that will export a table into a fixed length file (see below). However, when I run it, I get the following error: "Cannot update. Database or object is read-only." I've...
2
by: qazmlp1209 | last post by:
class base { public: base() { } base(int number) { priNumber = number ;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.