[SOURCE DOWNLOAD]
Indispensable Windows Native (1)-C language: Hello C
Webabcd
Introduced
Essential C language of Windows Native
- To call C + + in Windows Store Apps
- Hello C
Example
1. Demonstrates how to call C + + in Windows Store Apps (C #) and need to create a new Windows Runtime Component (c + +) project
Nativedll/simple.h
/**. h header File*///ensure that the header file is compiled only once (even if it is referenced multiple times, it is compiled only once)#pragmaOncenamespaceNativedll//name Space{ Public ref classSimpleSealed //class { Public: intADD (intXinty);//Method };}
Nativedll/simple.cpp
/**. CPP Implementation FILE * * To support Windows Runtime Component this way, so introduce Microsoft created the Visual C + + Component extensions (c++/c X), which can be thought of as a bridge between the "caller" and "C + +", the metadata is Windows metadata (. winmd) files * In order for the caller to invoke Windows Runtime Component, C++/CX will have its own Some of the data types, such as the string is platform::string^ type, so that the "caller" call * for knowledge about C++/CX, see:https://msdn.microsoft.com/en-us/library/hh755822.aspx */#include"pch.h" //Precompiled Header File#include"Simple.h" //header files that need to be implemented//namespaces defined in the header fileusing namespaceNativedll;//implementing methods in the header fileintSimple::add (intXinty) { returnX +y;}
Nativedemo/simple.xaml.cs
/** Demonstrates how to call C + + in C # * * Corresponding Windows Runtime Component (c + +) See Nativedll Project * Note: The Windows Runtime Component project generates. WINMD Files, Winmd-windows Metadata, which are language-independent*/usingWindows.UI.Xaml.Controls;usingWindows.UI.Xaml.Navigation;namespacenativedemo.demo{ Public Sealed Partial classSimple:page { PublicSimple () { This. InitializeComponent (); } protected Override voidonnavigatedto (NavigationEventArgs e) {//calling a function in C + +Nativedll.simple simple =Newnativedll.simple (); intresult = simple. ADD (1,1); Lblmsg.text="1 + 1 ="+result. ToString (); } }}
Readme.txt
1, in order to use the C language, you need to select the corresponding. c file, right-click Properties, and so on, compile to C + + code (/TP) 2, for example, if you want to use strcpy, in VS, the police Sue you, ask you to use strcpy_s, but strcpy_s is Microsoft's own, in order to remove this warning can do: a) defined at the beginning of the file #define _crt_secure_no_warnings B) or once and for all: DLL project, right-click Properties, C + +, preprocessor, add "_crt_secure_no_warnings" to "Preprocessor definition" 3, Debug Local code: Select Solution, Debugger Type-----Properties----------debug----"mixed (managed and native)" 4, how to create a new C code with the default Save as Utf-8 format: in similar D:\Program Files (x86) \microsoft Vis UAL Studio 12.0\vc\vcprojectitems directory under Modify template file "Hfile.h" and "newc++file.cpp" file format utf-8
2. Hello C
CHello.h
//c. h file//header files are typically used for placement: macro definitions that need to be exposed, global variable declarations, function declarations//prevent two compilations of the same file. For example, you have two C files, both C files include the same header file, at compile time, these two C files will be compiled together, then brought a declaration of conflict issues#ifndef _myhead_hello_//is the abbreviation for if not defined, and if not defined _myhead_hello_ executes this piece#define_myhead_hello_//define _myhead_hello_//write C language code in C + +#ifdef __cplusplus//if the current C + + environmentextern "C" //tell C + + that the C code is written in the {} block below{#endif //function Declaration Char*demo_chello (Char*name); #ifdef __cplusplus//if the current C + + environment}#endif/*//In Windows environment, can be shortened to such #ifdef __cplusplusextern "C" #endifchar *demo_chello (char *name);*/#endif //#ifndef _myhead_hello_
Chello.c
/** Hello C*/#include"pch.h" //Precompiled Header File#include"cHello.h" //Introducing header files that need to be implemented#include"CHelper.h" //the header file that introduces the custom functionChar*demo_chello (Char*name) { returnSTR_CONCAT2 ("Hello:", name);}//This demo does not show the main function, so here are some textual explanations of the main function//The main function is an entry function and cannot be called by another function//assuming the command is: executable file name parameter 1 parameter 2 parameter 3intMainintargcChar*argv[])//The main function can also be no parameter, no return value, that is: int main (void) {} or void main (void) {} are all possible{ //ARGC is the number of arguments; argv is the parameter value//argc-equals 4 (Note: "Executable file name" also counts as a parameter)//argv[0]-executable file name; argv[1]-parameter 1; argv[2]-parameter 2; argv[3]-Parameter 3//return 0 for normal return 0; }
Ok
[SOURCE DOWNLOAD]
Indispensable Windows Native (1)-C language: Hello C