MainApp now loads the mouse DLL.

master
Pacman Ghost 8 years ago
parent 2d196ace7c
commit 9da6f09729
  1. 34
      MainApp/MouseDll.cs
  2. 11
      MainApp/MouseInterception.csproj
  3. 25
      MainApp/MouseInterception.sln
  4. 4
      MainApp/Program.cs
  5. 63
      MainApp/strings.Designer.cs
  6. 120
      MainApp/strings.resx
  7. 40
      MouseDll/api.cpp
  8. 30
      MouseDll/main.cpp
  9. 11
      MouseDll/main.hpp
  10. 20
      MouseDll/mouse.sln
  11. 30
      MouseDll/mouse.vcproj
  12. 30
      MouseDll/utils.cpp
  13. 18
      MouseDll/utils.hpp

@ -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 ) ;
}
}
}

@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -54,6 +55,7 @@
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="MouseDll.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
@ -61,6 +63,10 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
@ -74,6 +80,11 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>strings.resx</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -2,17 +2,42 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MouseInterception", "MouseInterception.csproj", "{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}"
ProjectSection(ProjectDependencies) = postProject
{A0A8359D-6B08-4B29-9BC2-9A2EC676D647} = {A0A8359D-6B08-4B29-9BC2-9A2EC676D647}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mouse", "..\MouseDll\mouse.vcproj", "{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Debug|Win32.ActiveCfg = Debug|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Release|Any CPU.Build.0 = Release|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4D4FFFC1-301B-4312-8861-A62FC5E3C5A7}.Release|Win32.ActiveCfg = Release|Any CPU
{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Debug|Any CPU.ActiveCfg = Debug|Win32
{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{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|Any CPU.ActiveCfg = Release|Win32
{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{A0A8359D-6B08-4B29-9BC2-9A2EC676D647}.Release|Mixed Platforms.Build.0 = Release|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

@ -13,6 +13,10 @@ namespace MouseInterception
[STAThread]
static void Main()
{
// FIXME!
MouseDll mouseDll = new MouseDll() ;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new MainForm() );

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.5485
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MouseInterception {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class strings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal strings() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MouseInterception.strings", typeof(strings).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

@ -0,0 +1,40 @@
#include <stdexcept>
#include <windows.h>
#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() ) ;
}
}

@ -0,0 +1,30 @@
#include <stdexcept>
#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 ;
}

@ -0,0 +1,11 @@
#ifndef MAIN_HPP
#define MAIN_HPP
// ---------------------------------------------------------------------
extern void openApi() ;
extern void closeApi() ;
// ---------------------------------------------------------------------
#endif // MAIN_HPP

@ -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

@ -18,7 +18,7 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
@ -47,6 +47,7 @@
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
DebugInformationFormat="4"
/>
<Tool
@ -85,11 +86,13 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copying $(ProjectName).dll..."
CommandLine="COPY $(OutDir)\$(ProjectName).dll ..\MainApp\bin\$(OutDir)\"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
@ -119,6 +122,7 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
DebugInformationFormat="3"
/>
<Tool
@ -159,6 +163,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copying $(ProjectName).dll..."
CommandLine="COPY $(OutDir)\$(ProjectName).dll ..\MainApp\bin\$(OutDir)\"
/>
</Configuration>
</Configurations>
@ -170,16 +176,36 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\api.cpp"
>
</File>
<File
RelativePath=".\dllMain.cpp"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\utils.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\main.hpp"
>
</File>
<File
RelativePath=".\utils.hpp"
>
</File>
</Filter>
<Filter
Name="Resource Files"

@ -0,0 +1,30 @@
#include <windows.h>
#include <cassert>
#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<wchar_t*>(buf.c_str()) , nChars ) ;
return buf ;
}

@ -0,0 +1,18 @@
#ifndef UTILS_HPP
#define UTILS_HPP
#include <string>
#include <sstream>
// ---------------------------------------------------------------------
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
Loading…
Cancel
Save