C++ :: Setup Global Variables
Feb 23, 2015
I am using VS2010 to develop an app which includes several windows forms that I am trying to set up global variables for, and I am getting a few errors like:
LNK2005: "wchar_t *dsn"...already defined in ....obj
I have a header file (externals.h) with:
#ifndef MY_GLOBALS_H
#define MY_GLOBALS_H
extern long dbg;
extern wchar_t dsn[50];
extern wchar_t u[30];
extern wchar_t p[30];
#endif
and 2 different forms, each with different namespaces, but both including the above header (#include "externals.h").One of the form .h files defines the values for these externally declared variables like this: namespace PWValidationTools{
wchar_t dsn[50] =_T("MDOTProjectWise");
wchar_t u[30]=_T("api_admin");
wchar_t p[30]=_T("proce55");
long dbg = 1;
public ref class ValidationSetupForm : public System::Windows::Forms::Form {
}
The other form file only uses these variables, never defines them.I am getting the above LNK2005 error only for the variables declared as wchar_t, not the "long" one. why I'm getting the link errors only for the wchar_t variables.
View 1 Replies
ADVERTISEMENT
Oct 15, 2014
I have made an application and I have basically solved everything. But the only problem is that I am using global variables because it felt like the smoothest, so my program is built on it.
But now I've read around and I understand that you should not use these(?). Do you think pointers is the best think to use instead?I have previously declared my board array and some variables as global and I want them in alot of functions.I have read and understand the procedure for the use of pointers so I can use my int's in the other functions by doing like this? Code: #include <stdio.h>
int justprint();
int main()
{
int Row = 2;
int Column = 2;
int *pRow = &Row;
int *pColumn = &Column;
[code]...
But how do I do it with an array like this one? If I declare it in the main function, and then want to use it in other functions.Or are there better, easier solutions?
Code: char game[3][3]={{0,0}};
View 13 Replies
View Related
Jun 25, 2013
On linux, I can compile DLLs (shared objects) as well as executables that use them. I can even access globals and classes that are defined in the EXE from the DLL, and vice versa, simply with the 'export' keyword. flawlessly.
The Problem: But on Windows (using MinGW), no matter what I do, I'm completely unable to access global variables which defined in the EXE, from the DLL. On Linux, this is no sweat, but what's Windows' problem?
I also need to extend classes in the dll with base class method definitions defined in the exe.
Ive heard that on Windows, you need to use declspec(dllimport) and declspec(dllexport). I can compile with CygWin+MinGW/g++4.5.3 as well as "Pure Windows" with MinGW/g++4.7.2 *without* the declspecs. So what's the decljunk for? Is this really just something for MSVC or other compilers?
Here's some Windows code to show what the problem is. The DLL's global variable is accessible to the EXE just fine, but the EXE's global variable is not accessible to the DLL - compilation complains it is an undefined reference.
main.cpp
#include "myLib.h"
#include <stdio.h>
int exe;
[Code].....
edit: I tried using --enable-runtime-pseudo-reloc --allow-shlib-undefined options when compiling the DLL and G++ complains that --allow-shlib-undefined is an unrecognized option.
View 1 Replies
View Related
Jan 19, 2014
I am trying to get variables that are global to multiple files. I have mananged to make constant variables that are global but maybe not in the best way. In the header i have the constant variables being defined:
const int variable_Name = 5;
And the cpp file:
#include <iostream>
using namespace std;
#include "vars.h"
int main ( ) {
cout << variable_Name<< endl;
system ("pause");
return 0;
}
Is there a better way to do this and to make the variables able to be changed within the cpp files.
View 7 Replies
View Related
Jul 22, 2014
Is it possible to use & change global variables in a Static Library? For example:
I declare a
bool test = true;
globally.
Then later in an exported function If the user wants, he can set that test to false. So the program later when checks test if it's true, will notice that it's not true, since one of my function changed it.
Is it right?
View 3 Replies
View Related
Nov 6, 2013
I have a main thread and a worker thread. How do i pass data between them when both are already running without using global variables?
View 1 Replies
View Related
Sep 22, 2013
I realize that implicit int rule was removed in C99 but gcc still takes this approach by default. I wonder why this happens:
bbb = 5; // legal
int main(void) {
aaa = 10; // illegal
auto aaa = 10 // legal
Inside function a specifier is needed. Error message with no specifier used is:
error: ‘aaa’ undeclared (first use in this function)
Is this because of linkage - bbb variable has an external linkage so compiler knows that we are defining a variable here while inside mean() we need to show compiler that aaa is defined right here, it does not come from external functions?
View 4 Replies
View Related
Mar 10, 2014
I came across the following code today and I was a bit surprised that it worked:-
Code:
std::string func_A () {
static std::string x;
if (!x.empty())
return x;
[Code] ....
I've simplified things slightly - but the basic point is that both functions are in the same source file and they both have a static std::string called 'x'. Being static, I guess they aren't (strictly) local variables. So how does the compiler know that they're different entities? Does it encode their signatures using the function name or something like that? If I call each function separately I do seem to get the correct string...
View 5 Replies
View Related
Sep 18, 2013
I am trying to compile a c program for sudoku. I have declare const instances as global variables, but when i try to compile the code it says that my declarations are not constant, here is some of the code.
#include <stdio.h>
#include <assert.h>
const int GRIDSIZE = 3;
const int GRID_SQUARED = GRIDSIZE * GRIDSIZE; //this line
const int ALL_VALUES = (1<<GRID_SQUARED)-1; //and this give//the error
int board [GRID_SQUARED][GRID_SQUARED];
View 3 Replies
View Related
Mar 7, 2014
I developed one windows application in c#.net , this application is not working when i installed the setup in another system with another sql database server-r2. How can solve this. here i had attached my code for reference.
App.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SqlCon" value="Data Source=.sqlexpress;Initial Catalog=aathi;Integrated Security=True;Pooling=False"/>
</appSettings>
</configuration>
[Code] ....
View 3 Replies
View Related
Apr 20, 2013
i want make a setup for C# program with SQL data base but i can not . i use installshield but i have error in connection to database in execution program.
View 32 Replies
View Related
Dec 28, 2013
All day long I tried figuring out how to setup VOCE [URL] ....
I am using VS 2010.
What I did:
* Downloaded JDK
* Downloaded the VOCE, extracted and put in c:
* Opened VS and in properties->Vc++ Direcotories:
* In Include Directories i added: C:voce-0.9.1srcc++, C:Program * FilesJavajdk1.7.0_45include, C:Program FilesJavajdk1.7.0_45includewin32
* In Library Directories i added: C:voce-0.9.1lib, C:Program * FilesJavajdk1.7.0_45lib
ALSO: I didn't get what i suppose to do with C:voce-0.9.1lib everything there * is winrars
Tried to compile a sample file and it gives me the error:
Testing.obj : error LNK2001: unresolved external symbol _imp_JNI_CreateJavaVM@12
View 14 Replies
View Related
Apr 22, 2014
I am having trouble getting the cout statements that I commented out to work properly. And I can't figure out why the first movie in the movies.txt file displays at the end of the list in my output screen when it should only display once as the first item. I am also having trouble figuring out where and how to set up the static variable.
Purpose : This assignment requires that you to develop a program using the classes listed above. Specifically you will build a hash table containing movie data. The collision strategy will be to build linked lists as the array elements.
Program Specifications : Your program will read the data from the file named Movies.txt located in the StudentFiles1.zip file on the Connections Portal. Each record contains 2 fields separated by a space. They are:
FieldsData Type
Motion Picture Association Code (MPAC)Integer
Movie NameString
Your application program will read each record, create a Movie structure instance and place that structure instance into the hash table.
You will need to modify the appropriate code to provide for an audit trail of the hash table construction. To accomplish this, you will use cout statements in the above class member functions. You will need to modify them to include couts, but the modifications will be relatively small. If not, you are doing it wrong. The hashing algorithm to use is:
Index = int ( 0.618033 * MPAC) % size
Make the array size a constant and set it to 10.
Include a counter for the number of collisions that occurred in building the hash table. Including a static variable in the LinkedList or List class is the best method for doing that.
See the sample audit trail below for the first 5 records on Movies.txt and the size of the hash table set to 3. This is shown for illustration only. The full file will have different locations calculated.
1101-Casablanca is being added
The hashed location is 2
There was no collision loading 1101-Casablanca
------------------------------------------------
1200-Duck Soup is being added
The hashed location is 0
There was no collision loading 1200-Duck Soup
------------------------------------------------
[Code] ....
After the above is displayed, prompt the user to enter the MPAC of a movie to locate. Produce an audit trail when locating the requested movie as shown below: Make sure you list all movies that have collided at the hashed location. That may also cause you to modify one of the existing ADTs a little.
Will search for 6601
at the hashed location is 2
There was a collision here with 6601-Wizard of Oz
There was a collision here with 1101-Casablanca
retrieved from hash table: 6601-Wizard of Oz
[Code] ....
View 10 Replies
View Related
Jan 18, 2013
if (choice ==1){
Light *myobj = new Light();
}
FlipUpCommand switchUp(*myobj);
Error: `myobj' undeclared (first use this function)
How to solve this problem without changing the Light class.
View 4 Replies
View Related
Jun 23, 2014
I created a WinForm app in C# using VS 2013 Express.
I added code to create a Global Hot Key on the main form. This works fine. My hot key is Ctrl-T. I can press the hot key and make the main form show and hide.
Then I created a second form (ChecklistForm) and now I want to press ctrl-T and make that form show and hide. I do not need the main form to do this any more. I just used the main form to test my Global Hot Key code.
So I'm having trouble getting the second form to respond to the hot key. When I put a break on the WndProc(), there is no break.
namespace ChecklistFSX {
public partial class MainForm : Form {
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String AppName);
private IntPtr thisWindow;
private GlobalHotKeys hotkey;
public MainForm()
[code]....
View 2 Replies
View Related
Feb 29, 2012
Let's say I've got something like this:
struct Box{
//something
};
typedef struct Box* pBox;
[Code]....
function fun recieves the address(which is NULL) and then allocates the memory for the Box; Let's say I cannot return the address of new allocated p and I can't also use that pointer p(from main) without passing it into a function.
Q: How can I make it that I could operate in function "fun" as I operate on orginal pointer p(from main), right now I'm just passing the address to my function but I can't change the 'global' pointer p ;(.
I remember in pascal it's like:
"function(var pointer:[pointer to sth])"
and all is done.
View 14 Replies
View Related
Jan 18, 2013
if (choice ==1){
Light *myobj = new Light();
}
FlipUpCommand switchUp(*myobj);
Error: `myobj' undeclared (first use this function)
How to solve this problem without changing the Light class.
View 9 Replies
View Related
Dec 19, 2013
Expected output: 20
But what I got is: 22
Why. While calling sub function it should take the global variable am I right
insert Code:
#include <iostream>
using namespace std;
int a=0;
void sub()
[Code] ....
View 3 Replies
View Related
Jul 16, 2013
I am having trouble updating my global pointer in the following code,
Code:
#include <iostream>
using namespace std;
struct RB{
RB()=default;
RB(int clr):color(clr) { }
int color;
[Code] ....
The problem is, at line where I compar y==Tnil, It is evaluating to false at the first insert. But It should be true. again, after ending the function, T again becomes equal Tnil, as a result , none of the is being inserted.
View 2 Replies
View Related
Apr 20, 2013
Okay so I am programming an 8051 variant to interact with an SD card. In a separate initialization routine in SD_CARD.c I pull out the vital information of the card into global variables. I then call Menu() which is in another source file but includes a header file with all of the variables declared as extern. Now here is the weird, part this is from my Menu.c
printf("%u" , VOLUME_1_SECTOR);
if(VOLUME_1_SECTOR==16384)
printf("Correct");
else
printf("Incorrect");
Now the output of the first printf is 16384 but the conditional evaluates to false. If I put this code in SD_CARD.c (Where VOLUME_1_SECTOR is defined) the conditional evaluates to true. I am confused why the printf works correctly in Menu.c but not the conditional.
View 2 Replies
View Related
Sep 7, 2013
The problem that I want to make an array " vertextDegree [nbColours] " with " nbColours " elements in it ,but the "nbColours" unknown and I have to get it get it from a file .
Code:
int nbEdges,nbVetices, nbColours ;
typedef struct st_graphVertex {
int index;
int colour;
int val ;
int vertexDegree[nbColours]; // it won't work because nbColours unknown
// here and I want get it from file in the main
struct st_graphVertex *next;
t_edgeList *out;
}t_grapheVertex;
View 3 Replies
View Related
Jan 22, 2015
I want to declare a global array and then use it in a few functions. When I want to assign any number to that array I face with this error:
Code:
a.c:11:6: error: expected expression before ']' token
n[]={1,2,3,4,5};
^
The code is:
#include <stdio.h>
int n[5]; // I need to define the array here to be global
int main () {
n[]={1,2,3,4,5};
[Code] .....
View 6 Replies
View Related
Sep 30, 2014
I want to make a destructor counter...So it needs to be outside that specific instance of the class. And i want to keep it hidden. I don't want to be able to access it from outside the class...I Don't want main.cpp to have access to this variable
Is there a way to do this?
static int destructorCount;
View 8 Replies
View Related
Jul 28, 2013
I have a small problem with my program. It is kinda a mess but I will try to explain you what I am trying to do. I have some threads. One of it, it attempts to detect a game client. So my code is sort of like that:
DWORD ProcessID; // The process ID of the game client
void test() {
char* text;
[Code]....
So basically, its like the variable changes, but only inside the thread... why does that happen?
View 15 Replies
View Related
Sep 14, 2013
I am making a class called "bigint" and i have to have a global constant "size". How do I make that global "size" the size of bigint? If "size" is an array and "bigint" is an object how does that work? Heres the instructions for the program..
Requirements:
-You must use the class construct to implement your ADT.
-The ADT bigint need only work for positive numbers.
-Use a global constant value for the maximum size of the bigint that is, a constant sized array.
Implementation:
-The size of the bigint must be specified by a global constant
-A method (constructor) to initialize a bigint to zero.
-A method (constructor) to initialize a bigint to an int value you provide [0, maxint]. Example: bigint(128).
-A method (constructor) to initialize a bigint to a char[] you provide. You can assume what is provided is a valid bigint. Example: bigint("299793").
-A method to write a bigint that prints at most 60 digits per line.
-A method to compare if two bigints are equal. It should return a bool - true if equal and false otherwise.
View 6 Replies
View Related
Apr 28, 2015
I am getting this error while trying to compile my program:
It says that my variables "nome, cognome, eta..etc" are being used for the first time in my "inserisci" function.
I tought that I could just declare them as global in my structure like I did in my code, but apparently this doesn't work.
Do I really need to declare them again outside of my structure? Isn't there another way?
Here is my code:
#include <stdio.h>
#include "readline.h"
void inserisci(void);
struct impiegato{
char nome[20];
char cognome[20];
int eta;
[code].....
View 7 Replies
View Related