May be a bit off-topic, but you can also consider using the win32api-specific TCHAR data type instead of char/w_char, along with the _T() / TEXT() macro, and use the win32api generic string functions. This simplifies things and makes your programs "unicode ready" (just #define _UNICODE and UNICODE before anything else) .
For example...
#include <tchar.h>
...
#define my_strncpy _tcsncpy // generic win32api function for strncpy (I'm just defining a more familiar name for it)
#define MAX_BUF (255+1)
...
TCHAR *ptrstrold = NULL;
TCHAR strnew[ MAX_BUF] = {TEXT('\0')}; // this makes sure strnew is padded with 0s
...
// read old text
if ( NULL == (ptrstrold = malloc(MAX_BUF * sizeof(TCHAR)) )
// handle failure here
if ( 0 == GetDlgItemText(hDlg, Unit_Static, ptrstrold , MAX_BUF) )
// handle failure here
free( ptrstrold );
// assign new text
my_strncpy( strnew, TEXT("I'm the new string"), MAX_BUF-1 ); // padded initialization comes handy here
if ( 0 == SetDlgItemText(hDlg, Unit_Static, strnew) )
// handle failure here
...
EDIT:
Lots of typos!