Click to See Complete Forum and Search --> : Get Function Address


ricky_cpp
January 21st, 2009, 08:18 AM
Hello All,

I have imported a .dll into my C# project. One of the function in dll is:

extern "C" __declspec(dllexport) void SetCallbackProcAddr(long lProcAddress)
{
g_CallbackProc = (decodePacket)lProcAddress;
}

which takes address of function from client project.

In my client project, I am having :

namespace Client
{

Class useDLL
{
[DllImport("exampleDLL.dll", EntryPoint = "SetCallbackProcAddr", ExactSpelling = false, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern unsafe void SetCallbackProcAddr(long* apPointer);

//And I would like to pass below's function address to above function

public void CallBack(IntPtr apData, int aDataSize)
{

}

//Function test is called from main
public void test()
{
Client.SetCallbackProcAddr(????????); //What should replace ?????????
}
//Has someone any idea how should I pass on address of CallBack function )

}
}

I am new to C# and want first to import my projects in form of dll. example.dll is one of the projects which is using c++ and c files.

Can someone be of help?

Thanks and regards,
Ricky

MadHatter
January 22nd, 2009, 05:52 PM
try using a delegate.

toraj58
January 22nd, 2009, 05:59 PM
yes delegate is like c++ function pointer

ricky_cpp
January 27th, 2009, 02:44 AM
Thanks Toraj and MadHatter. It is working now.

Am using delegate now and to get memory address I had to use

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void callbackDelegate(in param)


regards,
Ricky

cjard
January 27th, 2009, 03:16 AM
Ricky, please use CODE tags (http://www.codeguru.com/forum/misc.php?do=bbcode)in future, when you post code