I am currently using delegate from c# to C++ dll i am passing the ref struct to get the value of struct from c++ dll,with out using call back i can able to get the struct value using marshalling.but for dynamic purpose i am using Delegate callback.
while i am working i dont know in callback what i need to use i am facing the issue
if i use without ref in update() method
Quote:
Error CS1676 Parameter 1 must be declared with the 'ref' keyword
if i am not using ref in update() method
Quote:
Error CS0246 The type or namespace name 'strNode' could not be found
What I have tried:
In C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NODE
{
public ulong ullSector;
public ulong ullSize;
unsafe public NODE* pNext;
unsafe public NODE* pChild;
unsafe public NODE* pParent;
public uint dwID;
public uint dwSelfNum;
public uint dwParentNum;
public IntPtr pwcName;
}
above one is my struct
public delegate void ProgressCallback(ref NODE strNode);
public delegate string GetFilePathCallback(string filter);
public async void update()
{
ProgressCallback callback =
( ref strNode) =>
{
Application.Current.Dispatcher.Invoke((Action)delegate
{
Console.WriteLine("Progress = {0}", strNode.Name.ToString());
});
};
DoWork(callback);
}
in my c++ dll
XXXX.h
#ifdef __cplusplus
extern "C"
{
#endif
#define DLL __declspec(dllexport)
typedef void(__stdcall* ProgressCallback)(NODE*);
typedef char* (__stdcall* GetFilePathCallback)(char* filter);
DLL void DoWork(ProgressCallback progressCallback);
DLL void ProcessFile(GetFilePathCallback getPath);
#ifdef __cplusplus
}
#endif
XXXX.cpp
DLL void DoWork(ProgressCallback progressCallback)
{
if (progressCallback)
{
Sleep(100);
}
}
}