473,396 Members | 1,923 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,396 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 2859
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 ;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.