Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. API explanation request [modified]

API explanation request [modified]

Scheduled Pinned Locked Moved C#
graphicsdesignjson
16 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR realJSOP

    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

    M Offline
    M Offline
    mehrdad333
    wrote on last edited by
    #7

    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[^]

    1 Reply Last reply
    0
    • L Lost User

      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.

      M Offline
      M Offline
      mehrdad333
      wrote on last edited by
      #8

      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\[^\]

      1 Reply Last reply
      0
      • M mehrdad333

        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
        
        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #9

        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 using IntPtr 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

        M 1 Reply Last reply
        0
        • realJSOPR realJSOP

          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 using IntPtr 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

          M Offline
          M Offline
          mehrdad333
          wrote on last edited by
          #10

          thank u for your post where should i exactly change int to intptr and what is the difference thanks

          D 1 Reply Last reply
          0
          • L Lost User

            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.

            D Offline
            D Offline
            dojohansen
            wrote on last edited by
            #11

            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.

            L 1 Reply Last reply
            0
            • M mehrdad333

              thank u for your post where should i exactly change int to intptr and what is the difference thanks

              D Offline
              D Offline
              dojohansen
              wrote on last edited by
              #12

              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...

              1 Reply Last reply
              0
              • D dojohansen

                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.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #13

                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.

                D 2 Replies Last reply
                0
                • L Lost User

                  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.

                  D Offline
                  D Offline
                  dojohansen
                  wrote on last edited by
                  #14

                  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. :)

                  L 1 Reply Last reply
                  0
                  • L Lost User

                    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.

                    D Offline
                    D Offline
                    dojohansen
                    wrote on last edited by
                    #15

                    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.)

                    1 Reply Last reply
                    0
                    • D dojohansen

                      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. :)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #16

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups