473,796 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extern question

I am trying to create a message box that allows you to enter a name
then display that name on a window. The program uses win32 but that is
not the issue. I want have a global buf variable. So that it can be
filled in the window then displayed in the main window.

Here is what I have

char * buf = NULL; //In my min program.

extern char * buf; // This is the section where I want buf displayed.

extern char * buf; //This is where I fill the array.
buf = new char[len];
GetDlgItemText( hwnd, IDC_NAME_EDIT, buf, len +1);
I have used extern before and it had made my progam possible but does
it work with a pointer?

Jun 6 '06 #1
2 2035

"JoeC" <en*****@yahoo. com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
I am trying to create a message box that allows you to enter a name
then display that name on a window. The program uses win32 but that is
not the issue. I want have a global buf variable. So that it can be
filled in the window then displayed in the main window.

Here is what I have

char * buf = NULL; //In my min program.

extern char * buf; // This is the section where I want buf displayed.

extern char * buf; //This is where I fill the array.
buf = new char[len];
GetDlgItemText( hwnd, IDC_NAME_EDIT, buf, len +1);
I have used extern before and it had made my progam possible but does
it work with a pointer?

Yes, a pointer is just like any other variable. You can have a global
pointer and set the value of the pointer to whatever you want in another
module. That module has to have a extern declaration for the pointer. As a
general rule I have one extern declaration in one header and one definition
in one c/c++ file.

Not all globals are bad but whether you should use a global in this
particular case is a different question.

Andrew
Jun 6 '06 #2

andrew queisser wrote:
"JoeC" <en*****@yahoo. com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
I am trying to create a message box that allows you to enter a name
then display that name on a window. The program uses win32 but that is
not the issue. I want have a global buf variable. So that it can be
filled in the window then displayed in the main window.

Here is what I have

char * buf = NULL; //In my min program.

extern char * buf; // This is the section where I want buf displayed.

extern char * buf; //This is where I fill the array.
buf = new char[len];
GetDlgItemText( hwnd, IDC_NAME_EDIT, buf, len +1);
I have used extern before and it had made my progam possible but does
it work with a pointer?

Yes, a pointer is just like any other variable. You can have a global
pointer and set the value of the pointer to whatever you want in another
module. That module has to have a extern declaration for the pointer. As a
general rule I have one extern declaration in one header and one definition
in one c/c++ file.

Not all globals are bad but whether you should use a global in this
particular case is a different question.

Andrew


At first it didn't work and now it does.

Jun 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2595
by: John Ratliff | last post by:
I have a few global variables in my app. They are defined in the main application class file and declared (extern) in a header which can be included by anyone who would want to use these variables. Two of the globals are pointers which are initialized at runtime. The others are classes whose values are initialized in the global space. When I had just the pointers, I didn't need to include the extern header in the defining class file. But...
10
6200
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: // main.cpp // This is defined in a C module extern "C" void fake_qsort(void*, std::size_t, std::size_t, int (*compare)(const void*, const void*));
12
2730
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external linkage? Not much on this in the FAQ or tutorials.
29
448
by: DevarajA | last post by:
Can anyone explain me what extern is used for? I thought it was used to declare variables definited in other files, but i can do that also without extern. /*file a.c*/ int a=5; int main() { f(); }
5
16609
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining extern storage class: /****************************************************************** SOURCE FILE ONE *******************************************************************/ extern int i; /* Reference to i, defined below */
7
3484
by: MikeF | last post by:
Group, I have a variable declared in 'main.c' as: const unsigned int x = 1; I have another module which uses this same variable, I've tried to declare as:
5
2860
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
7
2198
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
7
3537
by: blangela | last post by:
I am currently taking a course and one of the example programs showed a function prototype something like: extern void func(); I asked why the "extern" was necessary. Someone in the class (not the instructor) explained that if the same function prototype is used in more than one source file in a project, that the linker will complain.
0
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.