Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I converted vb6 code to C# and getting this error.

C#
public void test()
{
	//code...
}
public void CallTest(int i)
{
	//after some operation 
	return i;
}

form_Load()
{
	CallTest(AddressOf test); // Getting error.
}


Giving error 'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type.

I want get the address (memory pointer) of to the function "DirPickupSearchProcessReply" in vb.net or C# Please suggest how can i get?
Posted
Updated 9-May-12 19:21pm
v3

1 solution

You need to define a delegate type with the same signature of the method. (in this case a very simple one)
public delegate void TestDelegate();


You need to use this type as parameter type:
public void CallTest(TestDelegate i) {
  i();
}

... calling it with the test method as delegate
CallTest(new TestDelegate(test));

This is because it is unsafe to assume a method address is simply an integer and would make static type checking (to see if the method fits the expectations) nearly impossible. What would happen if you would pass i + 1?

http://msdn.microsoft.com/en-us/library/aa288459%28v=vs.71%29.aspx[^]

Good luck!
 
Share this answer
 
v2
Comments
to.areeb 9-May-12 7:00am    
Nijboer Thanks for your reply I did as you suugested but I got error in line
CallTest(new TestDelegate(test)); for address of or lamda expression Added addressof then I am getting error value type cannot convert to integer. Could you please suggest any solution for this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900