473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 2008

"JoeC" <en*****@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.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.googlegr oups.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
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....
10
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: //...
12
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...
29
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() {...
5
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...
7
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
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
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
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.