native-interop | Native Interoperability | Wrapper library
kandi X-RAY | native-interop Summary
kandi X-RAY | native-interop Summary
Call a function from a shared library written in C, from various languages.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- The main entry point
native-interop Key Features
native-interop Examples and Code Snippets
Community Discussions
Trending Discussions on native-interop
QUESTION
This issue is driving me up the wall... Just saying.
My company has a legacy C++ library and I have been tasked to create a .NET wrapper.
I have no experience of C++ or P/Invoke so to start with I am trying a simple method.
I have read the official documentation and I have also found a nice tutorial.
However, I have discovered that the target .NET framework of the consuming app makes a difference.
The P/Invoke code from the tutorial works fine but I have noticed that he is targeting .NET Framework 4 Client Profile.
If I place break points then they are hit and everything works as expected, if I target a framework higher than 4 then the program crashes without exception.
I have a really simple method defined in C++:
framework.h
ANSWER
Answered 2021-Jan-22 at 12:50Now that I know it is a string issue I did a little searching and I found this SO question.
So in the end I used the BSTR
approach.
QUESTION
I'm calling into a native DLL from F#. It's proven pretty simple for functions that take no arguments or only basic types, but I'm having a lot of trouble getting my code to work otherwise.
The C++ code is:
...ANSWER
Answered 2020-Aug-06 at 10:01Never mind, I got it worked out.
For anyone who might care, my F# code worked with just a couple of changes:
- I changed
UnmanagedType.LPStr
toUnmanagedType.ByValTStr
- In the
extern
function declaration, I decoratedHomeQuery[] queries
with[]
(i.e.[]HomeQuery[] queries
).
That's all.
QUESTION
I have a dotnet core library, a framework 4.7.2 library and a vb6 application.
I want to write a common library for them all to access and so choose .netstandard2.0
I tried a the 4.7.2 framework wrapper library between .netstandard2.0 library and vb6.
However I ran into assembly binding problems
Looking at the docs I see
In .NET Core, the process for exposing your .NET objects to COM has been significantly streamlined in comparison to .NET Framework.
However no mention .netstandard2.0
I decided to try following the docs anyway even though my project is using .netstandard2.0
I got up to the instructions on Generating the COM Host in which case the output files ProjectName.dll, ProjectName.deps.json, ProjectName.runtimeconfig.json and ProjectName.comhost.dll should build.
However the ProjectName.comhost.dll and ProjectName.runtimeconfig.json do not create.
I see in this dotnet standard issue that Microsoft plans on having tooling support in "Preview 4"
I am running VS 16.4.5
[Update]
I decided to try making a .net core wrapper library and enabling it for com.
I was able to add my .netstandard to the wrapper library via a nuget package (I build the .netstandard library using azure devops)
When I build my wrapper library the .dll, .deps.json, .pdb, .runtimeconfig.dev.json and .runtimeconfig.json files are created in a bin\Debug\netcoreapp3.1 folder.
However none of the .netstandard library files appear in the bin\debug folder.
I copied the .netstandard library and the .netcore wrapper libraries to the same folder and ran
...ANSWER
Answered 2020-Apr-26 at 08:07Regarding the .NET standard, I may be wrong but I think this is not applicable here because the COM interop stuff are at a higher level than the one .NET standard is targeting; we can only talk about either .NET Core or .NET Framework for COM interop.
If you want to generate a type library, you have few options.
By far, the easiest method is just to use .NET Framework. The fact that you are wanting to create a type library negates the advantages of .NET Core already because several COM, especially the "Automation" features are Windows-only. Using framework will be fine at least until .NET Core 5 comes out.
That said, if you have a business reason for using .NET Core but still need COM support, including the type library, then based on this GitHub comment, you should be able to compile your own IDL. Note that requires you to install C++ build tools because the MIDL compiler is not really a standalone thing that you can get without the rest of the C++ build tools.
It is strongly suggested to have had read the documentation on how .NET Core handles COM activation.
Assuming having the C++ build tools is not a barrier for you, the steps would be the following:
1) Create a .idl
file that defines all your COM interfaces in the IDL format. That requires some translation between the .NET interface and the COM interface. Here's a partial example of how you'd need to translate between your C# interface and COM interface as defined in IDL:
QUESTION
When PInvoking the WindowsAPI CreateFile from a c# program what is the best practice: calling the generic CreateFile, ANSI CreateFileA, or the Unicode CreateFileW version?
Each of the API's has a different signature for the relevant CharSet:
...ANSWER
Answered 2019-Mar-15 at 07:30Windows uses UTF-16 LE character encoding internally1. When you call the ANSI version of a Windows API, the system will convert the input to UTF-16 (using the calling thread's current code page), call into the Unicode version, and convert the output back to ANSI encoding. This is both needlessly costly as well as lossy: not every Unicode string can be represented using ANSI encoding. The conversion also imposes arbitrary size limitations on input and output buffers (CreateFileA limits the file name length to 260 ANSI code units).
With this in mind you will want to make sure to always call the Unicode version of the Windows API. This provides maximum performance on all supported versions of Windows, as well as guards against loss of information when converting from Unicode to ANSI. Whether you use CharSet.Auto
and MarshalAs(UnmanagedType.LPTStr)
or CharSet.Unicode
and MarshalAs(UnmanagedType.LPWStr)
amounts to the same2, and is a matter of personal preference. Microsoft recommends being explicit, i.e. explicitly name the Unicode version (CreateFileW
) and specify Unicode encoding as well as wide character string types (the 3rd option in your question).
1 With the exception of Windows 95/98/ME, collectively referred to as Win9x. None of them are officially supported.
2 CharSet.Auto
"chooses between ANSI and Unicode formats at run time, based on the target platform", so it isn't identical to CharSet.Unicdoe
in theory. However, all supported platforms use Unicode encoding in practice.
QUESTION
I have started using the :target :nodejs
compiler options for a cljs
project (src). By and large, it works well.
However, when attempting to convert @mapbox/react-native-mapbox-gl
to the updated require
syntax, e.g.
ANSWER
Answered 2017-Dec-15 at 05:04if you using 1.9.854
or above,
you can now use string in :require
QUESTION
Is it possible to use PInvoke to call into AppKit methods when running on .Net Core on Mac OS? Specifically, I would like to use the NSWorkspace.Recycle
method.
According to the documentation PInvoke is supported on MacOS, it is just not clear how one would use this to interact with frameworks such as AppKit.
...ANSWER
Answered 2017-Jun-22 at 07:39PInvoke is for C methods only but since the Objective C runtime is based on C methods, we can use them. Xamarin would provide all the necessary setup and convenience method but this is possible. Note that this example uses unsafe code and thus needs the following property set in the csproj file:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install native-interop
You can use native-interop like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the native-interop component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page