Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[C++] Unicode functions

Featured Replies

Hi all,

I wrote some c++ code to do some user management using the netapi32 library. I use certain functions such as NetLocalGroupAddMembers that requires the groupname to be a LPCWSTR. The variable I have for the groupname is a TCHAR and I need to convert it to a WCHAR* at runtime but am having some difficulty with it.

I was trying to use the MultiByteToWideChar function to get the required size, allocate the appropriate memory and then convert the groupname (group) to a WCHAR* (wGroup). But when calling MultiByteToWideChar the second time during execution, I get an application error. 'The instruction at "0x77f536f7" referenced memory at "0x5c740000". The memory could not be "written".

Below is the code in which I try to do this. Can anyone help me to get this working? Thanks.

iReqSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char*)group, -1, wGroup, 0);
if ( (wGroup = (WCHAR*)LocalAlloc(LPTR, iReqSize)) == NULL)
{
_tprintf(_T("\nUnable to add user to administrators group."));
if (bDebug) _tprintf(_T("..Error allocating memory for group name"));
LocalFree(wUser); wUser = NULL;
return ERROR_SET_GROUP;
}
if ( (MultiByteToWideChar(CP_ACP, 0, (char*)group, -1, wGroup, iReqSize)) == 0)
{
_tprintf(_T("\nUnable to add user to administrators group."));
if (bDebug) _tprintf(_T("..Error converting group name to unicode: %d"), GetLastError());
LocalFree(wUser); wUser = NULL;
LocalFree(wGroup); wGroup = NULL;
return ERROR_SET_GROUP;
}
NetLocalGroupAddMembers(NULL, wGroup, 3, (LPBYTE) &luser, 1);


  • Author

Well I decided to use the ATL macros (T2W) and that worked fine.

Problem solved. :thumbup

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.