Results 1 to 8 of 8

Thread: [RESOLVED with another method] WIA (Windows Image Acquisition) Video Preview Problem

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Resolved [RESOLVED with another method] WIA (Windows Image Acquisition) Video Preview Problem

    I recently posted a WIA sample project in the codebank in this forum here :http://www.vbforums.com/showthread.php?t=378126

    What I was trying to do is provide a video preview of the webcam video in a window, but I am having problems with trying to pass in the Window Handle. It should be as simple as Adding a reference to "WIAVideo 1.0 Type Library", and then putting in the following code:
    VB Code:
    1. Dim MyVidClass As New WIAVIDEOLib.WiaVideoClass
    2. 'selecteddevice is a device found in the original WIA project, see project link for details
    3. MyVidClass.CreateVideoByWiaDevID(SelectedDevice.DeviceID, [U]Me.Handle[/U], 1, 1)
    However, the CreateVideoByWiaDevID method requires a "WIAVIDEOLib._RemotableHandle" object, which is supposed to be the handle to the window you wish the preview to show in. Because of this, when trying to pass in a normal window handle (intptr), it cannot convert a System.IntPtr to a WIAVIDEOLib._RemotableHandle object. Does anyone know how to utilize this method? Or how I can get some kind of "RemotableHandle" object to create my video in??

    I have searched around, and came up with a post here:http://www.codeproject.com/dotnet/wi...tingdotnet.asp . In the video section of the post, he mentions how there is a bug for the methods passing a window handle, so how can I go around this? Anyone know of a fix? He said he included his fixed dll in the project that should remedy it, but it is only 3kb vs. 104kb for the regular one, plus I tried using it and still got an error when trying to pass in the window handle. I would have figured if there was some sort of bug like this than there would have been a fix or another updated version of the dll from the boys at Microsoft, but I am unable to find any. If anyone has any ideas, Im all ears

    MSDN Link for the CreateVideoByDevID Method: http://msdn.microsoft.com/library/de...bywiadevid.asp
    **Notice that in the msdn link, it simply refers to "hwndparent" for the handle, which is usually an intptr or an int32 representing the window handle, yet in intellisense when using it, it is wanting a "WIAVIDEOLib._RemotableHandle" object
    Last edited by gigemboy; Jan 6th, 2006 at 03:07 AM.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: WIA (Windows Image Acquisition) Video Preview Problem

    This avoids the need to rewrite the typelibrary
    WIAVIDEOLib.WiaVideoClass aoeu = new WIAVIDEOLib.WiaVideoClass();
    Code:
    unsafe
    {
    WIAVIDEOLib._RemotableHandle *handle = (WIAVIDEOLib._RemotableHandle*)picLastImage.Handle.ToPointer();
    
    aoeu.ImagesDirectory = "C:\\temp";
    aoeu.CreateVideoByWiaDevID(info.DeviceID, ref *handle, 1, 1);
    }
    This is the only thing I could find after searching on Google, but I don't know if VB.NET allows the "unsafe" functionality that's required to cast from one to the other. Perhaps stick this method in a C/C++ DLL and call it when you need to convert to a "WIAVIDEOLib._RemotableHandle".
    "Make it idiot-proof and someone will make a better idiot"

  3. #3
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: WIA (Windows Image Acquisition) Video Preview Problem

    Okay, I've been messing around with this and I do seem to have it working. At least as far as being able to convert from an IntPtr to _RemotableHandle - I obviously can't test it on a real project:
    VB Code:
    1. Public Function getRemotableHandle(windowHandle As IntPtr) As WIAVIDEOLib._RemotableHandle
    2.    'Allocate unmanaged memory to store this IntPtr
    3.    Dim address As IntPtr = Marshal.AllocHGlobal(IntPtr.Size)
    4.  
    5.    'Write the IntPtr into unmanaged memory
    6.    Marshal.WriteIntPtr(address, windowHandle)
    7.  
    8.    'Return the RemotableHandle by marshalling it from unmanaged memory
    9.    Return Marshal.PtrToStructure(address, GetType(WIAVIDEOLib._RemotableHandle))
    10. End Function
    This essentially stores the IntPtr into unmanaged memory and then marshalls it again into a new structure, in this case a _RemotableHandle. Can be used as follows:
    VB Code:
    1. Dim remotableHandle As WIAVIDEOLib._RemotableHandle = getRemotableHandle(Me.Handle)
    Hope it works.
    "Make it idiot-proof and someone will make a better idiot"

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WIA (Windows Image Acquisition) Video Preview Problem

    I tried it, Parallax, and it still gives me an invalid pointer error. I had to turn option strict off in order for it to compile, when it was on, it gave an "Option Strict On Disallows Implicit Conversions from System.Object to WIAVIDEOLib._Remotablehandle" error in the code window on the return line of the function. It doesn't seem to like the gettype command... Any Ideas?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WIA (Windows Image Acquisition) Video Preview Problem

    *bumping this to see if anyone feels like takin a stab at it*

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: WIA (Windows Image Acquisition) Video Preview Problem

    I've scrapped the efforts of trying to get the WIA video preview to work...

    I managed to essentially recreate this project using an entirely different method, using avicap32.dll instead of WIA .. WITH preview!!! hehehe. It's using API and its not as pretty as doing it through the WIA object model, but it works, and is not restricted to just WIA enabled devices.

    I got some help with avicap32.dll here:
    http://www.vb-helper.com/howto_net_video_capture.html

    It was a little buggy ... still had old VB6 declarations instead of .NET declarations, and had to modify some of the code, but got it to work after a little tinkering...
    Last edited by gigemboy; Jan 6th, 2006 at 03:08 AM.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    312

    Re: [RESOLVED with another method] WIA (Windows Image Acquisition) Video Preview Problem

    Hey can i get the code of this project with preview using this avicap32.dll plz??

    I saw ur other project that has no preview , but in my case a video preview is required before capturing the image.

  8. #8
    Addicted Member
    Join Date
    Dec 2008
    Posts
    144

    Re: [RESOLVED with another method] WIA (Windows Image Acquisition) Video Preview Prob

    This wirks great. Anyway to save the images as jpeg?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width