Vaibhav
Vaibhav

Reputation: 359

I am not able to add Leap.dll and Leapcsharp.dll references in visual studio

I am not able to add Leap.dll and Leapcsharp.dll from Leap SDK in given Visual studio project.I am using VS2012 express for Windows Desktop.

I have downloaded sdk from leapmotion site.I get error as "A reference could not be loaded.Please make sure that file is accessible and that is valid assembly or COM component."

Upvotes: 1

Views: 4948

Answers (4)

Aditya Alle
Aditya Alle

Reputation: 57

You simply need to add the files Leap.dll and LeapCSharp.dll to your project.

And set the file property in Visual studio

Copy to output directory = Copy Always;

Also add a reference to the project of LeapCSharp.NET4.0.dll or LeapCSharp.NET3.5.dll to your project. the reference must correspond to the machine type being used to debug or release the project. These files come to you within the SDK

Upvotes: 0

Joan Gerard
Joan Gerard

Reputation: 125

I had the same problem.

You have to add an existing item to your solution and select the files Leap.dll, LeapCSharp.dll from the folder: LeapDeveloperKit\LeapSDK\lib(x86 or x64) and LeapCSharp.NET4.0.dll or LeapCSharp.NET3.5.dll (it depends if you are using framework 4 or 3.5 in your current project) from folder: LeapDeveloperKit\LeapSDK\lib. Then you have to do rigth click in each one of them and select the Properties option. You have to ensure that the "Copy to Output Directory" option is selected with "copy allwas" option (that's very important). Then you have to do rigth click in the References -> Add Reference -> Browse -> select your proyect (your current solution)-> select LeapCSharp.NET4.0.dll (from folder)-> ok. That's all.

or

See this video min 11:29. She tells you better.

Upvotes: 0

Jeckyhl
Jeckyhl

Reputation: 41

from Leap Motion Developper Documentation

On Windows, make sure that Sample.exe, and either LeapCSharp.NET3.5.dll, or LeapCSharp.NET4.0.dll are in the current directory. Use the libraries in the lib\x86 directory for 32-bit projects. Use the libraries in the lib\x64 directory for 64-bit projects. [...]

You only need LeapCSharp.NET3.5.dll, or LeapCSharp.NET4.0.dll to compile your project. But you'll need the unmanaged libraries Leap.dll and LeapCSharp.dll to run your application (which are in lib\x86 or lib\x64 in the Leap SDK)

Personally I put these unmanaged libraries in a App_Bin\<platform name> folder (<platform name> = x84 or x64) under the solution directory and I use the following post-build command to copy them to the compiler output directory (e.g. MyProject\bin\x64\Debug)

xcopy /Y  /D "$(ProjectDir)..\App_Bin\$(PlatformName)\*.*" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\"

Upvotes: 1

crthompson
crthompson

Reputation: 15875

Up one directory from the leap.dll and leapcsharp.dll is LeapCSharp.NET3.5.dll and LeapCSharp.NET4.0.dll. (LeapDeveloperKit\LeapSDK\lib)

These are the tools for Visual studio references.

If you want to use the leap.dll file then you'll need to use P/Invoke

EDIT: Perhaps you could check out this leap tutorial, complete with code examples.

Here is a better P/Invoke tutorial.

Using an application like DLL Export Viewer you can see all the methods available for your leap dll's. These would be your entry points using P/Invoke. There is also a PInvoke assistance tool that will write your c# for you.

However, doing this with the leap.dll:

[DllImport("leap.dll")]
public static extern bool hasFocus();

Is the same as doing this with the LeapCSharp.Net4.0 dll reference:

Leap.Controller con = new Controller();
var focus = con.HasFocus;

So you dont need both sets of DLL's.

Upvotes: 1

Related Questions