Ive integrated a cuda/c++ dll in a C# application.
Nothing much to it if you know how the DllImport works in C#.
You compile the C/C++ code as a dll (project->properties->general->Configuration type)
C++:
extern "C" __declspec(dllexport) int doCuda( unsigned int threshold, int width,  int height, unsigned char *pixels,  unsigned char* oldPixels,unsigned  char *moved)
{
... stuff
somewhere in here you call the kernel
...
}
In C#:
[DllImport("motionDetectCuda.dll")]
�  �  �   public unsafe static extern int doCuda(uint threshold, int width, int height, byte[] pixels, byte[] oldpixels, IntPtr moved);
doCuda(threshold, streamSize.Width, streamSize.Height, bytes, oldbytes, pData.AddrOfPinnedObject());
Obviously the function signatures will vary, i just didnt modify mine to post this snipped.
So calling functions is easy, but marshalling the data between the 2 is a real pain in the ass. So depending on what kind of data you want to move around C# and C++, youll have a lot of fun looking for how to do that. Plenty of answers on the web.
This might help somebody… to move a an unsigned char* between C++ and C#:
moved = new byte[numBlocksH * numblocksV];
GCHandle pData = GCHandle.Alloc(moved, GCHandleType.Pinned);
doCuda(threshold, streamSize.Width, streamSize.Height, bytes, oldbytes, pData.AddrOfPinnedObject());
I have not tested the speed of calling a dll from C#. It was “fast enough” for a baby project i spent two days on and had no intention of really working through.