Click here to Skip to main content
15,893,663 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: System Query Pin
Randor 28-Dec-11 11:11
professional Randor 28-Dec-11 11:11 
GeneralRe: System Query Pin
john563227-Dec-11 20:27
john563227-Dec-11 20:27 
GeneralRe: System Query Pin
Randor 28-Dec-11 11:08
professional Randor 28-Dec-11 11:08 
GeneralRe: System Query Pin
john563229-Dec-11 18:23
john563229-Dec-11 18:23 
GeneralRe: System Query Pin
Randor 29-Dec-11 18:47
professional Randor 29-Dec-11 18:47 
GeneralRe: System Query Pin
john563229-Dec-11 20:29
john563229-Dec-11 20:29 
GeneralRe: System Query Pin
Randor 29-Dec-11 21:57
professional Randor 29-Dec-11 21:57 
QuestionJoining 2 values with wcsncat_s Pin
jkirkerx26-Dec-11 10:52
professionaljkirkerx26-Dec-11 10:52 
I'm having trouble with cating 2 values together, one of the buffers is not null terminated.

So I made a buffer to a pointer, that I passed to a function.

C#
// Make a copy of the new Server Name
int iNSN = wcslen(pzAddServerName)*sizeof(WCHAR);
szAddServerName = new WCHAR[iNSN+1];
wcsncpy_s(szAddServerName, iNSN, pzAddServerName, wcslen(pzAddServerName) );


I learned that the wcsncpy will automatically null terminate the szAddServerName, which is a copy of the pointer, which is not null terminated.

I then made a copy of the master list, with a new buffer, and assumed that the wcsncpy will null terminate the buffer. I added extra space for the new name and the delimiter plus null terminator.

C#
// Make a copy of the registry values
int iASN = wcslen(pzEnumeratedServerNames)+wcslen(szAddServerName);
szNewServerNames = new WCHAR[iASN+4];
wcsncpy_s(szNewServerNames, iASN, pzEnumeratedServerNames, wcslen(pzEnumeratedServerNames) );


And then if the new name is not in the list of names, tried to cat it to the list of names.

C#
if (pzMatch == NULL) {
// one of these is not null terminated
wcsncat_s(szNewServerNames, wcslen(szNewServerNames), szAddServerName, wcslen(szAddServerName) );
}


I know that I can walk through the code to figure out which one is not null terminated, but I really need to get a rock solid rule in my head, to avoid this in the future, where I just do it right the first time.
AnswerRe: Joining 2 values with wcsncat_s Pin
Chris Losinger26-Dec-11 10:59
professionalChris Losinger26-Dec-11 10:59 
GeneralRe: Joining 2 values with wcsncat_s Pin
jkirkerx26-Dec-11 11:13
professionaljkirkerx26-Dec-11 11:13 
QuestionNetwork Utilization Pin
john563225-Dec-11 22:13
john563225-Dec-11 22:13 
AnswerRe: Network Utilization Pin
Richard MacCutchan26-Dec-11 6:57
mveRichard MacCutchan26-Dec-11 6:57 
AnswerRe: Network Utilization Pin
Randor 26-Dec-11 12:17
professional Randor 26-Dec-11 12:17 
QuestionDetect keypress count Pin
juver escolta23-Dec-11 6:04
juver escolta23-Dec-11 6:04 
AnswerRe: Detect keypress count Pin
CPallini23-Dec-11 7:34
mveCPallini23-Dec-11 7:34 
AnswerRe: Detect keypress count Pin
Luc Pattyn24-Dec-11 2:21
sitebuilderLuc Pattyn24-Dec-11 2:21 
GeneralRe: Detect keypress count Pin
CPallini24-Dec-11 3:59
mveCPallini24-Dec-11 3:59 
AnswerRe: Detect keypress count Pin
Luc Pattyn24-Dec-11 4:06
sitebuilderLuc Pattyn24-Dec-11 4:06 
GeneralRe: Detect keypress count Pin
CPallini24-Dec-11 4:42
mveCPallini24-Dec-11 4:42 
QuestionRe: Detect keypress count Pin
David Crow23-Dec-11 9:28
David Crow23-Dec-11 9:28 
AnswerRe: Detect keypress count Pin
Gary R. Wheeler23-Dec-11 23:56
Gary R. Wheeler23-Dec-11 23:56 
AnswerRe: Detect keypress count Pin
Lactoferrin24-Dec-11 1:45
Lactoferrin24-Dec-11 1:45 
AnswerRe: Detect keypress count Pin
Software_Developer24-Dec-11 4:54
Software_Developer24-Dec-11 4:54 
QuestionHow GetObjectSchema() to work ? Pin
André Dewispelaere23-Dec-11 3:43
André Dewispelaere23-Dec-11 3:43 
AnswerRe: How GetObjectSchema() to work ? Pin
Mohibur Rashid26-Dec-11 22:13
professionalMohibur Rashid26-Dec-11 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.