Touchless Vision C# webcam wrapper, can't run without VS installed - c#

So I've been hunting around for a good way to utilize a webcam from within a C# application. I tried a p/invoke dll which turned out to be inexplicably and irreproduceably buggy. After tinkering with a few others that either weren't suitable or were utterly archaic, I was referred to this:
http://jakemdrew.wordpress.com/2012/01/10/controlling-your-web-camera-using-c/#comment-15
It's the Touchless Vision code with a C# wrapper updated to work in VS 2010. It works wonderfully...as long as VS is installed on the machine. Download and run that release build on anything that doesn't and it will throw an error claiming that it can't find WebCamLib.dll or one of its dependencies. The fun part is that I've already integrated this into the project. It works great, but I'd like to be able to distribute this without additional installers or requiring VS 2010 to be installed on everything. What gives here?

I am using Aforge.net libraries(Aforge.net) without any problems on multiple computers even without VS installed.
But are you sure WebCamLib.dll is copied in the app directory? Aforge.Net also needs some dlls copied to computers, but if you have set Copy Local property to true, it should be inside the Debug/Release directory, also it will be in the directory when you release your app using Publish.
Sample:
Add Aforge.Controls.dll to your toolbox items
In designer put VideoSourcePlayer control in your form
Add private FilterInfoCollection videoDevices; in form class
Add into form initializer (or in function that you want to start your camera)
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo fi in videoDevices)
{
this.videoSourcePlayer1.VideoSource = new VideoCaptureDevice(MonikerString);
this.videoSourcePlayer1.Start();
break;
}
Now you should be getting image from webcam in VideoSourcePlayer control. You can use NewFrame event of VideoSourcePlayer control to get access to each frame camera is sending and to save or change image.

well some time has passed since the question but, just for the sake of solving it I´ll say this:
Supposing that you have the references to the dlls and the files where they should be the only thing left to do is check the dll dependencies, in this case
the programmer of the touchless and webcamlib dlls didn´t care much for "versioning" so, find the c++ vs2012 redistribution for x64 and x86 and install them, then run your App and carry on with your Project.

Related

Replacing a DLL on a Windows shared folder that is used by a C# .NET application

We have an enterprise management software that our clients deploy to a Windows network shared folder that several users from several terminal servers launch our program from.
What we're trying to achieve is a way to replace a DLL while the program is being used by the users to apply patches to fix bugs. At the moment weirdly enough, we are able to rename the old DLL to replace and apply the new one without any errors regarding the file being used.
This causes us two problems though:
the new DLL isn't loaded by the application if an instance of the same application is still using the old DLL (I think this is a case of https://en.wikipedia.org/wiki/DLL_Hell#Shared_in-memory_modules)
Exceptions are thrown left and right by applications that were run before the replacing because they were only loaded partially (lazy loading) and the when its time to go look into the file for the parts that are missing that are being requested the IL code doesn't match what's in memory anymore.
The bottom line of this is I think that we're doing something we are not supposed to: renaming something that is being used.
The possible solutions I found so far are two:
launch the application with a new AppDomain with shadow copying enabled, but this is not reliable as every client has its own environment and we might get unexpected permission errors or something of this nature
load assemblies without locking them. On this note we've looked into using reflection (which we actually use to some extent) but we're unsure on how to load through reflection assemblies that are already referenced in the project by the DLL (we have multiple DLL referecing other DLL that are referencing other DLL, etc....).
Do any of you have any other idea on how to overcome this problem safely? Or how to solve the last point I mentioned above with the reflection?
You could try a poor man's version of blue/green deployment.
Deploy your application files into two identical folders
\\SomeMachine\d$\MyApp\Green
\\SomeMachine\d$\MyApp\Blue
Now put a shortcut in the root folder like this:
\\SomeMachine\d$\MyApp\MyApp.lnk
Start out with the shortcut pointing at the .exe in the Green folder.
Tell your users to always launch the application using the shortcut only (rather than navigating into the Green or Blue folders and launching it there).
When it's time to update a DLL, follow this process:
Make the modification in the Blue folder
Do whatever testing is required in the Blue folder.
Once you're sure it works, update the MyApp.lnk shortcut to point at Blue.
Users who started their application before your update will continue to hit the Green folder until they exit the application. Anyone who starts the application anew will hit the Blue folder.
The next time you have to update a DLL, reverse the process. Make the modification in the Green folder, then update the shortcut to point at Green.
This way, you are always updating a folder that nobody is using, then making it available via the shortcut. As long as people exit the application every now and then, you should be able to deploy seamlessly.
If you don't want to use a .lnk file (e.g. your clients aren't on Windows), there are other similar ways to do this by either mapping a drive letter or using a symbolic link. But the principle remains the same.

How to have a custom control pull over all required files when used from Toolbox

I have created a custom control for my development team to utilize the CefSharp Chromium Web Browser. I have everything setup and working well. The only problem is having it run for projects that do not directly reference the chrome project in their solution.
I would like to find a way for when a developer drag and drops my custom control into their application, it will automatically copy ALL of the required files from the compiled control to their bin folder.
Currently, it only pulls the handle full directly referenced by the tool, but some are utilized at run time due to limitation of the utility for being able to compile for Any CPU efficiently.
Image of Files
I would like to have all of the files on the left hand side be copied automatically upon using the control from the tool box to the appropriate folder, or at the very least at run time.
Any information or ideas on where to look are greatly appreciated.
I managed to solve the problem, though this feels like back practice.
My issue what using CefSharp and getting all of the x64 and x84 files downloaded where ever require. I ended up adding a zip file of each content and then extracting them at run time as needed.

MonoGame on linux failing to load effect assets

EDIT: The issue is now solved, I'm including the details here to help anyone else who runs into this, as it's not that simple to solve.
Basically, it comes down to updating using the develop branch.
The first step is to checkout the monogame develop branch, this will not include the thirdparty/libs submodule, so you need to also update this in order to be able to compile the sources.
After this, you can compile MonoGame.Framework.Linux.sln, and update the references in your project to point to the new dll files.
This will still not load effect files, unless they are created using an up-to-date version of the content processors, so you need to go to a windows computer, checkout the develop branch (and libs) - or copy them from your linux system - then compile MonoGame.ContentPipeline/ContentProcessors/MonoGameContentProcessors.sln
You need to update the reference to MonoGameContentProcessors.dll in your content project, you also need to rename the MonoGame.ContentPipeline\ContentProcessors\bin\Release\libmojoshader_32.dll file to simply libmojoshader.dll.
Once all of this is done, you can finally use it as intended - build the .xnb files from your .fx files and add them to the linux project.
Hopefully this information will be useful to someone.
=================================================
Original post:
I have just started out with MonoGame, and am trying to get a very simple application (rotating cube) to work on Windows and Linux - windows is not proving to be a problem, but I am having trouble getting my .fx files to work on Linux.
I have set up a "MonoGame Content Project", added the .fx file to it, selected the "MonoGame Effect" processor, set the build configuration to Linux - this all seems to work and i get a .xnb file in the output directory.
When I set up the Linux project, I copied the .xnb to the "Content" folder (the root directory is set accordingly) and used the following code to load the effect (same code as on windows):
CubeEffect = Content.Load<Effect>("Effect1");
CubeEffect.CurrentTechnique = CubeEffect.Techniques["Technique1"];
This then results in an application crash with this error:
Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Effect1 asset!
Initially i assumed this to be a problem with file names, directory names, or some incorrect setting. However, i tried adding a .png file to the content folder and loading that:
Texture2D Tex = Content.Load<Texture2D>("bg.png");
This works perfectly well (checked the properties of the Texture2D in the debugger, and it has correct details for the file).
Have i missed a step somewhere when converting the shader file? Is there some really obvious thing that I'm not seeing?
If not, does anyone have any clue why it would act like this, or some way to get a more detailed error from it, like an actual reason for it not being able to load the asset?
EDIT: Having looked at the point in the disassembly where it actually throws the error, it seems that it finds the file, but doesn't recognise it as any valid resource type - could this be some kind of version/compatibility issue?
This is a very common problem when trying to load shaders into Monogame.
I tried, and failed to be able to load my custom shader into the Monogame framework.
You need to compile from the develop3d branch, and not the official release. You also need to convert your HLSL shader into a MojoShader compatible syntax. Then you need to either load the effect from the Monogame Content importer (which needs to be configured manually), or add your shader as an embedded resource and load it into your project in order to use it.
I have never been able to actually pull this off myself. From my readings online, this particular part of the Monogame framework is not quite ready for primetime yet.
Here is some information on it. They really didn't provide much information on this as I suspect they know it is very problematic:
https://github.com/mono/MonoGame/wiki/Effects-And-Shaders

D3DERR_INVALIDCALL error, TeamCity builder

I've been trying to use TeamCity 4.5 in order to automate builds of an XNA project but I have a small problem. My projects compile correctly under Visual Studio 2008, but not when compiled with TeamCity as the builder. The configuration file uses the sln2008 setting, and compiling goes well for a while, but as soon as it goes compiling .png textures to .xnb, I get the following error:
[11:28:41]: [Project "Content.contentproj" (default targets):] Content\head.png Building content threw InvalidOperationException: D3DERR_INVALIDCALL
at Microsoft.Xna.Framework.Content.Pipeline.CommonHelperFunctions.InitD3D()
at Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.InitD3D()
at Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.Import(String filename, ContentImporterContext context)
at Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.ImportAssetDirectly(BuildItem item, String importerName)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.ImportAsset(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings)
Inner exception: COMException: Exception from HRESULT: 0x8876086C
I do not have any ideas what is causing this. Like I said, it's able to compile .fbx models correctly as well as my ContentPipeline project and my SharedContent project (part of the solution).
What I would actually like is some pointers to what would be the source of the problem (and if possible, a solution to the problem). As far as I understand, there seems to be a problem with the D3D library. I will also remind you that this whole solution compiles under Visual Studio 2008, thus there is a small problem with TeamCity, either I haven't provided something, or something is actually incorrectly set.
Almost certainly, Team City is running it's build process as Local System in a non-interactive mode, and not as a user that actually has the access and ability to grab the graphics device. I know I've had problems even attempting to batch process textures through a Remote Desktop interface because DirectX can't grab the graphics device.
The solution may be to see if Team City offers you the ability to request that it's builder run as a logged on user, not as Local System, or as a service, though I can't tell you that that's actually even possible in Team City.
I don't have a solution but I've been thinking about it.
The error is D3DERR_INVALIDCALL so I'm thinking the device isn't available at that time for some reason.
1) Do the machines running the build have DirectX installed/a graphics card? I'm assuming yes since XNA requires a card with shaders but TeamCity is a build distribution so maybe it's running on a machine without it?
2) Maybe TeamCity is causing too too many Direct3D devices to be created on the same machine/process (complete guess)?
Do the model files that compile correctly use textures or are they just geometry data? I have a feeling the content builder doesn't need access to DirectX to build models but does for texture data. Can you build anything else that requires access Direct3D? Can you build a project using TeamCity that just has one texture in it's content folder?
I'm not sure if this would work but can you get more information by running DirectX in Debug Mode and looking at the output?
Hope this helps somewhat.
XNA and DirectX 9 require a current logged in user in order to compile the Content folder.
The solution is simple, set up a build agent machine (real physical machine) with the pre-reqs for XNA (VS2008, XNA Game Studio 3.0, etc) and make it log in on startup, then create a script to run the team server agent when logged in (by placing a shortcut to the agent run script in the start up folder in the start menu).
This way the agent will run as the local user and can build as normal.
I have done this and can confirm that it works.
Sorry to drag up an old thread but I've just run into the exact same problem trying to get TC to build my XNA project on Windows Server and wanted to help others coming across the same problem.
I've just found this article and blog which looks like a very promising solution:
http://forums.create.msdn.com/forums/p/86699/532976.aspx
&
http://blogs.msdn.com/b/astebner/archive/2011/07/07/10184338.aspx
Aaron basically states that the new beta of Win Phone SDK 7.1 Beta 2 contains XNA Game Studio 4.0 Refresh Beta 2 which now allows you to build content via the content pipeline in the following types of configurations:
If your screen is locked during a build
If you are running a build on a headless computer
If you are running a build from a non-interactive user account
But it looks like it'll only run on Vista or above - hopefully that should include servers too. Update: Nope sadly it wont install on my Windows Server :(

Best solution for making an Autorun application?

For my work I need to create a Autorun application for a CD for our client. The problem is all I'm a C# programmer by trade and .NET does not make for the best autoruns since not all computers will have .NET installed on them.
What is a good solution that will work on Win98-Vista computers?
The answer to this question is really one of preference. Technically, anything can be instructed to open as an autorun. The autorun.inf file is simply an instruction file that Windows knows how to read in order to determine what it should do when a CD is inserted. That could be an application (written in any language you choose), a powerpoint presentation, opening a link to a website, etc. As long as you follow the rules of the autorun.inf file:
http://autorun.moonvalley.com/autoruninf.htm
There are many small autorun-utils (some free) that are configurable. I would go for one of those.
http://www.ezau.com/latest/articles/083.shtml
You need two things:
Follow this steps (http://support.microsoft.com/kb/324733 OR http://support.microsoft.com/kb/888469)
When your application is ready (with bootstrapper), you'll have to create a autorun.inf file on CD root path. Search 'autorun.inf create' on your favorite Search Engine.
It is possible using Mono's bundling feature:
"The resulting executable is self contained and does not need the Mono runtime installed to run."
Mono is an Open Source .Net clone and should be able to run most .Net applications. See "Bundles" section here: http://www.mono-project.com/Guide:Running_Mono_Applications
You could use .hta file on CD to launch as splash page, and from there detect if .NET is installed (using COM from HTA file) and then run your custom executable.
.hta files are what Microsoft SQL Server (and most of their others) installation cd uses from memory, easy to make them look very professional (its just html in the background basically)
You can include the runtime with the CD, but you'll have to install it before running your app. You might look into just popping open an html file from the CD.
Otherwise, you can look at writing a small native program that can prompt to install the runtime if it's not there, or run your .NET app if it is.
Try Delphi; it's by far the best way to create native win32 application nowadays.
It creates slick stand-alone .exe files with rich GUI's that don't need any runtime libraries or other annoying dependencies. Works on any windows machine.
There was a program from Macrovision called "Demoshield" that worked well back in the day. I'm not sure if its available anymore, but it was an alright program for creating the auto-run programs.

Categories