diff --git a/MainApp/MouseDll.cs b/MainApp/MouseDll.cs
new file mode 100644
index 0000000..b86ed29
--- /dev/null
+++ b/MainApp/MouseDll.cs
@@ -0,0 +1,34 @@
+using System ;
+using System.Runtime.InteropServices ;
+
+namespace MouseInterception
+{
+ class MouseDll
+ {
+
+ [DllImport( @"mouse.dll" , CallingConvention=CallingConvention.Cdecl )]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ private static extern string open_api() ;
+
+ [DllImport( @"mouse.dll" , CallingConvention=CallingConvention.Cdecl )]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ private static extern string close_api() ;
+
+ public MouseDll()
+ {
+ // open the mouse API
+ string errorMsg = open_api() ;
+ if ( errorMsg != null )
+ throw new Exception( errorMsg ) ;
+ }
+
+ ~MouseDll()
+ {
+ // close the mouse API
+ string errorMsg = close_api() ;
+ if ( errorMsg != null )
+ throw new Exception( errorMsg ) ;
+ }
+
+ }
+}
diff --git a/MainApp/MouseInterception.csproj b/MainApp/MouseInterception.csproj
index e7817f5..cb8aee9 100644
--- a/MainApp/MouseInterception.csproj
+++ b/MainApp/MouseInterception.csproj
@@ -21,6 +21,7 @@
DEBUG;TRACE
prompt
4
+ true
pdbonly
@@ -54,6 +55,7 @@
MainForm.cs
+
@@ -61,6 +63,10 @@
Resources.Designer.cs
Designer
+
+ ResXFileCodeGenerator
+ strings.Designer.cs
+
True
Resources.resx
@@ -74,6 +80,11 @@
Settings.settings
True
+
+ True
+ True
+ strings.resx
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/MouseDll/api.cpp b/MouseDll/api.cpp
new file mode 100644
index 0000000..822f1c0
--- /dev/null
+++ b/MouseDll/api.cpp
@@ -0,0 +1,40 @@
+#include
+#include
+#include "main.hpp"
+#include "utils.hpp"
+
+using namespace std ;
+
+// ---------------------------------------------------------------------
+
+extern "C" __declspec(dllexport) BSTR
+open_api()
+{
+ // open the API
+ try
+ {
+ openApi() ;
+ return NULL ;
+ }
+ catch ( exception& xcptn )
+ {
+ return SysAllocString( fromUtf8( MAKE_STRING( xcptn.what() ) ).c_str() ) ;
+ }
+}
+
+// ---------------------------------------------------------------------
+
+extern "C" __declspec(dllexport) BSTR
+close_api()
+{
+ // close the API
+ try
+ {
+ closeApi() ;
+ return NULL ;
+ }
+ catch ( exception& xcptn )
+ {
+ return SysAllocString( fromUtf8( MAKE_STRING( xcptn.what() ) ).c_str() ) ;
+ }
+}
diff --git a/MouseDll/main.cpp b/MouseDll/main.cpp
new file mode 100644
index 0000000..3119334
--- /dev/null
+++ b/MouseDll/main.cpp
@@ -0,0 +1,30 @@
+#include
+#include "main.hpp"
+
+using namespace std ;
+
+// --- LOCAL DATA ------------------------------------------------------
+
+static bool gIsOpen = false ;
+
+// ---------------------------------------------------------------------
+
+void
+openApi()
+{
+ // open the API
+ if ( gIsOpen )
+ throw runtime_error( "API is already open." ) ;
+ gIsOpen = true ;
+}
+
+// ---------------------------------------------------------------------
+
+void
+closeApi()
+{
+ // close the API
+ if ( ! gIsOpen )
+ throw runtime_error( "API is not open." ) ;
+ gIsOpen = false ;
+}
diff --git a/MouseDll/main.hpp b/MouseDll/main.hpp
new file mode 100644
index 0000000..0a35664
--- /dev/null
+++ b/MouseDll/main.hpp
@@ -0,0 +1,11 @@
+#ifndef MAIN_HPP
+#define MAIN_HPP
+
+// ---------------------------------------------------------------------
+
+extern void openApi() ;
+extern void closeApi() ;
+
+// ---------------------------------------------------------------------
+
+#endif // MAIN_HPP
\ No newline at end of file
diff --git a/MouseDll/mouse.sln b/MouseDll/mouse.sln
deleted file mode 100644
index 3389664..0000000
--- a/MouseDll/mouse.sln
+++ /dev/null
@@ -1,20 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual Studio 2008
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mouse", "mouse.vcproj", "{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Release|Win32 = Release|Win32
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Debug|Win32.ActiveCfg = Debug|Win32
- {A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Debug|Win32.Build.0 = Debug|Win32
- {A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Release|Win32.ActiveCfg = Release|Win32
- {A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Release|Win32.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/MouseDll/mouse.vcproj b/MouseDll/mouse.vcproj
index cfaec96..7624b86 100644
--- a/MouseDll/mouse.vcproj
+++ b/MouseDll/mouse.vcproj
@@ -18,7 +18,7 @@
@@ -170,16 +176,36 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
+
+
+
+
+
+
+
+
+
+
+#include
+#include "utils.hpp"
+
+using namespace std ;
+
+// ---------------------------------------------------------------------
+
+wstring
+fromUtf8( const char* pStr , int len )
+{
+ if ( pStr == NULL || len == 0 )
+ return L"" ;
+ assert( len > 0 || len == -1 ) ;
+
+ // figure out how many wide characters we are going to get
+ int nChars = MultiByteToWideChar( CP_UTF8 , 0 , pStr , len , NULL , 0 ) ;
+ if ( len == -1 )
+ -- nChars ;
+ if ( nChars == 0 )
+ return L"" ;
+
+ // convert the string from UTF-8
+ // nb: slightly naughty to write directly into the string like this
+ wstring buf ;
+ buf.resize( nChars ) ;
+ MultiByteToWideChar( CP_UTF8 , 0 , pStr , len , const_cast(buf.c_str()) , nChars ) ;
+
+ return buf ;
+}
diff --git a/MouseDll/utils.hpp b/MouseDll/utils.hpp
new file mode 100644
index 0000000..61407a2
--- /dev/null
+++ b/MouseDll/utils.hpp
@@ -0,0 +1,18 @@
+#ifndef UTILS_HPP
+#define UTILS_HPP
+
+#include
+#include
+
+// ---------------------------------------------------------------------
+
+extern std::wstring fromUtf8( const char* pStr , int len=-1 ) ;
+inline std::wstring fromUtf8( const std::string& str ) { return fromUtf8(str.c_str(),str.length()) ; }
+
+// ---------------------------------------------------------------------
+
+#define MAKE_STRING( msg ) ( ((std::ostringstream&)((std::ostream&)std::ostringstream() << msg)).str() )
+
+// ---------------------------------------------------------------------
+
+#endif // UTILS_HPP
\ No newline at end of file