function pointer - ambiguous symbol error

MyClass is a singleton class (There will only ever be one of these in my whole program).

What I want to do is follows.

1. Add data to my class using AddData, get a function pointer returned that I can then pass to 'another' function in a dll.
2. Then this 'other' function calls my call back function

My class is like so.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
typedef void (*DataReceivedCallback)(int, int);  

class MyClass
{
	MyClass();
	~MyClass();

	void AddData(int sourceId, DataReceivedCallback &callback);
	static void MyCallBackFunction(int var1, int var2);
};

void MyClass::AddData(int sourceId, DataReceivedCallback &callback)
{
	callback = &MyCallBackFunction;

}
void MyClass::MyCallBackFunction(int var1, int var2 )
{
	//do something blah blah
}


I can then do:

1
2
3
4
5
6
int main()
{
     DataReceivedCallback callback;
     MyClass->GetInstance()->AddData(1, callback);
     callback(1,100);
}


When I step through this I see that I do actually step into the callback MyCallBackFunction which is what I want :)

What I then want to do now is pass this 'callback' defined in main to a dll function that will call back into my callback function.

I have the code for the dll so I want to modify one if its functions so that it accepts my callback function parameter.

I am doing this in the dll function signature:

1
2
3
4
void * someDllFunction( int var1, int var2, DataReceivedCallback& callback)
{
   callback(2, 200);
}


But I get the error:
error C2872: 'DataReceivedCallback' : ambiguous symbol

How can I solve this?
Does this have to do with only being allowed to use c-style parameters across dll boundaries??
Last edited on
Just a guess here, but DataReceivedCallback is a (function)pointer, having a reference of a pointer makes no sense, try removing the & in the someDllFunction
Last edited on
closed account (1vRz3TCk)
error C2872: 'DataReceivedCallback' : ambiguous symbol

That would mean that you have two (or more) declarations of DataReceivedCallback and the compiler does not know which to use.

Also, is the code posted above actual code or a quick mockup? Because unless MyCallBackFunction() is static you should have a pointer to member function
typedef void (MyClass::*DataReceivedCallback)(int, int);

See: http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.1
Last edited on
sorry its a quick mockup, yes the callback function is static. NOW UPDATED

re: That would mean that you have two (or more) declarations of DataReceivedCallback and the compiler does not know which to use.
Yes youare right, I have defined
typedef void (*DataReceivedCallback)(int, int);
in my original class and also in my dll project as the dll is complaining that DataReceivedCallback is undefined.

How can I get around this??
Last edited on
re: Just a guess here, but DataReceivedCallback is a (function)pointer, having a reference of a pointer makes no sense, try removing the & in the someDllFunction

This made no difference.

Any other ideas??
in my original class and also in my dll project as the dll is complaining that DataReceivedCallback is undefined.

How can I get around this??


You can either change the name of one, make one of the typedefs private or include the original class.
Last edited on
hey man you can define pointer function to __thiscall function such as __stdcall or __cdecl !!!

if you want do this you must change your code such as :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class x {
public:
	x()
	{
		ptr = &x::show;
	}

	void show()
	{
	}

	void (x::*ptr)();

};
Topic archived. No new replies allowed.