The cause of the access violation is the improper casting of &workingDword to a (PDWORD_PTR). In an x64 build a DWORD_PTR is a 64-bit value. The workingDword variable should be a DWORD_PTR, not a DWORD.
Also, the call will allocate memory that must be freed with NetApiBufferFree and return that address in the pBytes variable. The call to malloc is not needed.
DWORD dwentriesread{}, dwtotalentries{};
DWORD_PTR resumehandle{};
LPBYTE pbuf{};
auto ret = NetLocalGroupEnum(
NULL, // servername
0, // level
&pbuf, // bufptr
MAX_PREFERRED_LENGTH, // prefmaxlen
&dwentriesread, // entries read
&dwtotalentries, // total entries
&resumehandle // resume handle
);
if (ret == NERR_Success)
{
printf_s("Entries read: %u, total entries: %u\n", dwentriesread, dwtotalentries);
for (ULONG i = 0; i < dwentriesread; i++)
{
LOCALGROUP_INFO_0 lgi = ((PLOCALGROUP_INFO_0)pbuf)[i];
printf_s("Group name: %ls\n", lgi.lgrpi0_name);
}
}
else
{
printf_s("NetLocalGroupEnum returned %u\n", ret);
}
if (pbuf)
NetApiBufferFree(pbuf);