You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if we could get an example of using native marshalling with a ref parameter. The current examples only handle in and return examples.
I was playing around with the new feature and decided to use dbghelp.dll's SymGetModuleInfo64 as an example. I wrote the custom marshaller and I am able to run it (below is the generated code), but it throws an AccessViolationException when the result of ConvertToManaged is assigned back to the ref. Does the ref parameter need special handling?
publicunsafepartialclassTest{[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator","7.0.10.26716")][System.Runtime.CompilerServices.SkipLocalsInitAttribute]privatestaticpartialboolSymGetModuleInfo64(ninthProcess,longModuleBase64,refglobal::Test.Test.IMAGEHELP_MODULE64imgHelpModule){int__lastError;global::Test.Test.IMAGEHELP_MODULE64_Marshaller.Unmanaged__imgHelpModule_native;bool__retVal;int__retVal_native;// Marshal - Convert managed data to native data.__imgHelpModule_native=global::Test.Test.IMAGEHELP_MODULE64_Marshaller.ConvertToUnmanaged(imgHelpModule);{System.Runtime.InteropServices.Marshal.SetLastSystemError(0);__retVal_native=__PInvoke(hProcess,ModuleBase64,&__imgHelpModule_native);__lastError=System.Runtime.InteropServices.Marshal.GetLastSystemError();}// Unmarshal - Convert native data to managed data.__retVal=__retVal_native!=0;-----> imgHelpModule=global::Test.Test.IMAGEHELP_MODULE64_Marshaller.ConvertToManaged(__imgHelpModule_native);System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);return__retVal;// Local P/Invoke[System.Runtime.InteropServices.DllImportAttribute("dbghelp.dll",EntryPoint="SymGetModuleInfo64",ExactSpelling=true)]staticexternunsafeint__PInvoke(ninthProcess,longModuleBase64,global::Test.Test.IMAGEHELP_MODULE64_Marshaller.Unmanaged*imgHelpModule);}}
Target framework
Check the .NET target framework(s) being used, and include the version number(s).
.NET Core
.NET Framework 9.0.100-preview.7.24407.12
.NET Standard
About VS info
Microsoft Visual Studio Community 2022Version 17.10.5VisualStudio.17.Release/17.10.5+35122.118Microsoft .NET FrameworkVersion 4.8.09037Installed Version: CommunityVisual C++ 2022 00482-90000-00000-AA361Microsoft Visual C++ 2022Azure App Service Tools v3.0.0 17.10.344.38934Azure App Service Tools v3.0.0C# Tools 4.10.0-3.24324.8+04fb39164c99c519832109f21b22630bc9246fceC# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.Microsoft JVM Debugger 1.0Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual MachinesNuGet Package Manager 6.10.2NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/Visual Basic Tools 4.10.0-3.24324.8+04fb39164c99c519832109f21b22630bc9246fceVisual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.Visual F# Tools 17.10.0-beta.24228.1+dd749058c91585e9b5dae62b0f8df892429ee28fMicrosoft Visual F# Tools
The text was updated successfully, but these errors were encountered:
The issue was my Unmanaged struct was not fully fleshed out so was too small, which caused it to mess up the stack on the way out. Refs work just fine.
Issue description
It would be great if we could get an example of using native marshalling with a ref parameter. The current examples only handle in and return examples.
I was playing around with the new feature and decided to use
dbghelp.dll
'sSymGetModuleInfo64
as an example. I wrote the custom marshaller and I am able to run it (below is the generated code), but it throws an AccessViolationException when the result ofConvertToManaged
is assigned back to the ref. Does the ref parameter need special handling?Target framework
Check the .NET target framework(s) being used, and include the version number(s).
About VS info
The text was updated successfully, but these errors were encountered: