惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - verygis

C++/CLI 本地字符串和托管字符串之间的转换 DWF Toolkit on Microsoft Windows Visual studio 2017 c++ wcout 无法输出中文 Javascript 技巧集(1) win10 下 gulp-sass 无法使用的解决 VS2010 下 将 EntityFramework 的版本从 4.0 升级到 5.0 [原]CentOS 6.5 上安装 MySQL 5.6 Filezilla 适用于 Win2003 和 WinXP 的版本 Bower 自定义组件文件夹名称 [原]JQuery mobile CSS 文件组织 [转]Django与遗留系统和数据库集成 [转]mysql在windows下支持表名大小写,lower_case_table_names [转]Installing python 2.7 on centos 6.3. Follow this sequence exactly for centos machine only [转]理解android.intent.category.LAUNCHER 具体作用 [转]如何判断某版本的.NET Framework是否安装 Google V8 源码下载及构建环境 关于网络字节序(network byte order)和主机字节序(host byte order) 宏 UNUSED_PARAM 的作用 [转]在C#中使用IDL文件,IDL是个接口定义文件
[转]Convert Windows TCHAR argv list to classical char * argv
verygis · 2012-09-04 · via 博客园 - verygis

http://www.wincli.com/?p=72

Many people used to classical C have hard time adopting the code to Windows types. The code below illustrates one of the frequent questions: how to use TCHAR arguments with good old code expecting char * in arguments with minimum blood?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

#include "stdafx.h"

#include "stdio.h"

#include "stdlib.h"

int wstrlen(_TCHAR * wstr)

{

    int l_idx = 0;

    while (((char*)wstr)[l_idx]!=0) l_idx+=2;

    return l_idx;

}

char * wstrdup(_TCHAR * wSrc)

{

    int l_idx=0;

    int l_len = wstrlen(wSrc);

    char * l_nstr = (char*)malloc(l_len);

    if (l_nstr) {

        do {

           l_nstr[l_idx] = (char)wSrc[l_idx];

           l_idx++;

        } while ((char)wSrc[l_idx]!=0);

    }

    nstr[l_idx] = 0;

    return l_nstr;

}

char ** allocate_argn (int argc, _TCHAR* argv[])

{

    char ** l_argn = (char **)malloc(argc * sizeof(char*));

    for (int idx=0; idx<argc; idx++) {

        l_argn[idx] = wstrdup(argv[idx]);

    }

    return l_argn;

}

void release_argn(int argc, char ** nargv)

{

    for (int idx=0; idx<argc; idx++) {

        free(nargv[idx]);

    }

    free(nargv);

}

int _tmain(int argc, _TCHAR* argv[])

{

    char ** argn = allocate_argn(argc, argv);

    if (argc>1) {

            printf(“Arg 1 = ‘%s’\n”, argn[1]);

    }

    release_argn(argc, argn);

    return 0;

}