API explanation request [modified]
-
hi there i am writing a program for video conference over internet i was looking for a sample for capturing a image from webcam i found that there is two way for doing this first is using WIA and second is using API i found a sample that use API (avicap32.dll) it work fine now i want to add another camera or webcam and the aouther is not accessible .i reviewed codes several times but i cant understand that. it is really complicated for me and as i cant understand the code i cant extend it for capturing image or video from any other devices synchronouslly here is the code and i would be really appriciated if you explan about the codes : the class for capturing and sending image:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WebCam_Capture
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")] // toolbox bitmap
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))] // make composite
public class WebCamCapture : System.Windows.Forms.UserControl
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;// property variables private int m\_TimeToCapture\_milliseconds = 100; private int m\_Width = 320; private int m\_Height = 240; private int mCapHwnd; private ulong m\_FrameNumber = 0; // global variables to make the video capture go faster private WebCam\_Capture.WebcamEventArgs x = new WebCam\_Capture.WebcamEventArgs(); private IDataObject tempObj; private System.Drawing.Image tempImg; private bool bStopped = true; // event delegate public delegate void WebCamEventHandler (object source, WebCam\_Capture.WebcamEventArgs e); // fired when a new image is captured public event WebCamEventHandler ImageCaptured; #region API Declarations \[DllImport("user32", EntryPoint="SendMessage")\] public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); \[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindowA")\] public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID); \[DllImport("user32", EntryPoint="OpenClipboard")\] public static extern int OpenClipboard(int
-
hi there i am writing a program for video conference over internet i was looking for a sample for capturing a image from webcam i found that there is two way for doing this first is using WIA and second is using API i found a sample that use API (avicap32.dll) it work fine now i want to add another camera or webcam and the aouther is not accessible .i reviewed codes several times but i cant understand that. it is really complicated for me and as i cant understand the code i cant extend it for capturing image or video from any other devices synchronouslly here is the code and i would be really appriciated if you explan about the codes : the class for capturing and sending image:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WebCam_Capture
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")] // toolbox bitmap
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))] // make composite
public class WebCamCapture : System.Windows.Forms.UserControl
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;// property variables private int m\_TimeToCapture\_milliseconds = 100; private int m\_Width = 320; private int m\_Height = 240; private int mCapHwnd; private ulong m\_FrameNumber = 0; // global variables to make the video capture go faster private WebCam\_Capture.WebcamEventArgs x = new WebCam\_Capture.WebcamEventArgs(); private IDataObject tempObj; private System.Drawing.Image tempImg; private bool bStopped = true; // event delegate public delegate void WebCamEventHandler (object source, WebCam\_Capture.WebcamEventArgs e); // fired when a new image is captured public event WebCamEventHandler ImageCaptured; #region API Declarations \[DllImport("user32", EntryPoint="SendMessage")\] public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); \[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindowA")\] public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID); \[DllImport("user32", EntryPoint="OpenClipboard")\] public static extern int OpenClipboard(int
Firstly you should put your code between <pre></pre> tags so it retains its formatting. The above code is very difficult to read, please edit the entry. Secondly if you do not understand the code then you really should not be trying to use it. The most important aspect of any application is that you understand the code you are using. This forum does not have the space (and contributors do not have the time) to provide tutorials in this fashion. If this code came from an internet article then you should spend time studying the article until you understand it.
-
Firstly you should put your code between <pre></pre> tags so it retains its formatting. The above code is very difficult to read, please edit the entry. Secondly if you do not understand the code then you really should not be trying to use it. The most important aspect of any application is that you understand the code you are using. This forum does not have the space (and contributors do not have the time) to provide tutorials in this fashion. If this code came from an internet article then you should spend time studying the article until you understand it.
Whats the betting he just puts <pre>...</pre>tags around the existing unformated code? :laugh:
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
-
Firstly you should put your code between <pre></pre> tags so it retains its formatting. The above code is very difficult to read, please edit the entry. Secondly if you do not understand the code then you really should not be trying to use it. The most important aspect of any application is that you understand the code you are using. This forum does not have the space (and contributors do not have the time) to provide tutorials in this fashion. If this code came from an internet article then you should spend time studying the article until you understand it.
Richard MacCutchan wrote:
Secondly if you do not understand the code then you really should not be trying to use it.
I don't think this is the right way to look at it. Just because you don't understand the code doesn't mean you shouldn't try to use it in order to gain said understanding.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
hi there i am writing a program for video conference over internet i was looking for a sample for capturing a image from webcam i found that there is two way for doing this first is using WIA and second is using API i found a sample that use API (avicap32.dll) it work fine now i want to add another camera or webcam and the aouther is not accessible .i reviewed codes several times but i cant understand that. it is really complicated for me and as i cant understand the code i cant extend it for capturing image or video from any other devices synchronouslly here is the code and i would be really appriciated if you explan about the codes : the class for capturing and sending image:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WebCam_Capture
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")] // toolbox bitmap
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))] // make composite
public class WebCamCapture : System.Windows.Forms.UserControl
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;// property variables private int m\_TimeToCapture\_milliseconds = 100; private int m\_Width = 320; private int m\_Height = 240; private int mCapHwnd; private ulong m\_FrameNumber = 0; // global variables to make the video capture go faster private WebCam\_Capture.WebcamEventArgs x = new WebCam\_Capture.WebcamEventArgs(); private IDataObject tempObj; private System.Drawing.Image tempImg; private bool bStopped = true; // event delegate public delegate void WebCamEventHandler (object source, WebCam\_Capture.WebcamEventArgs e); // fired when a new image is captured public event WebCamEventHandler ImageCaptured; #region API Declarations \[DllImport("user32", EntryPoint="SendMessage")\] public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); \[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindowA")\] public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID); \[DllImport("user32", EntryPoint="OpenClipboard")\] public static extern int OpenClipboard(int
First, you have to tell us where you got the code so we have a context in which to help yopu. Second, you need to properly format the code you posted into a properly tagged PRE block. Third, you need to use punctuation in your description so we can read it.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Richard MacCutchan wrote:
Secondly if you do not understand the code then you really should not be trying to use it.
I don't think this is the right way to look at it. Just because you don't understand the code doesn't mean you shouldn't try to use it in order to gain said understanding.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
First, you have to tell us where you got the code so we have a context in which to help yopu. Second, you need to properly format the code you posted into a properly tagged PRE block. Third, you need to use punctuation in your description so we can read it.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001at first excuse me because of confusing you i corrected the code and here is the site that i downloaded the file: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1339&lngWId=10[^]
-
Firstly you should put your code between <pre></pre> tags so it retains its formatting. The above code is very difficult to read, please edit the entry. Secondly if you do not understand the code then you really should not be trying to use it. The most important aspect of any application is that you understand the code you are using. This forum does not have the space (and contributors do not have the time) to provide tutorials in this fashion. If this code came from an internet article then you should spend time studying the article until you understand it.
at first excuse me because of confusing you i corrected the code and here is the site that i downloaded the file: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1339&lngWId=10\[^\]
-
hi there i am writing a program for video conference over internet i was looking for a sample for capturing a image from webcam i found that there is two way for doing this first is using WIA and second is using API i found a sample that use API (avicap32.dll) it work fine now i want to add another camera or webcam and the aouther is not accessible .i reviewed codes several times but i cant understand that. it is really complicated for me and as i cant understand the code i cant extend it for capturing image or video from any other devices synchronouslly here is the code and i would be really appriciated if you explan about the codes : the class for capturing and sending image:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WebCam_Capture
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")] // toolbox bitmap
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))] // make composite
public class WebCamCapture : System.Windows.Forms.UserControl
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;// property variables private int m\_TimeToCapture\_milliseconds = 100; private int m\_Width = 320; private int m\_Height = 240; private int mCapHwnd; private ulong m\_FrameNumber = 0; // global variables to make the video capture go faster private WebCam\_Capture.WebcamEventArgs x = new WebCam\_Capture.WebcamEventArgs(); private IDataObject tempObj; private System.Drawing.Image tempImg; private bool bStopped = true; // event delegate public delegate void WebCamEventHandler (object source, WebCam\_Capture.WebcamEventArgs e); // fired when a new image is captured public event WebCamEventHandler ImageCaptured; #region API Declarations \[DllImport("user32", EntryPoint="SendMessage")\] public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); \[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindowA")\] public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID); \[DllImport("user32", EntryPoint="OpenClipboard")\] public static extern int OpenClipboard(int
Thank you for putting the proper tags around your code. The first thing that jumps out is that you're using
int
types for your interop methods. You should be usingIntPtr
so that the code will run reliably on both 32-bit and 64-bit operating systems. Beyond that, I think you're going to have to find some additional code (or technique) that allows you to select a connected video capture device. I believe this will involve familiarity with the DirectX SDK, and more specifically buding what they call "graphs" to connect the various devices. You may be able to use WMI to detect devices connected to the system (especially if they're USB or Firewire devices, but I've never done this before, so yo're gonna have to do the research. Ain't programming fun?.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Thank you for putting the proper tags around your code. The first thing that jumps out is that you're using
int
types for your interop methods. You should be usingIntPtr
so that the code will run reliably on both 32-bit and 64-bit operating systems. Beyond that, I think you're going to have to find some additional code (or technique) that allows you to select a connected video capture device. I believe this will involve familiarity with the DirectX SDK, and more specifically buding what they call "graphs" to connect the various devices. You may be able to use WMI to detect devices connected to the system (especially if they're USB or Firewire devices, but I've never done this before, so yo're gonna have to do the research. Ain't programming fun?.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001thank u for your post where should i exactly change int to intptr and what is the difference thanks
-
Firstly you should put your code between <pre></pre> tags so it retains its formatting. The above code is very difficult to read, please edit the entry. Secondly if you do not understand the code then you really should not be trying to use it. The most important aspect of any application is that you understand the code you are using. This forum does not have the space (and contributors do not have the time) to provide tutorials in this fashion. If this code came from an internet article then you should spend time studying the article until you understand it.
Richard MacCutchan wrote:
if you do not understand the code then you really should not be trying to use it
That depends on what the code is! Most of us use code all the time that we don't understand - in the .net framework. And it truly would be a waste of time to study every implementation detail (most of which are undocumented!) of the primitive types before permitting oneself to use them. I do not know the exact representation of System.Decimal nor what bit-level manipulation it performs to carry out a multiplication, but it would be ridiculous to claim I shouldn't use decimals for that reason. Also, even code that was not written with the intent of becoming a library (though most code should be written that way imo!) can still be of good quality and of great utility. Trying to use it is sometimes the most effective way to learn about it, whether it's good or bad code, especially if one does not have access to documentation.
-
thank u for your post where should i exactly change int to intptr and what is the difference thanks
I believe it's the external methods that return int and that they should return IntPtr. These are windows api functions and though I didn't look at them individually they probably return windows handles. Such handles will be 32-bit on 32-bit systems but 64 bits on 64-bits systems. In other words they have nothing to do with your problem, but since int is just shorthand for Int32 you should use IntPtr instead, and your code would (or at least could) then work on 32-bit and 64-bit platforms. Also, if any of the parameters to these methods are handles they too should be IntPtr, but you'll likely find out simply by changing the return type of the extern methods and building, since any handles passed to one of these will come from one of these...
-
Richard MacCutchan wrote:
if you do not understand the code then you really should not be trying to use it
That depends on what the code is! Most of us use code all the time that we don't understand - in the .net framework. And it truly would be a waste of time to study every implementation detail (most of which are undocumented!) of the primitive types before permitting oneself to use them. I do not know the exact representation of System.Decimal nor what bit-level manipulation it performs to carry out a multiplication, but it would be ridiculous to claim I shouldn't use decimals for that reason. Also, even code that was not written with the intent of becoming a library (though most code should be written that way imo!) can still be of good quality and of great utility. Trying to use it is sometimes the most effective way to learn about it, whether it's good or bad code, especially if one does not have access to documentation.
This reply was aimed at the OP, who has downloaded some code from the internet that they admit to not understanding, and then wants a major change made to implement a feature that they probably understand less. It was not aimed at people who provide the answers on these forums. And I know that we all use unfamiliar code to learn new things, but we also spend a lot of time answering questions like this from people who have not taken the time to learn some of the basics.
-
This reply was aimed at the OP, who has downloaded some code from the internet that they admit to not understanding, and then wants a major change made to implement a feature that they probably understand less. It was not aimed at people who provide the answers on these forums. And I know that we all use unfamiliar code to learn new things, but we also spend a lot of time answering questions like this from people who have not taken the time to learn some of the basics.
OK. I think we've both made some valid points. It's not necessary to interpret any additional perspectives as implying "you're wrong" and it's not really a competition. :)
-
This reply was aimed at the OP, who has downloaded some code from the internet that they admit to not understanding, and then wants a major change made to implement a feature that they probably understand less. It was not aimed at people who provide the answers on these forums. And I know that we all use unfamiliar code to learn new things, but we also spend a lot of time answering questions like this from people who have not taken the time to learn some of the basics.
And by the way,
Richard MacCutchan wrote:
but we also spend a lot of time answering questions like this from people who have not taken the time to learn some of the basics.
If we do, we do so only by choice. (Reading them is at least partly another matter.)
-
OK. I think we've both made some valid points. It's not necessary to interpret any additional perspectives as implying "you're wrong" and it's not really a competition. :)
dojohansen wrote:
It's not necessary to interpret any additional perspectives as implying "you're wrong"
I was not for a moment implying this, so I hope you did not read it that way. I do accept the points you made, I was merely trying to clarify my earlier message which may not have been as clear as I thought it was.