Question: Export function with out parameter
See original GitHub issueHi, I’m trying to migrate code that previously used DllExport
so it could be used by InnoSetup.
Previously I had
[MarshalAs(UnmanagedType.LPWStr)] string input, [MarshalAs(UnmanagedType.BStr)] out string output
I can’t make an out IntPtr
though
[UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvStdcall) })]
public static void ReturnString(IntPtr value, out IntPtr result)
{
var message = Marshal.PtrToStringUni(value);
_ = NativeMethods.MsgBox(IntPtr.Zero, message, ":)", 0);
result = Marshal.StringToBSTR("???");
}
This required for interaction with Pascal/Delphi, where the return value is passed as parameter by reference when using stdcall
: https://stackoverflow.com/a/9353800/4503491
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
javascript - Exporting multiple functions with arguments
All I am trying to do is to export two functions from a module. One function taking an argument and the other with...
Read more >Is there a way to export functions with parameters already ...
My first thought was copying the value of PARAMETER to a parameter with a unique name, like my_func_PARAMETER . This would most likely...
Read more >Out Parameter With Examples in C# - ...
The out parameter is allowed to use var type in the method parameter list. In out parameter, it is not compulsory that the...
Read more >I want to create a function module but
EXPORTING parameters are output parameters. When the function module is called, a suitable actual parameter can be specified for every output parameter.
Read more >Testing Non-Exported Functions in JavaScript
To test exported function, you can simply import it. But what about non-exported functions? Well that's easy too, thanks to Rewire!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@CoenraadS This is a bit questionable if your previous API was using
out IntPtr
. Instead this should be:The default for x86 on Windows is
stdcall
but on non-Windows it iscdecl
.When you say “on top of”, I assume you mean to say that the method
UnmanagedCallersOnly
calls a method that uses the C# keyword - this is fine. If this isn’t the case, please elaborate.