473,569 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pinvoke help

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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();

public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{

}

private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

May 7 '07 #1
9 2718
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]
- mv*@spam.guard. caspershouse.co m

"Ringo" <ri*********@gm ail.comwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();

public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{

}

private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

May 7 '07 #2
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_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
#define
AFX_FACERECOG_H __484912E7_8723 _407A_91D6_39A2 4AD3B3E4__INCLU DED_

#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(C FaceRecogApp)
public:
//}}AFX_VIRTUAL

//{{AFX_MSG(CFace RecogApp)
// 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_LO CATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif // !
defined(AFX_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om

"Ringo" <ringo.da...@gm ail.comwrote in message

news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa *feNativeMethod s.IMsoComponent Manager.FPushMe ssageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()- Hide quoted text -

- Show quoted text -

May 7 '07 #3
On May 7, 1:29 pm, Ringo <ringo.da...@gm ail.comwrote:
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_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
#define
AFX_FACERECOG_H __484912E7_8723 _407A_91D6_39A2 4AD3B3E4__INCLU DED_

#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(C FaceRecogApp)
public:
//}}AFX_VIRTUAL

//{{AFX_MSG(CFace RecogApp)
// 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_LO CATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif // !
defined(AFX_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)

On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om
"Ringo" <ringo.da...@gm ail.comwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa **feNativeMetho ds.IMsoComponen tManager.FPushM essageLoop(Int3 2
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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(dlle xport) int GetNum();
extern "C" __declspec(dlle xport) int DoEigen();
extern "C" __declspec(dlle xport) int LookForFaces(ch ar* place);
extern "C" __declspec(dlle xport) int AddFace();
extern "C" __declspec(dlle xport) int StartCamera();
extern "C" __declspec(dlle xport) int StopCamera();

May 7 '07 #4
Hi Ringo

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

Ringo wrote:
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();

public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{

}

private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
May 7 '07 #5
On May 7, 2:15 pm, Dave Shooter
<alwayskeepitlo aded@delete_thi s.googlemail.co mwrote:
Hi Ringo

I don't know for sure if the argument to the DllImportAttrib ute is case
sensitive or not, but I notice that the first one is in lower case in
your code:
[DllImport("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
Ringo wrote:
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa *feNativeMethod s.IMsoComponent Manager.FPushMe ssageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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

May 7 '07 #6
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]
- mv*@spam.guard. caspershouse.co m

"Ringo" <ri*********@gm ail.comwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
On May 7, 1:29 pm, Ringo <ringo.da...@gm ail.comwrote:
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_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
#define
AFX_FACERECOG_H __484912E7_8723 _407A_91D6_39A2 4AD3B3E4__INCLU DED_

#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(C FaceRecogApp)
public:
//}}AFX_VIRTUAL

//{{AFX_MSG(CFace RecogApp)
// 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_LO CATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif // !
defined(AFX_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)

On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om
"Ringo" <ringo.da...@gm ail.comwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa **feNativeMetho ds.IMsoComponen tManager.FPushM essageLoop(Int3 2
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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(dlle xport) int GetNum();
extern "C" __declspec(dlle xport) int DoEigen();
extern "C" __declspec(dlle xport) int LookForFaces(ch ar* place);
extern "C" __declspec(dlle xport) int AddFace();
extern "C" __declspec(dlle xport) int StartCamera();
extern "C" __declspec(dlle xport) int StopCamera();
May 7 '07 #7
I've tried somethign like
[DllImport("c:\W indows\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.

On May 7, 2:39 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om

"Ringo" <ringo.da...@gm ail.comwrote in message

news:11******** **************@ h2g2000hsg.goog legroups.com...
On May 7, 1:29 pm, Ringo <ringo.da...@gm ail.comwrote:


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_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
#define
AFX_FACERECOG_H __484912E7_8723 _407A_91D6_39A2 4AD3B3E4__INCLU DED_
#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(C FaceRecogApp)
public:
//}}AFX_VIRTUAL
//{{AFX_MSG(CFace RecogApp)
// 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_LO CATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om
"Ringo" <ringo.da...@gm ail.comwrote in message
>news:11******* *************** @n59g2000hsh.go oglegroups.com. ..
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender, EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage&m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa ***feNativeMeth ods.IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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(dlle xport) int GetNum();
extern "C" __declspec(dlle xport) int DoEigen();
extern "C" __declspec(dlle xport) int LookForFaces(ch ar* place);
extern "C" __declspec(dlle xport) int AddFace();
extern "C" __declspec(dlle xport) int StartCamera();
extern "C" __declspec(dlle xport) int StopCamera();- Hide quoted text -

- Show quoted text -

May 7 '07 #8
Ringo,

If the path to the DLL is this:

"c:\Windows\sys tem32\FaceRecog .dll"

Then your DllImport needs to be this:

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

Or this:
[DllImport("c:\\ Windows\\system 32\\FaceRecog.d ll")]

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]
- mv*@spam.guard. caspershouse.co m

"Ringo" <ri*********@gm ail.comwrote in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
I've tried somethign like
[DllImport("c:\W indows\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.

On May 7, 2:39 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om

"Ringo" <ringo.da...@gm ail.comwrote in message

news:11******** **************@ h2g2000hsg.goog legroups.com...
On May 7, 1:29 pm, Ringo <ringo.da...@gm ail.comwrote:


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_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
#define
AFX_FACERECOG_H __484912E7_8723 _407A_91D6_39A2 4AD3B3E4__INCLU DED_
#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(C FaceRecogApp)
public:
//}}AFX_VIRTUAL
//{{AFX_MSG(CFace RecogApp)
// 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_LO CATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om
"Ringo" <ringo.da...@gm ail.comwrote in message
>news:11******* *************** @n59g2000hsh.go oglegroups.com. ..
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender,
EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs
mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage&
m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa ***feNativeMeth ods.IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at FaceRecognition .Program.Main() in e:\FaceRecognit ion
\FaceRecognitio n\Program.cs:li ne 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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(dlle xport) int GetNum();
extern "C" __declspec(dlle xport) int DoEigen();
extern "C" __declspec(dlle xport) int LookForFaces(ch ar* place);
extern "C" __declspec(dlle xport) int AddFace();
extern "C" __declspec(dlle xport) int StartCamera();
extern "C" __declspec(dlle xport) int StopCamera();- Hide quoted text -

- Show quoted text -


May 7 '07 #9
I put it here
E:\FaceRecognit ion\FaceRecogni tion\bin\Debug
But still get the same error.

I also tried
[DllImport("c:\\ Windows\\system 32\\FaceRecog.d ll")]
and
[DllImport(@"c:\ Windows\system3 2\FaceRecog.dll ")]
but with the same error
On May 7, 3:32 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Ringo,

If the path to the DLL is this:

"c:\Windows\sys tem32\FaceRecog .dll"

Then your DllImport needs to be this:

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

Or this:

[DllImport("c:\\ Windows\\system 32\\FaceRecog.d ll")]

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]
- m...@spam.guard .caspershouse.c om

"Ringo" <ringo.da...@gm ail.comwrote in message

news:11******** **************@ o5g2000hsb.goog legroups.com...
I've tried somethign like
[DllImport("c:\W indows\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.

On May 7, 2:39 pm, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om
"Ringo" <ringo.da...@gm ail.comwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
On May 7, 1:29 pm, Ringo <ringo.da...@gm ail.comwrote:
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_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
#define
AFX_FACERECOG_H __484912E7_8723 _407A_91D6_39A2 4AD3B3E4__INCLU DED_
#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(C FaceRecogApp)
public:
//}}AFX_VIRTUAL
//{{AFX_MSG(CFace RecogApp)
// 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_LO CATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_FAC ERECOG_H__48491 2E7_8723_407A_9 1D6_39A24AD3B3E 4__INCLUDED_)
On May 7, 1:20 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
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]
- m...@spam.guard .caspershouse.c om
"Ringo" <ringo.da...@gm ail.comwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
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 "StartCamer a")
()
: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 "LookForFac es")
((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.Collecti ons.Generic;
using System.Componen tModel;
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("face recog.dll")]
public static extern int StartCamera();
[DllImport("Face Recog.dll")]
public static extern int StopCamera();
[DllImport("Face Recog.dll")]
public static extern int GetNum();
[DllImport("Face Recog.dll")]
public static extern int DoEigen();
[DllImport("Face Recog.dll")]
public static extern int AddFace();
[DllImport("Face Recog.dll")]
public static extern int LookForFaces();
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
}
private void button1_Click(o bject sender, EventArgs e)
{
int result = StartCamera();
Console.WriteLi ne(" 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.DllNotFo undException was unhandled
Message="Unable to load DLL 'facerecog.dll' : The specified module
could not be found. (Exception from HRESULT: 0x8007007E)"
Source="FaceRec ognition"
TypeName=""
StackTrace:
at FaceRecognition .Form1.StartCam era()
at FaceRecognition .Form1.button1_ Click(Object sender,
EventArgs
e) in E:\FaceRecognit ion\FaceRecogni tion\Form1.cs:l ine 78
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs
mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage&
m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa ****feNativeMet hods.IMsoCompon entManager.FPus hMessageLoop(In t32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at

...

read more »- Hide quoted text -

- Show quoted text -

May 7 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3457
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is that my form appears to be blocked while the background thread is running. I am very familir with threads in unmanaged code but am just getting into...
5
2819
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile
6
2204
by: Pucca | last post by:
I have a program that originally compiles into a exe file. I changed the compile option to generate dll file. This program calls a com component. Can I use pinvoke in C# to call it? The following is the main dll file. #include "stdafx.h" #define MAX_ADSPATH_CHARS 2048 ...
8
6646
by: Rajesh Soni | last post by:
Hi! I'm getting a PInvoke error while trying to execute the following code... declaration: Structure POINTAPI Dim x As IntPtr
0
1214
by: sd | last post by:
Hi all, I have seen this useful Add-in to get the proper Dllimport sentence to use native code in managed applications. I have tested that add-in in VS.NET 2005 (with .NET CF 2.0) and I have found several problems: Before installation: Installer ask me about .Net CF 1.1. I have installed ..NET CF 2.0 in my machine, but I have install 1.1...
7
7886
by: Rymfax | last post by:
I would really appreciate it if someone could help me figure out what I'm doing wrong trying to PInvoke SetupDiEnumDriverInfo. All the other PInvokes i've done up to this point work fine. Whenver I PInvoke SetupDiEnumDriverInfo though, I get winerror.h code of 1784L, which basically says it doesn't like my buffer, which I assume is the...
0
1192
by: Benosham | last post by:
I have been playing around with trying to PInvoke GDI+ from C#, I made recently made the transition from C/C++ to C# and I really like the language, however being the old fashioned programmer I am I don't like the idea of the framework slowing down my applications with uncessesary safety checks. So I decided to try and PInvoke into GDI+ directly...
14
3774
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain more why C++/CLI would be better to PInvoke than doing the PInvoke in C#? Because, usually in C# as you already know we use DLLImport and extern
2
2051
by: Jeff A | last post by:
I am trying to use pInvoke and I need to pass some data from a C++ dll to C# app and vice-a-versa. The data which needs to be passed to C# app is WCHAR* in the dll. How do I marshal them? Do I need to allocate memory to the string in the dll? I used this in the DLL void GetMsg(LPTSTR msg) { wcsncpy(msg,lpszTheData,256);
3
2986
by: Siegfried Heintze | last post by:
Can someone kindly help me finish my attempt at pinvoke? HKL is a void* and I don't know how to translate it. //static extern UInt32 MapVirtualKeyExW(UInt32 uCode, UInt32 uMapType, HKL dwhkl); Here is the function: http://msdn.microsoft.com/en-us/library/ms646307(VS.85).aspx Thanks!
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.