Visual C++ :: CString Class In Non-MFC Static Library
Sep 13, 2013
I have a non-MFC static library which I share between a number of different projects, some non-MFC and some MFC. Currently the static library uses a typedef of std::wstring and std::string for UNICODE and non-UNICODE builds.
After discovering it's possible to use CString in non-MFC applications, by including atlstr.h header, I decided I'd rather that than using stl strings and having to keep converting between the different types. However, I seem to be struggling with linker errors when linking the library with a MFC application.
Can I create a non-MFC static library using CString from atlstr.h and link it with a MFC application?
I've been reading about libraries; How to make them, how to use them, the different types of libraries, etc..
When using a shared library, does the program require that library to be installed on the computer after the program has been compiled into an .exe?
Ie.. if somebody downloaded a "Helloworld.exe" that I had compiled on my computer using a shared library (that wasn't part of a standard operating system), would they also need that shared library on their computer for the program to run without errors?
and for Static Libraries, when I compile a program using a static library, does it include in the final binary only the functions of the library that are actually used, or does the compiler add in the entire library?
I have a class having static member.I have get and set methods which will Get and Set Values to this variable. In a multithreaded application does it have any thread safety issues.
Class a { static int b; void Set (int c); int Get(); };
A static function can be called in relation to a particular object by a statement such as the following:
aBox.Afunction(10);
The function has no access to the non-static members of aBox. The same function could also be called without reference to an object. In this case, the statement would be:
CBox::Afunction(10);
where CBox is the class name. Using the class name and the scope resolution operator tells the compiler to which class Afunction() belongs."
I am trying to refresh my memory here as I did some studies many years ago but the results elude me.Also todays c/c++ compilers may have better optimizations.Say I have a static library that includes three obj modules.Each of these object modules has a number of functions. These functions do not reference any other functions within the obj module.My main app links this library but only references one function from each of the object modules.
Question: Are the complete contents of each module linked into my main app or are todays linkers smart enough to just link the functions used?
How to create standalone program. For now I have simple program connecting to MySql Database and when i run it, shows me error, libmysql.dll is missing... When i put libmysql.dll in same folder works. Now my question is, how in code blocks can i compile so i won't require libmysql.dll anymore and be able to use it on any machine.
I have a libcx3d.a which contains my VrmlParser class and other classes which are used by VrmlParser. I have a main.cpp which does this :
VrmlParser vp = new VrmlParser(); double **VOB = vp.getVOB();
When I compile using g++ main.cpp -o main -L. -lcx3d, I get the following errors :
'VrmlParser' was not declared in this scope. expected ';' before vp. 'vp' was not declared in this scope.
There is a header file called "VrmlParser.h" in the static library. Should I include this header file in main.cpp ? If so, will include "VrmlParser.h" work ? I have the .a and .cpp in the same directory. I can't find the header file for the static library.
I have written a program that uses boost in visual studio 2012. The only boost library I used is filesystem by doing.
1)Properties->Linker->General and adding the path or the .lib to the additional dependencies. The libraries, link at compile time.However when i move the exe to a different computer, it doesn't work. Therefore the libraries were dynamically not statically linked. So my question is how do I statically link the filesystem library, so that i can include boost/filesystem.hpp in visual studio 2012?
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.
There is a file compressor called FreeArc (that has GPL code) and a sub project called Unarc (meant for file extraction only) that is free for any use.
Their source codes can be downloaded from here: [URL] ....
Unarc has a makefile for making a dll. I am trying to make it static instead (.a file), using MinGW, but am failing.
If I use the .o files compiled by the makefile to make one .a file, the decompression methods don't seem to be recognized as they should, so I can't extract anything. These decompression methods are added through static functions called withing the .cpp files of each method, so I guess their code is not being executed.
1. Is that mean that Do() is only available for use by Dog itself because Dog is 'oryginal' Dog, and if i create new dogs - instances of oryginal Dog (dog1, dog2 ...) they cant access because Do is only available fo 'oryginal' one? Is that correct thinking?
2. If i would want to have something common (e.g value) for all dogs is that good way to create static field/method for Dog instead of non-static once then all instances of Dog would access Dog static member to get/change it? Just stupid example: static method GetAmountOfLegs() which return 4 Then all instances can take/call that value from Dog. Is that correct thinking?
Why would the following line of code cause an exception and how can I fix it? This is with Visual Studio 2013 and it is set to use "Multibyte Character Set". This is a very old program that I was updating.
Code: thepath = dadir + "*.csv";
Both dadir and thepath are type CString.
Prior to this line dadir looks fine when I look at it in the debugger but when I reach this line of code I get
First-chance exception at 0x0FA08EE1 (mfc120d.dll) in GAQUtilities2014.exe: 0xC0000005: Access violation reading location 0xFEFEFFC6.
How do I detect garbage chars in a CString. Actually I'm reading some data from COM port. In some certain condition it will give some garbage as a version no. Now I need to show _T("N/A") in case of there is any garbage.
My solution is to check for a Valid char or integer. If found its correct else Garbage.
But the output rows are not aligned as shown in the attached picture. There a two problems.
1. Data rows don't align with the header row. 2. When the first element of a row changes to two digits, the other elements are shifted.
According to MSDN [URL] ...., CString::Format() works the same way as printf(). I wrote a small program using printf() to do the same thing, and the output in the console are perfectly aligned.
I've been trying for more than one month to access a method found in a library called libcocosnas_static.a. I'm using Cocos2d-X version 2.0.4. The library has been used many times by my company to make games using cocos2d-1.0.1-x-0.12.0 without any problem.
This is what I've done: 1- I added the include paths of the library to both eclipse and Android.mk 2- Included the .h file using #include "NASPlatformUtil.h" 3- Added the libcocosnas_static.a file to the proj.androidobjlocalarmeabi folder 4- Added "LOCAL_WHOLE_STATIC_LIBRARIES += cocosnas_static" to the Android.mk file 5- Called the function using: NASPlatformUtil:: openUrl("http://xxx.xxx.com/");
I can right click on the function, click Open Declaration and get it without any problem, but the compiler keeps on giving me that dreaded error...
I want to use CPLEX library in c++. The variables of this library can not be defined as poitners (because it does not work so). Therefore, I had to define them statically as follows:
IloEnv env_; IloModel model_(env_); ...
As class IloModel has not defult constructor, the env_ variable should be passed in the definition.
Now, I want to define class Solver which uses cplex. How can I define env_ and model_ as the members of Solver? If I define them statically as follows:
Class Solver { IloEnv env_; IloModel model_(env_); }
There will be a compile error with defining model_. On the other hand, it is not possible to define Solver as follows and "new" it in the constructor:
I have a class containing a map member that I want to initialize at declaration time. I know I can do it in the cpp file but I'm having a problem with the order of initialization (static initialization order fiasco).
My questions are:
Is it possible that the scenario in which, the Test's constructor's implementation and the map initialization instruction are in the same cpp file and constructor is called when the map is not initialized yet, could happen?
Is it possible to initialize the map in class like I did? I get these errors:
in-class initialization of static data member 'std::map<std::basic_string<char>, Test*> Test::a' of incomplete type temporary of non-literal type 'std::map<std::basic_string<char>, Test*>' in a constant expression
If yes, does this initialization resolve the static initialization order fiasco?
class Test { public: static std::map<std::string, Test*> a = {};//this is an error Test(std::string ID) {