microsoft / microsoft/win32metadata

Friendly overload for `CommandLineToArgv()` returns a `PWSTR*` instead of something like a `LocalFreeSafeHandle`.

Open
#2,161 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
C++
Stars
1.5k
Forks
149
Avg merge
5d 16h
Merged PRs (30d)
4

Description

## Actual behavior

The signature for the friendly `CommandLineToArgv()` function is `public static unsafe winmdroot.Foundation.PWSTR* CommandLineToArgv(string lpCmdLine, out int pNumArgs)`, however the memory that's pointed to in the returned value is something that the caller must free.

> CommandLineToArgvW allocates a block of contiguous memory for pointers to the argument strings, and for the argument strings themselves; the calling application must free the memory used by the argument list when it is no longer needed. To free the memory, use a single call to the [LocalFree](https://learn.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-localfree) function.

## Expected behavior

That the signature for the friendly `CommandLineToArgv()` function be something like `public static unsafe LocalFreeSafeHandle CommandLineToArgv(string lpCmdLine, out int pNumArgs)` so that this is somewhat managed for the caller.

## Repro steps

1. `NativeMethods.txt` content:
```
CommandLineToArgv
```

2. `NativeMethods.json` content (if present):
N/A

3. Any of your own code that should be shared?
4. N/A

### Context

- CsWin32 version: 0.3.248
- Win32Metadata version (if explicitly set by project):
- Target Framework: net472
- `LangVersion` (if explicitly set by project): N/A

Contributor guide

Open the contributing guide

Research direction

Start with the NativeMethods.txt repro containing CommandLineToArgv and inspect the generated friendly overload. Compare its returned type and ownership behavior with the issue's LocalFreeSafeHandle expectation, then verify the generated signature and cleanup path for the net472 scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.