Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MarshalAs attributes #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,82 @@ GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
nuget.exe


# Created by https://www.toptal.com/developers/gitignore/api/rider
# Edit at https://www.toptal.com/developers/gitignore?templates=rider

### Rider ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# End of https://www.toptal.com/developers/gitignore/api/rider

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.LegacyWrapper/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.LegacyWrapper/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.LegacyWrapper/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.LegacyWrapper/.idea/projectSettingsUpdater.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.LegacyWrapper/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.LegacyWrapper/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions LegacyWrapper.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
# Visual Studio Version 16
VisualStudioVersion = 16.0.30523.141
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyWrapper32", "LegacyWrapper32\LegacyWrapper32.csproj", "{B7665A68-F19C-4539-9FE1-06B14BA774E3}"
EndProject
Expand Down
72 changes: 62 additions & 10 deletions LegacyWrapperTest.Integration/Client/WrapperClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using LegacyWrapper.ErrorHandling;
using LegacyWrapperClient.Architecture;
using LegacyWrapperClient.Client;
using LegacyWrapperClient.Configuration;
using LegacyWrapperClient.DynamicProxy;
using LegacyWrapperTest.Integration.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -108,6 +101,67 @@ public void TestPWideCharHandling()

Assert.AreEqual(input, result);
}

[TestMethod]
public void TestBstrHandling()
{
IWrapperConfig configuration = WrapperConfigBuilder.Create()
.TargetArchitecture(ArchitectureToLoad)
.Build();

string input = "Hello World";

int result;

using (var client = WrapperProxyFactory<ITestDll>.GetInstance(configuration))
{
result = client.TestBstrHandling(input);
}

// Result should be length of input
Assert.AreEqual(11, result);
}

[TestMethod]
public void TestBstrPointerHandling()
{
IWrapperConfig configuration = WrapperConfigBuilder.Create()
.TargetArchitecture(ArchitectureToLoad)
.Build();

string input = "Hello World";

int result;

using (var client = WrapperProxyFactory<ITestDll>.GetInstance(configuration))
{
result = client.TestBstrPointerHandling(ref input);
}

// Result should be length of input
Assert.AreEqual(11, result);
}

[TestMethod]
public void TestBstrRefHandling()
{
IWrapperConfig configuration = WrapperConfigBuilder.Create()
.TargetArchitecture(ArchitectureToLoad)
.Build();

IntPtr input = IntPtr.Zero;

int result;

using (var client = WrapperProxyFactory<ITestDll>.GetInstance(configuration))
{
result = client.TestBstrRefHandling(ref input);
}

// Result should be length of input
Assert.AreEqual(11, result);
Assert.AreEqual("HELLO WORLD", input);
}

[TestMethod]
public void TestRefParameterHandling()
Expand Down Expand Up @@ -164,7 +218,5 @@ public void TestCallLibraryMultipleTimes()
// Ref param should be incremented by 1
Assert.AreEqual(1339, parameter);
}


}
}
}
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions LegacyWrapperTestDll/LegacyWrapperTestDll.def
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ EXPORTS
TestNormalFunc
TestPCharHandling
TestPWideCharHandling
TestBstrHandling
TestBstrPointerHandling
TestBstrRefHandling
TestVarParamHandling
TestMultipleVarParamsHandling
16 changes: 9 additions & 7 deletions LegacyWrapperTestDll/LegacyWrapperTestDll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
<ProjectGuid>{E53A4D07-C345-4C92-B1B6-F0E72BA7262E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>LegacyWrapperTestDll</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand All @@ -72,17 +72,19 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -125,7 +127,7 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>Test.def</ModuleDefinitionFile>
<ModuleDefinitionFile>LegacyWrapperTestDll.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down
21 changes: 21 additions & 0 deletions LegacyWrapperTestDll/Test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <wchar.h>
#include <wtypes.h>
#include <Windows.h>

#define DllExport __declspec(dllexport)
Expand Down Expand Up @@ -40,6 +41,26 @@ extern "C" {

return ptr;
}

DllExport int TestBstrHandling(BSTR AParam) {
size_t size = sizeof(wchar_t) * SysStringLen(AParam) + 1;

return size;
}

DllExport int TestBstrPointerHandling(BSTR* AParam) {
size_t size = sizeof(wchar_t) * SysStringLen(*AParam) + 1;

return size;
}

DllExport int TestBstrRefHandling(BSTR* AParam) {
size_t size = sizeof(wchar_t) * SysStringLen(*AParam) + 1;

*AParam = SysAllocString(L"HELLO WORLD!");

return size;
}

/////

Expand Down