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

[API Proposal]: aot export api stdcall,UnmanagedCallersOnly for vb6 #96103

Closed
xiaoyaocode163 opened this issue Dec 17, 2023 · 4 comments
Closed
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-NativeAOT-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@xiaoyaocode163
Copy link

Background and motivation

HOW TO EXPORT API IN VB.NET? LIKE:DotNetRuntimeDebugHeader

c# can export stdcall api by UnmanagedCallersOnly,but vb.net can't do this,how can you fix?
or i can use
public function add_export_stdcall(a as long,b as long) as long
return a+b
end function

aot will auto set add_export_stdcall to export as :add

`public static class MyFunctions
{
[UnmanagedCallersOnly(EntryPoint = "Add")]
public static int Add(int a, int b)
{
return a + b;
}

[UnmanagedCallersOnly(EntryPoint = "PrintString")]
public static void PrintString(IntPtr str)
{
    Console.WriteLine(Marshal.PtrToStringAnsi(str));
}

[UnmanagedCallersOnly(EntryPoint = "GetSystemInfoWrite")]
public static void GetSystemInfo()
{
    Console.WriteLine($"ProcessorCount: {Environment.ProcessorCount}");
    Console.WriteLine($"MachineName: {Environment.MachineName}");
}

}`

API Proposal

namespace System.Collections.Generic;

public class MyFancyCollection<T> : IEnumerable<T>
{
    public void Fancy(T item);
}

API Usage

// Fancy the value
var c = new MyFancyCollection<int>();
c.Fancy(42);

// Getting the values out
foreach (var v in c)
    Console.WriteLine(v);

Alternative Designs

No response

Risks

No response

@xiaoyaocode163 xiaoyaocode163 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 17, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 17, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 17, 2023
@am11 am11 added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 17, 2023
@ghost
Copy link

ghost commented Dec 17, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

HOW TO EXPORT API IN VB.NET? LIKE:DotNetRuntimeDebugHeader

c# can export stdcall api by UnmanagedCallersOnly,but vb.net can't do this,how can you fix?
or i can use
public function add_export_stdcall(a as long,b as long) as long
return a+b
end function

aot will auto set add_export_stdcall to export as :add

`public static class MyFunctions
{
[UnmanagedCallersOnly(EntryPoint = "Add")]
public static int Add(int a, int b)
{
return a + b;
}

[UnmanagedCallersOnly(EntryPoint = "PrintString")]
public static void PrintString(IntPtr str)
{
    Console.WriteLine(Marshal.PtrToStringAnsi(str));
}

[UnmanagedCallersOnly(EntryPoint = "GetSystemInfoWrite")]
public static void GetSystemInfo()
{
    Console.WriteLine($"ProcessorCount: {Environment.ProcessorCount}");
    Console.WriteLine($"MachineName: {Environment.MachineName}");
}

}`

API Proposal

namespace System.Collections.Generic;

public class MyFancyCollection<T> : IEnumerable<T>
{
    public void Fancy(T item);
}

API Usage

// Fancy the value
var c = new MyFancyCollection<int>();
c.Fancy(42);

// Getting the values out
foreach (var v in c)
    Console.WriteLine(v);

Alternative Designs

No response

Risks

No response

Author: xiaoyaocode163
Assignees: -
Labels:

api-suggestion, untriaged, area-NativeAOT-coreclr

Milestone: -

@am11
Copy link
Member

am11 commented Dec 17, 2023

I assume this is because UnmanagedCallersOnly is not CLS complaint: #40461. VB compiler gives error BC37316: 'UnmanagedCallersOnly' attribute is not supported :(

Bad workaround: manually inject attribute in IL using reflection etc.
Better workaround: use C# project to expose your API with <ProjectReference Include="path\to\your.vbproj" /> in csproj.

@jkotas
Copy link
Member

jkotas commented Dec 17, 2023

It is by design that Visual Basic cannot do everything that C# can do. .NET language strategy explains our approach in more detail.

use C# project to expose your API

Yes, this is the right solution.

@jkotas jkotas closed this as completed Dec 17, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 17, 2023
@jkotas jkotas added the question Answer questions and provide assistance, not an issue with source code or documentation. label Dec 17, 2023
@teo-tsirpanis teo-tsirpanis closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2023
@MichalStrehovsky
Copy link
Member

Cc @dotnet/interop-contrib - UnamangedCallersOnlyAttribute cannot be used with VB due to the non-CLS compliant constructor

@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-NativeAOT-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
Archived in project
Development

No branches or pull requests

5 participants