Pinvoke help


R

Ringo

the LeafProject http://www.leafproject.org has a DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.

;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")

; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)

; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)

; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)

; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)

; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)

; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)



So from that I looked up Pinvoke and wrote this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();



public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}

When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?

Thanks
Ringo


System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

Can you show the header file for C++ to access this? You woud probably
have more people able to help if you provided that, and it would be easier
to show you the declarations you would need.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ringo said:
the LeafProject http://www.leafproject.org has a DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.

;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")

; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)

; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)

; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)

; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)

; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)

; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)



So from that I looked up Pinvoke and wrote this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();



public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}

When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?

Thanks
Ringo


System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
R

Ringo

I jsut got the .H file used. i was going by the LISP code. I'm not a C+
+ guy at all, but I don't see anything in the .H file that has to do
with the function names called. Am I missing somethign here?


// FaceRecog.h : main header file for the FACERECOG DLL
//

#if !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
#define
AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

/////////////////////////////////////////////////////////////////////////////
// CFaceRecogApp
// See FaceRecog.cpp for the implementation of this class
//

class CFaceRecogApp : public CWinApp
{
public:
CFaceRecogApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFaceRecogApp)
public:
//}}AFX_VIRTUAL

//{{AFX_MSG(CFaceRecogApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif // !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)


Can you show the header file for C++ to access this? You woud probably
have more people able to help if you provided that, and it would be easier
to show you the declarations you would need.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




the LeafProjecthttp://www.leafproject.orghas a DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo

System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()- Hide quoted text -

- Show quoted text -
 
R

Ringo

I jsut got the .H file used. i was going by the LISP code. I'm not a C+
+ guy at all, but I don't see anything in the .H file that has to do
with the function names called. Am I missing somethign here?

// FaceRecog.h : main header file for the FACERECOG DLL
//

#if !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
#define
AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

///////////////////////////////////////////////////////////////////////////­//
// CFaceRecogApp
// See FaceRecog.cpp for the implementation of this class
//

class CFaceRecogApp : public CWinApp
{
public:
CFaceRecogApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFaceRecogApp)
public:
//}}AFX_VIRTUAL

//{{AFX_MSG(CFaceRecogApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

};

///////////////////////////////////////////////////////////////////////////­//

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif // !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)

Can you show the header file for C++ to access this? You woud probably
have more people able to help if you provided that, and it would be easier
to show you the declarations you would need.
the LeafProjecthttp://www.leafproject.orghasa DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo
System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -




Also here are the definitions at the begginning of the .cpp file
extern "C" __declspec(dllexport) int GetNum();
extern "C" __declspec(dllexport) int DoEigen();
extern "C" __declspec(dllexport) int LookForFaces(char* place);
extern "C" __declspec(dllexport) int AddFace();
extern "C" __declspec(dllexport) int StartCamera();
extern "C" __declspec(dllexport) int StopCamera();
 
D

Dave Shooter

Hi Ringo

I don't know for sure if the argument to the DllImportAttribute is case
sensitive or not, but I notice that the first one is in lower case in
your code:
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();

the LeafProject http://www.leafproject.org has a DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.

;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")

; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)

; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)

; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)

; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)

; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)

; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)



So from that I looked up Pinvoke and wrote this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();



public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}

When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?

Thanks
Ringo


System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
R

Ringo

Hi Ringo

I don't know for sure if the argument to the DllImportAttribute is case
sensitive or not, but I notice that the first one is in lower case in
your code:


[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
Ringo said:
the LeafProjecthttp://www.leafproject.orghas a DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo

System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()- Hide quoted text-

- Show quoted text -

I've tried uppercase, lowercase, etc. I copied the name of the file
directly from the file itself and pasted that to be sure and still get
the same error. I have commented out all the other pinvokes except the
start camera and it still crashes. Must be something I'm missing. any
other ideas?
Ringo
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

Have you tried hard-coding the path to the dll just to see if it works?
Also, is the facerecog.dll stand-alone? If so, place it in the same
directory as your application and it should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I jsut got the .H file used. i was going by the LISP code. I'm not a C+
+ guy at all, but I don't see anything in the .H file that has to do
with the function names called. Am I missing somethign here?

// FaceRecog.h : main header file for the FACERECOG DLL
//

#if !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
#define
AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

///////////////////////////////////////////////////////////////////////////­//
// CFaceRecogApp
// See FaceRecog.cpp for the implementation of this class
//

class CFaceRecogApp : public CWinApp
{
public:
CFaceRecogApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFaceRecogApp)
public:
//}}AFX_VIRTUAL

//{{AFX_MSG(CFaceRecogApp)
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of
generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

};

///////////////////////////////////////////////////////////////////////////­//

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif // !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)

Can you show the header file for C++ to access this? You woud
probably
have more people able to help if you provided that, and it would be
easier
to show you the declarations you would need.
the LeafProjecthttp://www.leafproject.orghasa DLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo
System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()- Hide quoted
text -
- Show quoted text -- Hide quoted text -

- Show quoted text -




Also here are the definitions at the begginning of the .cpp file
extern "C" __declspec(dllexport) int GetNum();
extern "C" __declspec(dllexport) int DoEigen();
extern "C" __declspec(dllexport) int LookForFaces(char* place);
extern "C" __declspec(dllexport) int AddFace();
extern "C" __declspec(dllexport) int StartCamera();
extern "C" __declspec(dllexport) int StopCamera();
 
R

Ringo

I've tried somethign like
[DllImport("c:\Windows\system32\FaceRecog.dll")]
public static extern int StartCamera();

But it did not like the "\"'s.

I also tried putting the dll where the .sln file goes and down 1
directory where the rest of the files go and got the same result.
still no luck.

Have you tried hard-coding the path to the dll just to see if it works?
Also, is the facerecog.dll stand-alone? If so, place it in the same
directory as your application and it should work.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I jsut got the .H file used. i was going by the LISP code. I'm not a C+
+ guy at all, but I don't see anything in the .H file that has to do
with the function names called. Am I missing somethign here?
// FaceRecog.h : main header file for the FACERECOG DLL
//
#if !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
#define
AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
///////////////////////////////////////////////////////////////////////////­­//
// CFaceRecogApp
// See FaceRecog.cpp for the implementation of this class
//
class CFaceRecogApp : public CWinApp
{
public:
CFaceRecogApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFaceRecogApp)
public:
//}}AFX_VIRTUAL
//{{AFX_MSG(CFaceRecogApp)
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of
generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
Can you show the header file for C++ to access this? You woud
probably
have more people able to help if you provided that, and it would be
easier
to show you the declarations you would need.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

the LeafProjecthttp://www.leafproject.orghasaDLL for Face
recognition. it is written in C++ but they interface to it from Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo
System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender, EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­­­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()- Hide quoted
text -
- Show quoted text -- Hide quoted text -
- Show quoted text -

Also here are the definitions at the begginning of the .cpp file
extern "C" __declspec(dllexport) int GetNum();
extern "C" __declspec(dllexport) int DoEigen();
extern "C" __declspec(dllexport) int LookForFaces(char* place);
extern "C" __declspec(dllexport) int AddFace();
extern "C" __declspec(dllexport) int StartCamera();
extern "C" __declspec(dllexport) int StopCamera();- Hide quoted text -

- Show quoted text -
 
N

Nicholas Paldino [.NET/C# MVP]

Ringo,

If the path to the DLL is this:

"c:\Windows\system32\FaceRecog.dll"

Then your DllImport needs to be this:

[DllImport(@"c:\Windows\system32\FaceRecog.dll")]

Or this:


[DllImport("c:\\Windows\\system32\\FaceRecog.dll")]

Also, you say you put the dll one directory down from where the .sln
file is, which would be the project directory, but that isn't where the
output EXE is built. Place it in that directory and see if it works without
the full path.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I've tried somethign like
[DllImport("c:\Windows\system32\FaceRecog.dll")]
public static extern int StartCamera();

But it did not like the "\"'s.

I also tried putting the dll where the .sln file goes and down 1
directory where the rest of the files go and got the same result.
still no luck.

Have you tried hard-coding the path to the dll just to see if it
works?
Also, is the facerecog.dll stand-alone? If so, place it in the same
directory as your application and it should work.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I jsut got the .H file used. i was going by the LISP code. I'm not a C+
+ guy at all, but I don't see anything in the .H file that has to do
with the function names called. Am I missing somethign here?
// FaceRecog.h : main header file for the FACERECOG DLL
//
#if !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
#define
AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
///////////////////////////////////////////////////////////////////////////­­//
// CFaceRecogApp
// See FaceRecog.cpp for the implementation of this class
//
class CFaceRecogApp : public CWinApp
{
public:
CFaceRecogApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFaceRecogApp)
public:
//}}AFX_VIRTUAL
//{{AFX_MSG(CFaceRecogApp)
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of
generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
Can you show the header file for C++ to access this? You woud
probably
have more people able to help if you provided that, and it would be
easier
to show you the declarations you would need.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

the LeafProjecthttp://www.leafproject.orghasaDLL for Face
recognition. it is written in C++ but they interface to it from
Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face
detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following
message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo
System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender,
EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­­­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FaceRecognition.Program.Main() in e:\FaceRecognition
\FaceRecognition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()- Hide quoted
text -
- Show quoted text -- Hide quoted text -
- Show quoted text -

Also here are the definitions at the begginning of the .cpp file
extern "C" __declspec(dllexport) int GetNum();
extern "C" __declspec(dllexport) int DoEigen();
extern "C" __declspec(dllexport) int LookForFaces(char* place);
extern "C" __declspec(dllexport) int AddFace();
extern "C" __declspec(dllexport) int StartCamera();
extern "C" __declspec(dllexport) int StopCamera();- Hide quoted text -

- Show quoted text -
 
Ad

Advertisements

R

Ringo

I put it here
E:\FaceRecognition\FaceRecognition\bin\Debug
But still get the same error.

I also tried
[DllImport("c:\\Windows\\system32\\FaceRecog.dll")]
and
[DllImport(@"c:\Windows\system32\FaceRecog.dll")]
but with the same error


Ringo,

If the path to the DLL is this:

"c:\Windows\system32\FaceRecog.dll"

Then your DllImport needs to be this:

[DllImport(@"c:\Windows\system32\FaceRecog.dll")]

Or this:

[DllImport("c:\\Windows\\system32\\FaceRecog.dll")]

Also, you say you put the dll one directory down from where the .sln
file is, which would be the project directory, but that isn't where the
output EXE is built. Place it in that directory and see if it works without
the full path.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I've tried somethign like
[DllImport("c:\Windows\system32\FaceRecog.dll")]
public static extern int StartCamera();

But it did not like the "\"'s.

I also tried putting the dll where the .sln file goes and down 1
directory where the rest of the files go and got the same result.
still no luck.

Have you tried hard-coding the path to the dll just to see if it
works?
Also, is the facerecog.dll stand-alone? If so, place it in the same
directory as your application and it should work.
"Ringo" <[email protected]> wrote in message
I jsut got the .H file used. i was going by the LISP code. I'm not a C+
+ guy at all, but I don't see anything in the .H file that has to do
with the function names called. Am I missing somethign here?
// FaceRecog.h : main header file for the FACERECOG DLL
//
#if !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
#define
AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
///////////////////////////////////////////////////////////////////////////­­­//
// CFaceRecogApp
// See FaceRecog.cpp for the implementation of this class
//
class CFaceRecogApp : public CWinApp
{
public:
CFaceRecogApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFaceRecogApp)
public:
//}}AFX_VIRTUAL
//{{AFX_MSG(CFaceRecogApp)
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of
generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////////////////////////////////////////­­­//
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_FACERECOG_H__484912E7_8723_407A_91D6_39A24AD3B3E4__INCLUDED_)
On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"
Can you show the header file for C++ to access this? You woud
probably
have more people able to help if you provided that, and it would be
easier
to show you the declarations you would need.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

the LeafProjecthttp://www.leafproject.orghasaDLLfor Face
recognition. it is written in C++ but they interface to it from
Lisp.
I want to interface to it from C#.
Their Lisp definitions looks like this.
;;;; REGISTER THE VISION FACE RECOGNITION
DLL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fli:register-module "FaceRecog.dll")
; an interface function:
; -1 = ERROR: camera failed to start
; 0 = camera on successfully
(fli:define-foreign-function
(Start-Camera "StartCamera")
()
:result-type :int)
; an interface function:
; -1 = ERROR: camera failed to stop
; 0 = camera off successfully
(fli:define-foreign-function
(Stop-Camera "StopCamera")
()
:result-type :int)
; an interface function:
; returns the number of face images in the database
(fli:define-foreign-function
(Get-Number-Images "GetNum")
()
:result-type :int)
; an interface function:
; -2 = ERROR: write error
; -1 = ERROR: could not create values.txt file
; 0 = eigens created and stored successfully
(fli:define-foreign-function
(Calc-Eigens "DoEigen")
()
:result-type :int)
; an interface function
; -1 = ERROR: could not rename or add face
; 0 = face added sucessfully
(fli:define-foreign-function
(Add-Face "AddFace")
()
:result-type :int)
; an interface function
; -4 = ERROR: could not save face image
; -3 = ERROR: could not read coefficient file
; -2 = ERROR: could not capture
; -1 = ERROR: could not load classifier cascade
; 0 or more = number of faces detected... if only one face
detected,
then
; return string = image number as a string, eg. "6" means image 6
(fli:define-foreign-function
(Look-For-Faces "LookForFaces")
((return-string :)reference-return :)ef-mb-string :limit 256))))
:result-type :int
:lambda-list (&aux return-string)
:language :c
:calling-convention :cdecl
:result-type :int)
So from that I looked up Pinvoke and wrote this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceRecognition
{
public partial class Form1 : Form
{
[DllImport("facerecog.dll")]
public static extern int StartCamera();
[DllImport("FaceRecog.dll")]
public static extern int StopCamera();
[DllImport("FaceRecog.dll")]
public static extern int GetNum();
[DllImport("FaceRecog.dll")]
public static extern int DoEigen();
[DllImport("FaceRecog.dll")]
public static extern int AddFace();
[DllImport("FaceRecog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLine(" startcamera = " + result);
}
}
}
When I click the button to do StartCamera I get the following
message
like it cannot find the DLL (which is in windows/system32). I have
tried moving the DLL to the C# apps directory too but that did not
help either. What am I doing wrong?
Thanks
Ringo
System.DllNotFoundException was unhandled
Message="Unable to load DLL 'facerecog.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRecognition"
TypeName=""
StackTrace:
at FaceRecognition.Form1.StartCamera()
at FaceRecognition.Form1.button1_Click(Object sender,
EventArgs
e) in E:\FaceRecognition\FaceRecognition\Form1.cs:line 78
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa­­­­feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at

...

read more »- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top