extern

#ifdef,#else,#endif,#if 拾忆

最后都变了- 提交于 2020-01-10 04:01:39
预处理就是在进行编译的第一遍词法扫描和语法分析之前所作的工作。说白了,就是对源文件进行编译前,先对预处理部分进行处理,然后对处理后的代码进行编译。这样做的好处是,经过处理后的代码,将会变的很精短。 关于预处理命令中的文件包含(#i nclude),宏定义(#define),书上已经有了详细的说明,在这里就不详述了。这里主要是对条件编译(#ifdef,#else,#endif,#if等)进行说明。以下分3种情况: 1:情况1: #ifdef _XXXX ...程序段1... #else ...程序段2... #endif 这表明如果标识符_XXXX已被#define命令定义过则对程序段1进行编译;否则对程序段2进行编译。 例: #define NUM ............. ............. ............. #ifdef NUM printf("之前NUM有过定义啦!:) \n"); #else printf("之前NUM没有过定义!:( \n"); #endif } 如果程序开头有#define NUM这行,即NUM有定义,碰到下面#ifdef NUM的时候,当然执行第一个printf。否则第二个printf将被执行。 我认为,用这种,可以很方便的开启/关闭整个程序的某项特定功能。 2:情况2: #ifndef _XXXX ...程序段1... #else

C语言中的extern变量

人盡茶涼 提交于 2020-01-09 22:45:20
C语言中的extern变量 extern变量是全局变量的扩充。 全局(global)变量 在任何一个函数之外声明的变量就是全局变量,全局变量可以被声明所在文件中的任何一个函数调用。全局变量只可以被定义一次。 int globalVar globalVar定义为全局变量时,默认初值为0,并且系统为之分配相应的内存。现在,定义该变量的文件中的任意一个函数可以调用它。 extern变量 假如你想要调用另外一个文件中的全局变量,如果你再声明一个同名的全局变量,那么编译器会因为重名报错,这个时候就要使用extern变量。 extern int globalVar extern声明告诉编译器这个变量的定义在其他文件中,所以并不会为它分配内存。 例子 #main.c #include<stdlib.h> #include<stdio.h> #include"test.h" int a; /* global variable */ int main(int argc, char** argv) { a = 10; func(); return 0; } #test.h extern int a int func(); # test.c #include"test.h" #include"stdio.h" int func() { printf("value of a is %d", a ); }

CEF截图

≡放荡痞女 提交于 2020-01-08 19:40:45
记录目前两种实现方式 [DllImport("user32.dll")] private static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, uint nFlags); public void WriteBmp(string bmpPath) { int screenWidth = webbrowser.Document.Body.ScrollRectangle.Width; int screenHeight = webbrowser.Document.Body.ScrollRectangle.Height; IntPtr myIntptr = webbrowser.Handle; int hwndInt = myIntptr.ToInt32(); IntPtr hwnd = myIntptr; // Set hdc to the bitmap Bitmap bm = new Bitmap(screenWidth, screenHeight); Graphics g = Graphics.FromImage(bm); IntPtr hdc = g.GetHdc(); // Snapshot the WebBrowser bool result = PrintWindow(hwnd, hdc, 0); g

EXE和DLL调用关系,DLL制作,钩子

随声附和 提交于 2020-01-08 12:23:16
制作DLL时,在cpp种引入了头文件,但头文件里的全局变量在cpp种却不能用 参考大佬博客 https://blog.csdn.net/speargod/article/details/88854344 制作DLL DLL种包含 SetGlobalHook(设置钩子函数) UnsetGlobalHook(卸载钩子函数) GetMsgProc(钩子回调函数) 1、新建DLL空项目,我选的不到导出项的,导出项我们自己写,建好后是这样 2、右键源文件-》添加项-》添加cpp源文件 3、右键头文件-》添加项-》添加h头文件 4、在GH.cpp种写我们的函数实体 #include "GH.h" //这里包含了三个头文件,打开头文件菜单,把里面的都包含进去即可 #include "pch.h" #include "framework.h" LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam); //这三个不仅在头文件中需要写,在源文件中也需要写,这一定注意!!! extern "C" __declspec(dllexport) BOOL SetGlobalHook(); //用作声明函数 extern "C" __declspec(dllexport) BOOL UnsetGlobalHook(); HHOOK

Windows API

家住魔仙堡 提交于 2020-01-06 14:20:29
Windows API Windows 这个多作业系统除了协调应用程序的执行、分配内存、管理资源之外, 它同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务就是一个函数),可以帮应用程式达到开启视窗、描绘图形、使用周边设备等目的,由于这些函数服务的对象是应用程序(Application), 所以便称之为 Application Programming Interface,简称 API 函数。WIN32 API也就是Microsoft Windows 32位平台的应用程序编程接口。 C#调用Windows API C#调用Windows API之调用格式,在.Net Framework SDK文档中是比较零散。但在C#中使用Windows API最常见的方式是用DllImport 来进行处理,并 使用 C# 关键字 static 和 extern 声明方法 。 [DllImport("kernel32")] public static extern void GetWindowsDirectory(StringBuilder WinDir,int count);  上述代码中,DllImport属性用来从不可控代码中调用一个方法,它指定了DLL的位置,该DLL中包含调用的外部方法: kernel32设定了类库名 public指明函数的访问类型为公有的

C++ Standard regarding external linkage and calling conventions

浪子不回头ぞ 提交于 2020-01-06 07:46:05
问题 I've read the last C++11 draft (n3337 - is it the last one?), and I got a question for a possible implementation I've been working on. Let's say we have this code: extern "Objective C" { class Object { public: static Object *alloc(); Object *init(); }; }; Then calling Object *x = Object::alloc()->init(); The question is that I didn't understand if it is allowed for the compiler to control the calling convention of extern "X" blocks: the idea would be to "translate" the calls to objc_msgSend

Getting LINK error : Extern in C++. How to access the value of a variable which is modified in File A.CPP in another file File B.CPP

不羁的心 提交于 2020-01-05 19:49:05
问题 IN my C++ code I want to make use of a variable "VarX" in a file "B" which is actually modified in another file "A". So I had a look @ the following link & used extern concept. How do I use extern to share variables between source files? error LNK2005: "unsigned int VarX" (?VarX@@3IA) already defined in ***.obj. My scenario is as follows: File1.h extern unsigned int VarX; File2.cpp #include File1.h unsigned int VarX = 101; File3.cpp #include File1.h unsigned int temp = VarX; IMP NOTE: In the

Getting LINK error : Extern in C++. How to access the value of a variable which is modified in File A.CPP in another file File B.CPP

荒凉一梦 提交于 2020-01-05 19:48:09
问题 IN my C++ code I want to make use of a variable "VarX" in a file "B" which is actually modified in another file "A". So I had a look @ the following link & used extern concept. How do I use extern to share variables between source files? error LNK2005: "unsigned int VarX" (?VarX@@3IA) already defined in ***.obj. My scenario is as follows: File1.h extern unsigned int VarX; File2.cpp #include File1.h unsigned int VarX = 101; File3.cpp #include File1.h unsigned int temp = VarX; IMP NOTE: In the

Doubt related to extern keyword usage

断了今生、忘了曾经 提交于 2020-01-05 12:18:36
问题 AFAIK, extern keyword should be used for declaration and no value can be associated with the variable being declared with extern keyword. But supposing I write a statement like extern int i = 10; Should the compiler flag an error for the same? I have seen some compilers being tolerant and ignoring this? Why is this so? What does the 'C' standard says about this? EDIT: @All, Thanks for the answers. I have a doubt still though. Suppose I have the definition for this variable without the extern