9 Replies
$ask
How to get the best help
Make a post in #help or one of the topic channels under Development.
Avoid asking Can anybody help Has anyone used Why doesn't my code work?
C# is a big area! No one knows they can help unless you tell them about the small area you're trying to work in.
Explain what you are doing, and potentially why for as much context as possible. Avoid screenshots where possible, share code directly in Discord. Type
$code
into chat to learn how to post code.
See https://www.nohello.net and https://dontasktoask.com if you want common help chat room etiquette.just call
CoTaskMemFree
on that buffer?
which api are you using that you need to do this?(which, for what it's worth, is already available as https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.freecotaskmem?view=net-7.0)
Marshal.FreeCoTaskMem(IntPtr) Method (System.Runtime.InteropServices)
Frees a block of memory allocated by the unmanaged COM task memory allocator.
my code right now looks like this:
Marshal.FreeCoTaskMem dosn't accept the pointer to pwstr directly it seems, and trying to use CoTaskMemFree itself results in an access violation
sorry for posting such a half-baked question
you don't pass the pointer to PWSTR to CoTaskMemFree
you pass PWSTR itself
Marshal.FreeCoTaskMem((nint)pwstr);
this complains about not being able to cast
(nint)pwstr.Value
?that worked, thanks a ton