Somewhat new to C#...
-
but a long time C/C++ programmer. I've ran in to a bit of a spot that I just can't seem to get a grasp on. I have a callback in a C++ unmanaged DLL that I've written: LRESULT CALLBACK eventListener(HWND hWnd, UINT msg, WPARAM wP, LPARAM lP) { switch(msg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hDc = BeginPaint(GetFocus(), &ps); if(g_currVideo != NULL) { const VideoFrame& currFrame = g_frames[g_currentFrame].frame; BITMAPINFO bi; ZeroMemory(&bi, sizeof(bi)); bi.bmiHeader.biSize = sizeof(bi); bi.bmiHeader.biWidth = currFrame.getWidth(); bi.bmiHeader.biHeight = currFrame.getHeight(); bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; SetDIBitsToDevice(hDc, 0, 0, currFrame.getWidth(), currFrame.getHeight(), 0, 0, 0, currFrame.getHeight(), currFrame.getData(), &bi, DIB_RGB_COLORS); } EndPaint(GetFocus(), &ps); return 0; }break; ... } In C++, I would have no problem calling this, however, I am lost when it comes to doing it in C#. The DLL in question relies on the callback to load and play back frames and samples of an uncommon video format. In C#, I'm able to get it as far as loading that first frame and audio sample, however, without the callback, that's as far as I can go. My question is how would I implement use of this callback this in C#?
-
but a long time C/C++ programmer. I've ran in to a bit of a spot that I just can't seem to get a grasp on. I have a callback in a C++ unmanaged DLL that I've written: LRESULT CALLBACK eventListener(HWND hWnd, UINT msg, WPARAM wP, LPARAM lP) { switch(msg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hDc = BeginPaint(GetFocus(), &ps); if(g_currVideo != NULL) { const VideoFrame& currFrame = g_frames[g_currentFrame].frame; BITMAPINFO bi; ZeroMemory(&bi, sizeof(bi)); bi.bmiHeader.biSize = sizeof(bi); bi.bmiHeader.biWidth = currFrame.getWidth(); bi.bmiHeader.biHeight = currFrame.getHeight(); bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; SetDIBitsToDevice(hDc, 0, 0, currFrame.getWidth(), currFrame.getHeight(), 0, 0, 0, currFrame.getHeight(), currFrame.getData(), &bi, DIB_RGB_COLORS); } EndPaint(GetFocus(), &ps); return 0; }break; ... } In C++, I would have no problem calling this, however, I am lost when it comes to doing it in C#. The DLL in question relies on the callback to load and play back frames and samples of an uncommon video format. In C#, I'm able to get it as far as loading that first frame and audio sample, however, without the callback, that's as far as I can go. My question is how would I implement use of this callback this in C#?
In C#, a callback is called a delegate. If you google delegates in C#, you'll find heaps of info on how they work.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog