C中模块之间的变量共享 [英] Variable sharing between Modules in C

查看:125
本文介绍了C中模块之间的变量共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TheForgers的Win32教程作为WinAPI的起点...无论如何,我将源代码分解为模块以使其易于编写:

I am using TheForgers'' Win32 Tutorial as a starting point to the WinAPI... Anyways I broke the source down into modules to make it easier to write:

main.c          =    WinMain and Main Window Procedure
MDIChdProc.c    =    MDI Child Proc


我需要在这两个模块之间共享主窗口句柄的句柄,但是我不确定如何...任何帮助将不胜感激...

我需要分享的句柄是:


I need to share the handle of the Main Window Handle between these two modules but I am not really sure how... Any help would be greatly Appreciated...

The handle I need to share is:

HWND g_hMainWindow;

推荐答案

也许我们可以使用普通的外部变量.值,并在创建主窗口后更新它)作为main.c中的全局变量,并在MDIChdProc.h中将其声明为extern HWND g_hMainWindow;.
May be we can use normal extern variables.Defining HWND g_hMainWindow=NULL;(NULL value is inialisation value and it will be updated after the main window is created) as global variable in main.c and declaring it as extern HWND g_hMainWindow; in MDIChdProc.h.


这篇关于C中模块之间的变量共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆