Click here to Skip to main content
15,894,343 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: unit test Pin
lucy17-Aug-06 6:09
lucy17-Aug-06 6:09 
GeneralRe: unit test Pin
Waldermort17-Aug-06 6:26
Waldermort17-Aug-06 6:26 
QuestionCRT string macros Pin
Waldermort17-Aug-06 5:17
Waldermort17-Aug-06 5:17 
AnswerRe: CRT string macros Pin
Waldermort17-Aug-06 6:03
Waldermort17-Aug-06 6:03 
GeneralRe: CRT string macros Pin
Zac Howland17-Aug-06 6:07
Zac Howland17-Aug-06 6:07 
GeneralRe: CRT string macros Pin
Michael Dunn17-Aug-06 13:21
sitebuilderMichael Dunn17-Aug-06 13:21 
Questionpost build event in makefile Pin
rana7417-Aug-06 5:11
rana7417-Aug-06 5:11 
QuestionMultiByteToWide does not work without printf??? Pin
fvandun17-Aug-06 5:02
fvandun17-Aug-06 5:02 
Hello,


I have a program that takes a command line argument and then converts it to a unicode string (with MultiByteToWide) for use in NetLocalGroupEnum (not shown in the program extract below).

The strange thing is that when I have a printf (line 18 below) at the start of the program, it seems to work fine (It prints the converted string).
But when I remove the printf the string conversion is not correct anymore. I must be doing something wrong with 'sizeof' or with the MultiByteToWideChar function.



01 #pragma comment( lib, "netapi32.lib" )
02 #include <stdio.h>
03
04 #include <stdlib.h>
05 //#include <string.h>
06 #include <windows.h>
07 #include <atl\atlbase.h>
08
09 #include <lmcons.h>
10 #include <lmaccess.h>
11 #include <lm.h>
12 #include <sddl.h>
13
14 int main(int argc, char** argv)
15 {
16 char buf[256];
17
18 //printf("Test\n\n");
19
20 if (argc < 2) {
21 printf("Usage:lgenum2 <servername>");
22 exit(EXIT_FAILURE);
23 }
24
25 LPWSTR servername = new WCHAR[sizeof(argv[1])+1];
26
27 MultiByteToWideChar (
28 CP_ACP, // code page
29 0, // performance and mapping flags
30 (char *) argv[1], // address of character string
31 -1, // number of characters in string
32 servername, // address of buffer for new string
33 wcslen(servername) // size of buffer
34 );
35
36 wprintf(L"Multibyte to Widechar:%s\n",servername);
37 printf("-------\n\n");
38 exit(EXIT_SUCCESS);
39 }


Thanks for any help
Francis
AnswerRe: MultiByteToWide does not work without printf??? Pin
Zac Howland17-Aug-06 5:14
Zac Howland17-Aug-06 5:14 
GeneralRe: MultiByteToWide does not work without printf??? Pin
fvandun17-Aug-06 5:29
fvandun17-Aug-06 5:29 
GeneralRe: MultiByteToWide does not work without printf??? Pin
Zac Howland17-Aug-06 5:41
Zac Howland17-Aug-06 5:41 
GeneralRe: MultiByteToWide does not work without printf??? Pin
fvandun17-Aug-06 5:55
fvandun17-Aug-06 5:55 
GeneralRe: MultiByteToWide does not work without printf??? Pin
Zac Howland17-Aug-06 5:58
Zac Howland17-Aug-06 5:58 
GeneralRe: MultiByteToWide does not work without printf??? Pin
fvandun17-Aug-06 6:07
fvandun17-Aug-06 6:07 
QuestionLimited Users Pin
Dave Kerr17-Aug-06 4:58
Dave Kerr17-Aug-06 4:58 
QuestionMicrosoft Access Database Import to VC++ Windows Forms Pin
Nokoff17-Aug-06 4:56
Nokoff17-Aug-06 4:56 
AnswerRe: Microsoft Access Database Import to VC++ Windows Forms Pin
cje17-Aug-06 5:15
cje17-Aug-06 5:15 
QuestionWindows Directory Pin
si_6917-Aug-06 4:49
si_6917-Aug-06 4:49 
AnswerRe: Windows Directory Pin
Dave Kerr17-Aug-06 4:56
Dave Kerr17-Aug-06 4:56 
GeneralRe: Windows Directory Pin
Michael Dunn17-Aug-06 13:23
sitebuilderMichael Dunn17-Aug-06 13:23 
AnswerRe: Windows Directory Pin
Hamid_RT17-Aug-06 6:32
Hamid_RT17-Aug-06 6:32 
AnswerRe: Windows Directory Pin
G_S17-Aug-06 13:29
G_S17-Aug-06 13:29 
QuestionUsing Spy++ in Visual Studio 2003 Pin
Jethro6317-Aug-06 4:40
Jethro6317-Aug-06 4:40 
AnswerRe: Using Spy++ in Visual Studio 2003 Pin
G_S17-Aug-06 4:53
G_S17-Aug-06 4:53 
GeneralRe: Using Spy++ in Visual Studio 2003 Pin
Jethro6317-Aug-06 7:35
Jethro6317-Aug-06 7:35 

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.