Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,
I'm trying build an app which need to stream USB cameras, for that, I'm utilizing a source code from codeProject:Versatile WebCam C# library[^]

where GUI is developed in C# but the to handle USB camera it uses Directshow which is written C++, which are acessed as dll's, this source code uses DirectShow Sample Grabber and draws frames on PictureBox, but now I want change this method, what I'm planning to do is, pass window handle(hwnd) of C# to dll and stream video to C# window, I tried passing HWND from C# to cpp dll and try to stream video using directshow but no use, no streaming video is shown on winforms C# window, webcams light is turning on(so graph is running fine), and no errors throughout the code while building the Graph.

What I have tried:

Handle passed through setParent method from C# to cpp
C#
_frameSource.setParent(this.Handle);




Inside WebCamlib.cpp file I'm assigning ghwndApp local attribute with hwnd which we received from C#.
C++
void CameraMethods::setParent(Int32 hwnd) {

	ghwndApp =(HWND) hwnd;

}



In the DirectShow, I just added these lines to display the video
C++
gcap.pVW->put_Owner((OAHWND)ghwndApp);
gcap.pVW->put_WindowStyle(WS_CHILD);
gcap.pVW->put_Visible(OATRUE);



but Nothing is showing on my Screen, but I'm sure that the DirectShow graph is running well because my webcam light is glowing.
Posted
Updated 18-Nov-22 0:35am
v2

First and foremost you need to be aware on what architecture you are: 32 bit or 64 bit. Your function with

void CameraMethods::setParent(Int32 hwnd) {

	ghwndApp =(HWND) hwnd;

}


Isn't going to work in 64 bit. Int32 in a signed 32 bit integer whereas windows handle is a platform dependent width pointer. You probably want to replace it with IntPtr. I am not a big c# guru but even in C++ this approach would fail
 
Share this answer
 
Comments
KarstenK 18-Nov-22 9:04am    
absolut correct.
There are always a lot of reason why it may not work. At first check ALL return code of used function, because you may miss some access rights.
Another plain reason and my best guess is always that your code is drawing at some invisible coordinates. So try to make the drawing windows full screen when at the main monitor to see something.
Consider creating an extra output child window. Dig in the drawing code to control the output coordinates.

bonus tip: write some output in some function to see that
C#
pictureBoxDisplay.Paint += new PaintEventHandler(drawLatestImage);
is really called and you not only are guessing with a lamp.
 
Share this answer
 

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