question_id int64 25 74.7M | answer_id int64 332 74.7M | title stringlengths 20 150 | question stringlengths 23 4.1k | answer stringlengths 20 4.1k |
|---|---|---|---|---|
2,066,477 | 2,066,592 | RtlpNtMakeTemporaryKey - VerySleepy indicates that this takes a lot of time | I'm profiling some computationally intensive code of mine, and was surprised to see that the function RtlpNtMakeTemporaryKey takes up a huge chunk of time. It's module is ntdll and the source file is Unknown. Is this a call which is waiting for my slow function to terminate or is it something which I can optimize?
| Are you sure you have symbols for ntdll? It's possible that you don't, and RtlpNtMakeTemporaryKey is just the closet exported symbol name that your debugger can see to the real function or functions that are taking up so much time.
But yeah, you should focus on your code and who/why you're calling into ntdll so much.
|
2,066,863 | 2,066,902 | compiling a program to run in DOS mode | I write a simple program, to run in DOS mode. Everything works under emulated console in Win XP / Vista / Seven, but not in DOS. The error says: this program caonnot be run in DOS mode. I wonder is that a problem with compiler flags or something bigger.
For programming i use Code::Blocks v 8.02 with such settings for c... | From the sound of things, you're currently compiling a Windows console program. Even though it's a console program, it still needs Windows to run.
To compile a program to run on real DOS, you'll need to find a (probably really old) compiler and (especially) linker that targets DOS and can produce DOS MZ executables. Th... |
2,066,906 | 2,067,015 | How are objects of subclasses allocated in C++? | I have confusion about the concept of inheritance in C++, suppose we have a class named computer and we publicly inherit a class named laptop from computer class. Now when we create an object of class laptop in main function what happens in the memory? Please Explain.
| I'm assuming that Laptop inherits from Computer, and am explaining what happens in general; the implementation details of C++ (for optimization reasons) may differ from this general explanation.
Logically, the Laptop class definition has a pointer to the Computer class definition. An instance of Laptop class has a poin... |
2,066,965 | 2,082,634 | Is it possible to troubleshoot C# COM Interface Implementations? | I have a C# implementation of a C++ COM Interface. I have ported the IDL (Interface) as accurately as I can.
When the C++ app instantiates my object it successfully calls one of the methods. It then tries to call another of the methods but nothing happens. The second call's execution path never makes it to the C# side... | After solving my compatibility issue, I discovered that The C++ dll doesn't expose the interface items I was expecting. Although this question was aimed at how to debug or compare the exposed interfaces of the 2 dlls, I got my project working by using the [ComImport] attribute on the C# interfaces I was implementing r... |
2,067,111 | 2,067,395 | Moving objects on screen by per pixel basis with glRasterPos() | I have the following code to render text in my app, first i get the mouse coordinates in the world, then use those coordinates to place my text in the world, so it will follow my mouse position:
Edit: added buildfont() function in code example:
GLvoid BuildFont(GLvoid) // Build Our Bitmap... | Here's a small snippet of code that I use to render some debug text in a small application:
void
renderText(float x, float y, const char* text) {
int viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(viewport[0], viewport[2]... |
2,067,196 | 2,114,690 | Using fstream tellg to read a portion of the stream till the end | I have this simple code that needs to get a chunk of a large log file that is being written into. At some point it stores the current location returned from
streampos start = istream::tellg();
method.
Later on the code has to read from the stream a buffer from the start till the end. The code is approximately like thi... | http://groups.google.com/group/comp.lang.c++/browse_thread/thread/709cde3942e64d6c#
|
2,067,310 | 2,292,607 | How to communicate between Rhapsody models in different processes/systems? | We are using IBM (formerly Telelogic) Rhapsody for a new project to do model driven development of a complex device. The device consists of several subsystems that are connected by various network interfaces. We'd like to model the entire system in Rhapsody and then generate code separately for the various subsystems.
... | You can implement your own version of the Rhapsody MessageQueue class and rebuild the oxf library using your code instead of the default code.
|
2,067,349 | 2,067,364 | simulate socket errors | How to simulate socket errors? (sometimes server or client disconnects because of some socket error and it is impossible to reproduce.)
I was looking for a tool to do this, but I can't find one.
Does anyone know either of a tool or has a code example on how to do this? (C# or C/C++)
| Add a wrapper layer to the APIs you're using to access the sockets and have them fail rand() % 100 > x percent of the time.
|
2,067,392 | 2,067,416 | pthread vs NSThread: which is faster | In Cocoa, is NSThread faster than pthread? is are any performance gain? is it negligible to ignore?
| I have no data to back this up, but I'm going to go out on a limb and say "they're equivalent". NSThread is almost certainly wrapper around pthread (is there really any other way to create a system thread?), so any overhead of using NSThread versus pthread would be that associated with creating a new object and then d... |
2,067,433 | 2,067,692 | Convert MYSQL Timestamp to time_t | I'm writing a multi-threaded program that needs to be able to check if a row requires updating and act accordingly.
I had problems using the built in date/time functions of MySql and so decided to just store the "lastupdate" timestamp as an integer in the table. However, I'm having problems converting this timestamp t... | The MySql timestamp data type can be stored as a number in either YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD, or YYMMDD format.
In Unix and POSIX-compliant systems, time_t is typically an integer which represents the number of seconds since the start of the Unix epoch: midnight UTC of January 1, 1970.
In MySQL you can use... |
2,067,436 | 2,067,470 | Sequential Key Generation | Right now, I'm working on a project which requires sequential text key generation. I need to seed the key generator with an integer corresponding to a certain key, which the constructor converts to a key.
My key generator overloads the increment operators so that the string is incremented directly, rather than what I h... | You could store a vector of the same length as your key, where each element in the vector was the index in the charset of the corresponding character in the key.
For example, if key[0] was 'c', then thisVector[0] would be 2, since 'c' is the 3rd character in the character set.
Then all operations would be performed on... |
2,067,457 | 2,067,492 | CComModule UnregisterServer error? | I have a CComModule that is calling RegisterServer (TRUE) on DllRegisterServer and UnregisterServer (TRUE) on DllUnregisterServer. The UnregisterServer is getting a 0x8002801C (Error accessing the OLE registry.) error and leaving around registery keys. I am using a Windows Server 2k8 R2 machine with UAC enabled. The co... | You must run Regsvr32.exe from a command prompt that's elevated to administrator (i.e. UAC disabled). Make a shortcut on your desktop to "cmd.exe", right-click it and choose "Run as Administrator".
|
2,067,479 | 2,067,505 | Is there any reason that the STL does not provide functions to return an iterator via index? | Is there a reason that the STL does not provide functions to return an iterator into a container via an index?
For example, let's say I wanted to insert an element into a std::list but at the nth position. It appears that I have to retrieve an iterator via something like begin() and add n to that iterator. I'm thinking... | You can use advance() from the <iterator> header:
list<foo>::iterator iter = advance(someFooList.begin(), n);
list<foo>::iterator iter = someFooList.begin();
std::advance( iter, n);
If the iterator supports random access (like vector) it'll work quite efficiently, if it only supports increasing (or decreasing) the ... |
2,067,497 | 2,078,506 | How to programmatically move Windows taskbar? | I'd like to know any sort of API or workaround (e.g., script or registry) to move (or resize) Windows taskbar to another position including another monitor (if dual monitors). Definitely, we can move task bar by using mouse, but I want to move it by a program, or a sort of automated way.
I tried to find Win32 API, but ... | As far as I can tell, Vista and onwards ignore any program trying to move the taskbar. The old method was ABM_SETPOS + MoveWindow, and this no longer works on the taskbar. The only way that I am aware of that still works is simulating a mouse move (click-move-release). I've read about that method, but I've never done i... |
2,067,814 | 2,067,826 | Apache mod_c++ wanted? | I want to experiment a bit with C++ as a server side language. I'm not looking for a framework, and simply want to achieve a silly old "Hello World" webapp using C++.
Is there an Apache HTTP server module that I can install?
If i can do the PHP equivalent of :
<?php
$personName = "Peter Pan";
echo "Hello " . $... | cgi would do this. Just have your C++ app spit its output to stdout and your mod_cgi will handle it
|
2,067,833 | 2,067,856 | What could be generating the compiler error in this statement to advance an iterator? | The following line generates a compiler error:
std::vector<int>::iterator blah = std::advance(instructions.begin(), x );
where I have declared:
std::vector<int> instructions;
int x;
The error I get is:
error C2440: 'initializing' : cannot convert from 'void' to 'std::_Vector_iterator<_Ty,_Alloc>'.
What element of t... | Without looking this up, I'm guessing the advance function returns void, which you are assigning to blah
try: advance(blah, x);, assuming of course you've initialized blah: blah = instructions.begin();
|
2,067,846 | 2,067,968 | Windows Threads: when should you use InterlockedExchangeAdd()? | The naming of this function seems like this is some complicated stuff going on. When exactly does one know that this is the way to go instead of doing something like this:
Preparation
CRITICAL_SECTION cs;
int *p = malloc(sizeof(int)); // Allocation Site
InitializeCriticalSection(&cs); // HINT for first Writ... | InterlockedExchangeAdd is used to add a value to an integer as an atomic operation, meaning that you won't have to use a critical section. This also removes the risk of a deadlock if one of your threads throws an exception - you need to make sure that you don't keep any lock of any kind as that would prevent other thre... |
2,067,893 | 2,068,078 | C++ console keyboard events | Is there any way to get key events in a Windows console? I need a way to get keydown and keyup events quickly without a GUI. I've tried using getch(), but it doesn't get keyups and waits until a key has been pressed to return.
| You can use GetKeyState or GetAsyncKeyState, but that won't give you keydown/keyup events. It will only tell you what keys are currently down.
So if you really need to get the keydown/keyup events, you could install a hook.
A Console window has a window handle that is owned by code in Windows and a message pump, also ... |
2,067,975 | 2,068,308 | Ogre3D Basic Framework issue on Ubuntu | I have been trying to learn to use Ogre3D and have gotten to the stage where I want to start something more serious than the examples it comes with so I found and copied the Basic Ogre Framework
I am using Ubuntu 9.10, but have compiled Ogre 1.7 from the Ogre3D website, I am using the Netbeans 6.8 IDE with the c++ plug... | Have you configured the application to use the correct video drivers for your system? Since you're on ubuntu you'll need to use OpenGL. I found some drivers didn't work on some systems when using Ogre.
|
2,067,988 | 4,081,391 | Recursive lambda functions in C++11 | I am new to C++11. I am writing the following recursive lambda function, but it doesn't compile.
sum.cpp
#include <iostream>
#include <functional>
auto term = [](int a)->int {
return a*a;
};
auto next = [](int a)->int {
return ++a;
};
auto sum = [term,next,&sum](int a, int b)mutable ->int {
if(a>b)
return ... | Think about the difference between the auto version and the fully specified type version. The auto keyword infers its type from whatever it's initialized with, but what you're initializing it with needs to know what its type is (in this case, the lambda closure needs to know the types it's capturing). Something of a ... |
2,068,022 | 2,068,048 | In C++, is it safe/portable to use static member function pointer for C API callbacks? | In C++, is it safe/portable to use static member function pointer for C API callbacks? Is the ABI of a static member function the same as a C function?
| It is not safe per the C++ standard. As stated in this SO posting:
A C callback function implemented in C++ must be extern "C". It may seem to work as a static function in a class because class-static functions often use the same calling convention as a C function. However, doing that is a bug waiting to happen (see c... |
2,068,088 | 2,068,108 | C++ method only visible when object cast to base class? | It must be something specific in my code, which I can't post. But maybe someone can suggest possible causes.
Basically I have:
class CParent
{
public:
void doIt(int x);
};
class CChild : public CParent
{
public:
void doIt(int x,int y,int z);
};
CChild *pChild = ...
pChild->doIt(123); //FAILS compiler, no method ... | You have shadowed a method. For example:
struct base
{
void method(int);
void method(float);
};
struct derived : base
{
void method(int);
// base::method(int) is not visible.
// base::method(float) is not visible.
};
You can fix this with a using directive:
class derived : public base
{
using ... |
2,068,300 | 2,068,321 | Keyboard Tabbing Stops working on Windows GUI | I have a windows gui built in Microsoft Visual C++ and when the user performs a certain set of actions the keyboard tabbing to move from widget to widget stops working.
Simply put, there are two list boxes with an add and a remove buttons. Selecting a row in listbox #1 and pressing the add button removes the object fro... | If I understand correctly, you just want to set the focus back to one of the listboxes. Since this is in a dialog, instead of calling SetFocus, The Old New Thing recommends you send a message to the listbox's hWnd to do this:
void SetDialogFocus(HWND hdlg, HWND hwndControl)
{
SendMessage(hdlg, WM_NEXTDLGCTL, (WPARA... |
2,068,531 | 2,068,800 | Is It Possible To Simplify This Branch-Based Vector Math Operation? | I'm trying to achieve something like the following in C++:
class MyVector; // 3 component vector class
MyVector const kA = /* ... */;
MyVector const kB = /* ... */;
MyVector const kC = /* ... */;
MyVector const kD = /* ... */;
// I'd like to shorten the remaining lines, ideally making it readable but less code/ope... | Depending on the platform you're on, the compiler might be able to optimize statements like
result.x = (kC.x > kD.x) ? kA.x : kB.x;
result.y = (kC.y > kD.y) ? kA.y : kB.y;
result.z = (kC.z > kD.z) ? kA.z : kB.z;
using fsel (floating point select) instructions or conditional moves. Personally, I think the code looks ni... |
2,068,693 | 2,084,228 | OpenGL and GLUT in Eclipse on OS X | I have been trying to setup the OpenGL and GLUT libraries in Eclipse, with CDT, on OS X with not very much success. I cannot seem to get eclipse to actually realize where GLUT is. It is currently giving me the error that I have an unresolved inclusion GL/glut.h. Looking around online I found that I should be using the ... | Ok. I got it working in X11. The reason I could only get it working on X11 is because it seems the OpenGL libs on the OS are for the 64-bit architecture, but eclipse will only compile code if we use 32-bit architecture. Maybe if this got fixed we could use OS X pre-installed libraries. Also, maybe there is a 32-bit ... |
2,068,816 | 2,068,829 | Usefulness of const (C++) | I'm a const fiend, and I strive to make everything as const as possible.
I've tried looking at various dissassembly outputs from const and non const versions of functions, and I've yet to see a marked improvement however. I'm assuming compilers nowadays are able to do smart things with non const functions that could t... | As far as I know, the only effect of marking a function const is to allow the function to be called on a const object. There's no optimization benefit.
Herb Sutter has an article which discusses const and optimization in depth:
http://www.gotw.ca/gotw/081.htm
The one area that const is useful at the machine level is ... |
2,068,916 | 2,068,935 | Coding Linux console application in Visual C++ 2008/2010 Express | I was told about the fascination of C++ and I have recently downloaded Visual C++ IDE to start learning C++.
However I had this question in mind: How can I write C++ console application in Visual C++ and build it for Linux and Windows? Is there any plugin, additional compilers or hacks to go around with?
| The most important thing is you want to avoid OS specific calls and stick with the standard C++ library.
If you don't include any Windows header file such as windows.h or winuser.h, then the compiler will warn you if you try to call a Windows specific function.
There are some features available on both Windows and Linu... |
2,068,969 | 2,069,031 | Template deduction and function pointers | How does the compiler know the correct type for this code:
class Base
{
protected:
typedef View * ViewType;
typedef boost::function<ViewType ()> ActionType;
typedef boost::unordered_map<std::string, ActionType> ActionMapType;
ActionMapType actions;
template <class ControllerType>
inline void... | The template parameter is ControllerType which is used in the function parameter list as ViewType (ControllerType::*action)() parameter. When you supply an actual argument of ViewType (Derived::*)() type, the compiler immediately realizes that ControllerType = Derived. That's it. This is called template argument deduct... |
2,069,097 | 2,069,148 | Using Boost with Team Foundation Server | What would be a good way to use Boost in a small team (< 10 people) and lower the time between joining the team and building the application as much as possible. I basically want a workflow like this...
Set up the TFS with the new person's username + password.
Have them log into the TFS from Visual Studio.
Check out t... | Check in an already-compiled Boost into a "vendor" folder, then just point all the project refs toward that folder.
|
2,069,110 | 2,069,131 | Read a line from file, using stream style | I have a simple text file, that has following content
word1 word2
I need to read it's first line in my C++ application.
Following code works, ...
std::string result;
std::ifstream f( "file.txt" );
f >> result;
... but result variable will be equal to "word1". It should be equal to "word1 word2" (first line of text fi... | No, there isn't. Use getline(f, result) to read a line.
|
2,069,174 | 6,789,862 | Using boost test with Visual Studio | I am trying to use Boost Test to add some much needed unit tests to my code. However I can't seem to get it to work. Right now I have the following code
#include <Drawing.h>
#define BOOST_AUTO_TEST_MAIN
#define BOOST_TEST_MODULE DrawingModelTests
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(DrawingModelTe... | I had this problem with VS2010 and the solution was to set 'Configuration Properties -> Linker -> Advanced -> Entry Point' to 'main' for the project.
|
2,069,450 | 2,069,460 | How to get a "bus error"? | I am trying very hard to get a bus error.
One way is misaligned access and I have tried the examples given here and here, but no error for me - the programs execute just fine.
Is there some situation which is sure to produce a bus error?
| Bus errors can only be invoked on hardware platforms that:
Require aligned access, and
Don't compensate for an unaligned access by performing two aligned accesses and combining the results.
You probably do not have access to such a system.
|
2,069,744 | 2,069,982 | SFINAE canAdd template problem | I'm trying tow write a SFINAE template to determine whether two classes can be added together. This is mostly to better understand how SFINAE works, rather than for any particular "real world" reason.
So what I've come up with is
#include <assert.h>
struct Vec
{
Vec operator+(Vec v );
};
template<typename T1, typen... | It looks to me like you've run into the problem that's discussed in Core Issue 339 as well as N2634. The bottom line is that you're pushing a bit beyond what any compiler can currently handle, even though what you're doing is allowed by the standard. C++ 0x will add more detail about what will and won't result in SFINA... |
2,069,855 | 2,070,134 | Getting Machine's MAC Address -- Good Solution? | I've heard it's not possible with my current library of winpcap.
Is this really true? I see lots of examples on the net but then comments saying "This doesn't work".
What's the best way to get a MAC address of the local machine?
| One common method is using bits from a UUID, but this isn't entirely dependable. For example, it'll return a value even on a machine that doesn't have a network adapter.
Fortunately, there is a way that works dependably on any reasonably recent version of Windows. MSDN says it only goes back to Windows 2000, but if mem... |
2,069,949 | 2,069,987 | Compact pointer notation with doubles | Quick question. When you are accessing a character array, I know you can set the pointer to the first element in the array, and use a while look and do something like
while (*ptr != '\0') {
do something
}
Now is there a double or int equivalent?
#define ARRAY_SIZE 10
double someArray[ARRAY_SIZE] = {0};
double *... | If I understand you correctly, you want to iterate through the array and stop when *ptr has a certain value. That's not always possible. With a character array (string), a common convention is to have the string be "null-terminated"; that is, it will have a 0 byte ('\0') at the end. You can add such a sentinel to an... |
2,070,156 | 4,380,886 | Margin in popup menu (qt3) | alt text http://img130.imageshack.us/img130/6218/menuk.jpg
Is there any method to get rid of the huge margin on the right side? It appears to be constant, because adding some text to the menu items doesn't change its width at all.
| QPopupMenu is inherited from QWidget. So try function setMaximumWidth() or try to use adjustSize() after adding all items in popup menu.
|
2,070,216 | 2,070,269 | Why building the same project generates different EXE file for each developer | My team and I are developing a VC++ 6 project.
We are all using the same code-base (using version control system), and all our compiler/linker/environment-settings (including include directories order), as far as we can tell, are exactly the same.
Of course we are using the same VC++ version with the same service packs... | If Debug version has the option "Link incrementally" checked, then probably it's the reason for the diffs.
|
2,070,307 | 2,082,913 | Qt: How to connect QScriptEngineDebugger to QScriptEngine in separate thread? | I need to process script in separate, non-GUI thread since script calls C++ function that can take very long time to process (seconds). Is it possible to connect QScriptEngineDebugger to my QScriptEngine in non-gui thread?
The problem is - if I put QScriptEngineDebugger in same thread as QScriptEngine (non-gui) than de... | Unless you're prepared to write your own script debugger, there doesn't seem to be a way to run the debugger in a different thread than the engine.
Behind the scenes, QScriptEngineDebugger uses a class called QScriptEngineDebuggerFrontend, which in turn uses a class called QScriptEngineDebuggerBackend, which in turn ... |
2,070,397 | 2,073,671 | how to deal with a static analyzer output | We have started using a static analyzer (Coverity) on our code base. We were promptly stupefied by the sheer amount of warnings we received (its in the hundreds of thousands) , it will take the entire team a few months to clear them all (obliviously impossible).
the options we discussed so far are
1) hire a contract... | The first thing to do is tweak the heck out of your analysis settings; Coverity support probably left you with a fairly generic configuration.
Triage a representative sample of the defects, and if a checker doesn’t seem to be producing a lot more signal than noise, turn it off for now. (Most of Coverity’s checkers... |
2,070,567 | 2,070,665 | Object oriented programming , inheritance copy constructor | Suppose i have a base class "person". and i publically inherits a class "student " from the base class "person". i have not written the copy constructor for base and the derived class. now suppose i write in the main program
main()
{
student sobj1("name", "computer science");
student sobj2=sobj1;
}
now in the second ... | I believe the rules are following:
Constructor of base class always should be called before constructor of derived class.
You can choose which one of base class constructors will be called by calling it explicitly in initialization list.
If you do not do that, default constructor is called.
When class has no copy cons... |
2,070,740 | 2,450,314 | Drag Drop using SendMessage | This sounds funny..just a little experiment.
i wanted to simulate a drag drop of a file on a Application/Window using Send Message.
Is it possible?
I dont have code for the application but on the executable.
The application is IP Messenger.
What i wanted to do is use "Send To" functionality to send the file to an .exe ... | There is the WM_DROPFILES Message. I guess that you could use CreateToolhelp32Snapshot to locate the window that is IP Messenger and then build the DROPFILES structure to send with the WM_DROPFILES message.
The final link would be to Codeproject, with some help on creating the DROPFILES structure: How to Implement Dr... |
2,070,782 | 2,072,582 | How to speed up rotated text output in MFC | I have a MFC application that displays annotated maps, which can include a large amount of text. While the size and font of the text does not tend to change much, the rotation of the text varies considerably, in order to be aligned with the surrounding line work. This basically means that I have to do create and sele... | Creating and destroying many GDI object can be slow. What you can do is create 360 fonts at the startup of your program so that you can SelectObject() from a lookup table with pre-made fonts at the correct rotation, rather than creating them on-demand. Or you can rotate your text by not using lfEscapement but by using ... |
2,070,951 | 2,070,968 | main function does not return anything. Why? | With respect to C/C++ main() must always return an integer(zero to indicate success and non-zero to indicate failure). I can understand this as the program is run it becomes a process and every process should have an exit status, which we obtain by doing echo $? from shell after the process gets over.
Now I don't unde... | If the main method of a single threaded java application terminates, the application will terminate with exit code 0. If you need another exit code, maybe to indicate an error, you can place
System.exit(yourNumberHere);
anywhere in the code (especially outside of the main method).
This is different for multi-threaded ... |
2,071,403 | 2,071,431 | Calling a subclassed virtual method from a base class method | class A
{
public:
virtual void
doSomething(void)
{}
void
doStuff(void)
{
doSomething();
}
};
class B : public A
{
public:
void
doSomething(void)
{
// do some stuff here
}
};
B * b = new B;
b->doStuff();
It gives me Segmentation fault. What am I... | As far as I can see, you're not doing any polymorphism in the code bellow the class definition.
b->doStuff() should call the method of B class. If you want to inside B call A-> doSomething you can use A:: doSomething
|
2,071,411 | 2,071,452 | Returning from a multimap search with equal_range without being error-prone | I'm about to refactor some duplicated code. Two functions both search in a multimap using
equal_range(). In a for loop after the call to equal_range() there is a for loop that sets
an iterator to equalRange.first with the condition it != equalRange.second.
If the correct value is found, the two functions differ. What ... | Instead of an either/or decision on the return value, it sounds to me like you'd want to do what functions like map::insert do - return a std::pair<iterator, bool> to signal both the position and the success/failure of the search function.
|
2,071,449 | 2,086,314 | my_thread_global_end threads didn't exit, error? | I am using MySQL c++ connector (1.0.5) , recently I moved get_driver_instance() and connect() methods to secondary thread then I am getting below error.
Error in my_thread_global_end(): 1 threads didn't exit
After googling I found that mysql thread isn't exiting. Is there a method in c++ wrapper to do cleanup?
| After googling I came to know that mysql_thread_end() will solve the problem. Any way I was linking against libmysqlclient.a so included mysql.h file and called mysql_thread_end before exiting secondary thread, now the problem is solved.
|
2,071,492 | 2,071,848 | How to display exception message of managed C# code in c++ code | Iam calling the functions using SMO of a c# dll in a c++ project but the code in that dll is throwing some exception, so how can I display the exception message in my C++ code
| It depends how you call it. If you use COM then you'll get a failure HRESULT. You can use IErrorInfo to retrieve the exception message. If you use something else then you'll lose the error context, all you can see is an SEH exception with exception code 0xe0434f4e, catchable only with the __try and __except keywords... |
2,071,557 | 2,071,832 | Memory analysis for a process | I have a process which calls/creates another process, and this one will load a bunch of modules. The thing is that these modules will all be loaded in the same process as the caller (by default). Is there any way that I can collect resources information for the individual loaded module, even through they are all on one... | I have been in a situation where a process loaded some modules, these modules loaded lots of data from a database and put them this data in STL and Boost containers (std::set, std::map, std::vector, boost::multiindex). And since most of memory was used by these containers my task was to measure how much memory each con... |
2,071,876 | 2,071,910 | Does the following code invoke UB? | Does the following code invoke UB ?
int main(){
volatile int i = 0;
volatile int* p = &i;
int j = ++i * *p;
}
| Yes that is Undefined Behavior because you are trying to violate the second rule..
The Standard states that
1) Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression.
2) Furthermore, the prior value shall be accessed only to determin... |
2,071,993 | 2,072,069 | Using DLLImport to import an Object | I have a dll for a c++ class (SLABHIDDevice.dll). I am trying to use the functions of this dll in a C#.net application. The dll contains several methods which I can use easily with statements such as this...
(I appolagize if i get some of the terminology wrong here I am new to using dlls)
[DllImport("SLABHIDDevice.dll... | You cannot use P/Invoke to call instance methods of a C++ class. The primary hang-up is that you can't create an object of the class, you cannot discover the required memory allocation size. Passing the implicit "this" pointer to the instance method is another problem, it needs to be passed in a register.
You'll need... |
2,072,256 | 2,072,292 | Under what circumstances can a vtable pointer be null (or 0x1)? | I am currently debugging a crashlog. The crash occurs because the vtable pointer of a (c++-) object is 0x1, while the rest of the object seems to be ok as far as I can tell from the crashlog.
The program crashes when it tries to call a virtual method.
My question: Under what circumstances can a vtable pointer become nu... | Could be a memory trample - something writing over that vtable by mistake. There is a nearly infinite amount of ways to "achieve" this in C++. A buffer overflow, for example.
|
2,072,424 | 2,072,510 | outputting to cin from a worker thread (c++) | My program has a main thread that takes command input from a user. Separately, it has potentially multiplie (at least 1) worker threads churning data in the background.
The user is able to terminate the program using a command by typing into the console. However, when the data churning is done, the main thread is stil... | On Unix, when you need a thread to wait for multiple things (for example, a character on std::in and a command from a worker thread to communicate that it is shutting down) you use select()... You could create a pipe with the pipe() system call and the worker thread could write to it when it's exiting... The main threa... |
2,072,454 | 2,072,710 | How do I find out why g++ takes a very long time on a particular file? | I am building a lot of auto-generated code, including one particularly large file (~15K lines), using a mingw32 cross compiler on linux. Most files are extremely quick, but this one large file takes an unexpectedly long time (~15 minutes) to compile.
I have tried manipulating various optimization flags to see if they ... | Won't give all the details you want, but try running with the -v (verbose) and -ftime-report flags. The latter produces a summary of what the compiler has been up to.
|
2,072,838 | 2,074,662 | Is there a better design pattern/method to use? | I've currently completed one of two phases of a project that required I write database information to XML using C++. While use of a third party tool was used to do the actually formatting of XML tags and data, I still had to design a model along with business logic to take the database tables and map them into XML stru... | An other idea, that might also fit:
When performance is not an issue, also generic data containers could be used. A generic data container could take a specification of one node (like an XML node or an object or even a table entry) and just store such a container.
This way, the ~75 classes could be replaced by one or a... |
2,073,016 | 2,074,374 | C++: how to prevent destructing of objects constructed in argument? | I have a questing around such staff.
There is a class A which has a object of type class B as it's member. Since I'd like B to be a base class of group of other classes I need to use pointer or reference to the object, not it's copy, to use virtual methods of B inside A properly. But when I write such code
class B
{... | This is a standard issue, don't fear.
First, you could retain your design with a subtle change:
class A
{
public:
A(B& b): m_b(b) {}
private:
B& m_b;
};
By using a reference instead of a const reference, the compiler will reject the call to A's constructor that is made with a temporary because it is illegal to tak... |
2,073,054 | 2,073,084 | How to parse complex string with C++? | I'm trying to figure out how could I parse this string using "sstream" and C++
The format of it is: "string,int,int".
I need to be able to assign the first part of the string which contains an IP address to a std::string.
Here is an example of this string:
std::string("127.0.0.1,12,324");
I would then need to obtain
... | Here's a useful tokenization function. It doesn't use streams, but can easily perform the task you require by splitting the string on commas. Then you can do whatever you want with the resulting vector of tokens.
/// String tokenizer.
///
/// A simple tokenizer - extracts a vector of tokens from a
/// string, delimite... |
2,073,079 | 2,073,212 | what does compiler do with a[i] which a is array? And what if a is a pointer? | I was told by c-faq that compiler do different things to deal with a[i] while a is an array or a pointer. Here's an example from c-faq:
char a[] = "hello";
char *p = "world";
Given the declarations above, when the compiler sees the expression a[3], it emits code to start at the location ``a'', move three past it, and... | a is a pointer to an array of chars. p is a pointer to a char which happens to, in this case, being pointed at a string-literal.
movl $1819043176, -14(%ebp)
movw $111, -10(%ebp)
Initializes the local "hello" on the stack (that's why it is referenced through ebp). Since there are more than 4bytes in "hello", it ... |
2,073,366 | 2,073,403 | how to return from a blocked call? | is it possible to force a thread to return from a call to a blocking function such as a blocking read from a stream ?
int x;
std::cin >> x;
for example...
| No, it's not possible. If you want to find out whether there's data to read, use the select() syscall - if you only read when there's data waiting, you'll never block
|
2,073,510 | 2,073,914 | simple 2d collision problem | I want to find when a collision between a static and a moving ball occurs, but the algorithm I came up with, sometimes doesn't detect a collision and the moving ball goes through the static one. The moving ball is affected by gravity and the static one is not.
Here's my collision detection code:
GLfloat whenSpheresColl... | delta = ( P[0] . V[0] )^2 - V[0]^2 * (P[0]^2 - R^2)
Shouldn't that be delta = b2 - 4 ac?
[Edit] Oh I see, you factored the 4 out. In that case, are you sure you're considering both solutions for t?
t = ( -( P[0] . V[0] ) - sqrt(delta) ) / V[0]^2
and
t = ( -( P[0] . V[0] ) + sqrt(delta) ) / V[0]^2
|
2,074,099 | 2,075,050 | Coding Practices which enable the compiler/optimizer to make a faster program | Many years ago, C compilers were not particularly smart. As a workaround K&R invented the register keyword, to hint to the compiler, that maybe it would be a good idea to keep this variable in an internal register. They also made the tertiary operator to help generate better code.
As time passed, the compilers matur... | Write to local variables and not output arguments! This can be a huge help for getting around aliasing slowdowns. For example, if your code looks like
void DoSomething(const Foo& foo1, const Foo* foo2, int numFoo, Foo& barOut)
{
for (int i=0; i<numFoo, i++)
{
barOut.munge(foo1, foo2[i]);
}
}
the c... |
2,074,173 | 2,074,241 | Resizing Arrays - Difference between two execution blocks? | I have a function which grows an array when trying to add an element if it is full. Which of the execution blocks is better or faster?
I think my second block (commented out) may be wrong, because after doubling my array I then go back and point to the original.
When creating arrays does the compiler look for a contigu... | The second block wouldn't accomplish what you want at all.
When you do
myStack = new int[length *= 2];
then the system will return a pointer to wherever it happens to allocate the new, larger array.
You then reassign myStack to the old location (which you've already de-allocated!), which means you're pointing at memor... |
2,074,424 | 2,074,445 | Which open-source C++ projects have good (inspiring) tests? | What are inspiring examples of open-source software written in C++ with great tests?
I would like to read, study and follow.
| I like mysql's exhaustive test suite, where they add a test for almost every bug they fix to prevent regressions.
|
2,074,494 | 2,074,520 | virtual function question | #include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
class Helper
{
public:
Helper() { init(); }
virtual void print() {
int nSize = m_vItems.size();
std::cout << "Size : " << nSize << std::endl;
std::cout << "Items: " << std::endl;
for(int i=0; i<nSize; i... | In a base class constructor, the derived class has not yet been constructed so the overriden function on the derived class is not yet available. There's a FAQ entry on this somewhere... which I can't find.
The simplest solution is to just put the .push_back("A") part of init into the Helper constructor and the .push_ba... |
2,074,579 | 2,074,884 | Should I use _T or _TEXT on C++ string literals? | For example:
// This will become either SomeMethodA or SomeMethodW,
// depending on whether _UNICODE is defined.
SomeMethod( _T( "My String Literal" ) );
// Becomes either AnotherMethodA or AnotherMethodW.
AnotherMethod( _TEXT( "My Text" ) );
I've seen both. _T seems to be for brevity and _TEXT for clarity. Is this m... | A simple grep of the SDK shows us that the answer is that it doesn't matter—they are the same. They both turn into __T(x).
C:\...\Visual Studio 8\VC>findstr /spin /c:"#define _T(" *.h
crt\src\tchar.h:2439:#define _T(x) __T(x)
include\tchar.h:2390:#define _T(x) __T(x)
C:\...\Visual Studio 8\VC>findstr /... |
2,074,780 | 2,075,795 | how to create a vpn software | I want to create an application which creates a VPN between some endpoints, something like hamachi and i do not have a starting point. I haven't found any resource to explain how to create such a network application.I want to use c# because i have some experience with it.
I really need some help, anything that can put ... | There are a number of distinct elements of VPN software that you'll have to figure out:
What technology/standard will your program use to provide the privacy? Some common ones are IPSEC, L2TP, PPTP, SSH, and SSL. Web searches ought to turn up rich information (including RFCs) on all of these. If you're doing this as a... |
2,075,078 | 2,075,099 | C++/VS2005: Defining the same class name in two different .cpp files | Somewhat of an academic question, but I ran into this while writing some unit tests.
My unit test framework (UnitTest++) allows you to create structs to serve as fixtures. Usually these are customized to the tests in the file, so I put them at the top of my unit test file.
//Tests1.cpp
struct MyFixture { MyFixture()... | Try sticking the classes in an anonymous namespace, you may find it less distasteful than having to create and name a new namespace for each file.
Don't have access to VS2005 and Cpp unit but this may work..
//Tests1.cpp
namespace
{
struct MyFixture { MyFixture() { ... do some setup things ...} };
}
TEST_FIXTURE(MyFi... |
2,075,123 | 2,075,212 | How to get an object of a unknown class with given classname | I am searching for a way to determine at runtime, which type of object should be alloced (based on a given class name, which is of type const char*).
Well the simplest way of course is to use loads of ifs /else ifs, but that doesnt seem applicable, because i have > 100 different classes(well at least they all derive fr... | Can't you just declare
template<typename TBase, typename TDerived, typename TArg, typename... TArgs>
?
Then you can specialize for the case of
typename TBase, typename TDerived, typename TArg
|
2,075,231 | 2,075,268 | Problem with a trainer I'm trying to create (for educational purposes) | I'm trying to create a trainer for Icy Tower 1.4 for educational purposes.
I wrote a function that shorten the WriteProcessMemory function like that:
void WPM(HWND hWnd,int address,byte data[])
{
DWORD proc_id;
GetWindowThreadProcessId(hWnd, &proc_id);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE... | You can't pass an array to a function like that. Having a byte[] parameter is the same as a byte * parameter, and sizeof(data) will just give you the size of a pointer. Also, you shouldn't use &data since it's already a pointer.
So your function should look like:
void WPM(HWND hWnd,int address, byte *data, int dataSize... |
2,075,247 | 2,075,256 | C++: Overloading operator= | Okay so I have a class that has 'weak typing' I.E. it can store many different types defined as:
#include <string>
class myObject{
public:
bool isString;
std::string strVal;
bool isNumber;
double numVal;
bool isBoolean;
bool boolVal;
double operator= (const myObject &);
... | Overloading operator= changes the behaviour when assigning to objects of your class type.
If you want to provide implicit conversion to other types you need to supply a conversion operator, e.g.
operator double() const
{
if (!isNumber)
throw something();
return numVal;
}
|
2,075,299 | 3,324,185 | Any good (really good) material on Poco C++? | Hardly can I find any good material on Poco C++. Their documentation cannot replace a good 3rd party tutorial enriched with real-world examples and lit with creativity. Please refer some if you know any. Thanks in advance.
| We have now posted lots of introductory slides to our documentation website: http://pocoproject.org/documentation
|
2,075,655 | 2,075,770 | Dealing with 32-bit code on Snow Leopard 64-bit? | I would like to create an XPCOM plugin for a XULRunner application that I'm building. Since Mozilla only provides a 32-bit build of the XULRunner SDK I have to link with 32-bit libraries. This means that a lot of libraries need to be built by me.
Relating this I have a few questions:
Can I do a sudo make install for a ... | sudo make install will be fine, IF the installation location does not conflict with the system libraries. In order to allow the built binaries to find your libraries, otool and install_name_tool are your friends. For deployment, these will allow you to make everything bundle-relative even if it has been built for a d... |
2,075,814 | 2,075,826 | Can C++ export class from DLL | I would like to know if the export of class ( __declspec(dllexport) in VC++ ) is a kind of standard ( ANSI , ISO , ... )
I would like to know if someone has already try to do the same with intel c++ compiler and gcc ( mingw on windows ) and if it is possible to mix dlls generated from different compilers ( I really dou... | No, __declspec is VC++ specific.
One of the reasons that VC++ needs that is by default, DLLs do not expose symbols outside the DLL unless explicitly requested to do that. On Posix, shared objects expose all their (not-static) symbols unless explicitly told to hide them.
Update
Based on your comment that you want to ma... |
2,075,898 | 2,076,144 | Good input validation loop using cin - C++ | I'm in my second OOP class, and my first class was taught in C#, so I'm new to C++ and currently I am practicing input validation using cin. So here's my question:
Is this loop I constructed a pretty good way of validating input? Or is there a more common/accepted way of doing it?
Thanks!
Code:
int taxableIncome;
int e... | I'm not a huge fan of turning on exceptions for iostreams. I/O errors aren't exceptional enough, in that errors are often very likely. I prefer only to use exceptions for less frequent error conditions.
The code isn't bad, but skipping 80 characters is a bit arbitrary, and the error variable isn't necessary if you fi... |
2,075,957 | 2,075,982 | Passing a const vector<pointers> to a method but changing value pointed to | I have following code (only relevant portions shown for sake of brevity - please let me know if I have been too brief):
class my_class
{
public:
my_class() {m_i=0;}
set(int i) {m_i = i;}
private:
int m_i;
}
void CallMod()
{
// create a bunch of my_class* o = new my_class() and store in vector<m... | The vector will be const. You can only get const_iterators from it. You can't modify it or it's elements.
The elements in the container will be const pointers. Unfortunately, a const pointer doesn't mean the element it points to is const, just that the value of the pointer can't change.
If you had a vector<my_class> in... |
2,076,000 | 2,076,011 | removing strings from a vector via boost::bind | I am trying to remove short strings from a vector.
std::vector<std::string> vec;
// ...
vec.erase(std::remove_if(vec.begin(),
vec.end(),
boost::bind(std::less<size_t>(),
boost::bind(&std::string::length, _1),
... | It looks like you got your parenthesis off (there should be two after 5, one to close the bind, one to close the remove_if.) I am surprised this didn't give another error message about invalid token or something though, as the parens are clearly unbalanced (did you remove an extra close paren from the end while prepari... |
2,076,209 | 2,076,261 | passing pointers from C to C++ and vice versa | Is there any tips one can give me about passing pointers to structs, doubles, functions, ... from a C program to a C++ library and back?
| Assuming you're coding these in two different libraries static or dynamic (DLLs on windows shared libraries on Linux and other *nix variants) The biggest concerns I have are as follows:
They are compiled with the same compiler. While this isn't necessary if all C++ exports are exported with a C-style naming conventio... |
2,076,238 | 2,076,263 | Dispatch Table in C++ | Suppose I have something like the following:
class Point : geometry {
...
Point(double x, double y) {
}
double distanceTo(Line) {
}
double distanceTo(Point) {
}
}
class Line : geometry {
...
Line(double x, double y, double slopex, double slopey) {
}
double distanceTo(Line) {
}
dou... | I would make the class diagram different: an abstract base class GeomObject, subclassing geometry (with a getType accessor, as well as pure virtual distanceTo overloads), and concrete subclasses Line and Point of GeomObject (with overrides of the accessor and overloads). The need to "extern C" the double distanceTo fu... |
2,076,332 | 2,076,347 | Strange Compiler Behavior Regarding Default Constructors in C++ | class TestClass
{
public:
TestClass(int i) { i = i; };
private:
int i;
}
class TestClass2
{
private:
TestClass testClass;
}
Why does the above code compile fine even when we have not provided a default constructor?
Only if someone instantiates TestClass2 elsewhere in the code, do we get a compile error. W... | When you specify a non default constructor without specifying a default constructor, the default constructor doesn't exist.
You aren't attempting to call the default constructor until you try to call it explicitly as you are in TestClass2. If you instead in TestClass2 specified a constructor that initialized TestClass... |
2,076,337 | 2,076,361 | Semantic checking of default template parameters | On page 340 of the C++ Programming Language: Special Edition, Stroustrup writes...
The semantic checking of a default argument for a template parameter is done if and (only) when that default argument is actually used. In particular, as long as we refrain from using the default template argument Cmp<T> we can compare()... | The given example is:
template<class T, class C = Cmp<T> >
int compare(const String<T>& str1, const String<T>& str2)
{
// ... compare using C
}
The idea is that the class template Cmp might not be defined or illegal for some T. In that case, you can pass a custom comparison class template:
compare<char, MyCompare... |
2,076,339 | 2,076,349 | Java wrapper around a PE (.exe) | Is there any way to make a Java program (in Windows) that just acts as a wrapper around a PE
(.exe), passing all stdin input to the program and writing out to stdout everything that the PE writes out.
I need this because the interface for a program only allows Java classes, but I want it to run some code that I've put... | Take a look at ProcessBuilder:
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("OTHERVAR");
env.put("VAR2", env.get("VAR1") + "suffix");
pb.directory("myDir");
Process p = pb.start();
and another example ... |
2,076,409 | 2,076,413 | C++ ...when all the arguments have default values | I guess that this is a very absurd/basic question, but still:
class m
{
public:
void f(int ***);
/***/
}
void m::f(int ***a = NULL)
{
/***/
}
The call to f (as well as any function which has default values for all the arguments) doesn't accept 0 arguments. Why? How should I format the declaration then?
| That works fine if the function definition is in the header file. The rule is that whoever is calling the function has to 'see' the default value.
So, I'm guessing you have the function definition in a separate source file. Assuming that's the case, just put the default in the function declaration (in the class):
cla... |
2,076,460 | 2,076,476 | C++ NetUserAdd() not working? | I posted earlier about how to do this, and got some great replies, and have managed to get the code written based off the MSDN example. However, it does not seem to be working properly. Its printing out the ERROR_ACCESS_DENIED message, but im not sure why as I am running it as a full admin. I was initially trying to cr... | Is you os vista or win 7?, if so then you may need to raise your privilege level.
|
2,076,532 | 2,076,547 | How does sbrk() work in C++? | Where can I read about sbrk() in some detail?
How does it exactly work?
In what situations would I want to use sbrk() instead of the cumbersome malloc() and new()?
btw, what is the expansion for sbrk()?
| Have a look at the specification for brk/sbrk.
The call basically asks the OS to allocate some more memory for the application by incrementing the previous "break value" by a certain amount. This amount (the first parameter) is the amount of extra memory your application then gets.
Most rudimentary malloc implementatio... |
2,076,618 | 2,076,627 | NetUserAdd() to Remote Desktop Group? | Is there anyway to give a newly created user from NetUserAdd() remote desktop access and/or administrative rights? I know it is possible, at least for Remote Desktop, and I have been reading through the MSDN but nothing seems to hint at what is required to be set for it to work.
| Those rights are controlled by alias membership. For Remote Desktop access it's the Remote Desktop Users alias, while for administrators it's the Administrators alias (obviously). You can add users to aliases using NetLocalGroupAddMembers.
PS: The proper term is "alias", but the Net* functions use "local group" for som... |
2,076,723 | 2,076,761 | Read from file, clear it, write to it | I'm trying to read data from a text file, clear it, and then write to it, in that order using the fstream class.
My question is how to clear a file after reading from it. I know that I can open a file and clear it at the same time, but is there some function I can call on the stream to clear its contents?
| You should open it, perform your input operations, and then close it and reopen it with the std::fstream::trunc flag set.
#include <fstream>
int main()
{
std::fstream f;
f.open("file", std::fstream::in);
// read data
f.close();
f.open("file", std::fstream::out | std::fstream::trunc);
// writ... |
2,076,753 | 2,076,778 | auto_ptr released without assigning its return value | So what happens to a pointer if you release an object owned by auto_ptr but do not actually assign it to a raw pointer? It seems like it's supposed to be deleted but it never gets the chance to. So does it get leaked out "into the wild"?
void usingPointer(int* p);
std::auto_ptr<int> point(new int);
*point = 3;
using... | release isn't suppose to delete the owned point, from the docs:
Sets the auto_ptr internal pointer to null pointer (which indicates it points to no object) without destructing the object currently pointed by the auto_ptr.
Also, it's overkill to replace all uses of your auto_ptr with tr1::shared_ptr - you should be us... |
2,076,817 | 2,079,921 | Help Using NetuserAdd() and NetLocalGroupAddMembers() in C++ | So I think I almost got it. I create my dummy account with one function, and wrote a second function to add it to the Remote Desktop group. Problem is, the Administrator account is the one logged in, so I am not sure how to specify what account to add to the group. Here is my code...
The user is being created properly.... | No offense, but you don't seem to know what you're doing with the code at all. You're not adding the current user to the target group; you're adding the user you just created to it right? Then why are you calling GetUserNameEx? Just use the name of the new user:
lgmi3.lgrmi3_domainandname = L"BrettXFactor";
|
2,076,874 | 2,076,892 | friend function in template definition | My question ist related a bit to this one.
I want to overload the operator << for some class and I found two different notations that both work:
template <class T>
class A{
T t;
public:
A(T init) : t(init){}
friend ostream& operator<< <> (ostream &os, const A<T> &a); //need forward declaration
//template <class... | The first version restricts the friendship to the operator<< for the specific type A<T> , while the second makes any operator<< that takes an A<SomeType> a friend.
So yes, the first one is more restrictive:
template<class T>
ostream& operator<< (ostream& os, const A<T>& a) {
A<double> b(0.0);
b.t; // compile er... |
2,076,936 | 2,076,943 | An Analog of List.h in .Net | I used to use List.h to work with lists in C++, but are there any similar libraries in .Net ? Becouse I can't use List.h for managed types.
| Check out the System.Collections and System.Collections.Generic namespaces.
There, you'll find classes like ArrayList, List<T>, etc...
|
2,077,068 | 2,077,073 | Number of items in a byte array | I've the following C++ array:
byte data[] = {0xc7, 0x05, 0x04, 0x11 ,0x45, 0x00, 0x00, 0x00, 0x00, 0x00};
How can I know how many items there are in this array?
| For byte-sized elements, you can use sizeof(data).
More generally, sizeof(data)/sizeof(data[0]) will give the number of elements.
Since this issue came up in your last question, I'll clarify that this can't be used when you pass an array to a function as a parameter:
void f(byte arr[])
{
//This always prints the s... |
2,077,091 | 2,077,114 | If I Develop a C++ (native) DLL with VS2010 will I need MSVCRT100.dll to be also deployed? | I'm not using any features of the MSVCRT100.dll (I don't even know if there are new features).
| Unfortunately, yes. You'll need the VC10 runtime for your platform (x86) or (x64) -- keep in mind though the runtime may change, though it is highly unlikely since VStudio has been in it's final phases for a while now.
It is the core runtime library, you can find out more of your dependencies using DependencyWalker (ht... |
2,077,119 | 2,077,434 | what is the best way to synchronize container access between multiple threads in real-time application | I have std::list<Info> infoList in my application that is shared between two threads. These 2 threads are accessing this list as follows:
Thread 1: uses push_back(), pop_front() or clear() on the list (Depending on the situation)
Thread 2: uses an iterator to iterate through the items in the list and do some actions.
T... | In general it is not safe to use STL containers this way. You will have to implement specific method to make your code thread safe. The solution you chose depends on your needs. I would probably solve this by maintaining two lists, one in each thread. And communicating the changes through a lock free queue (mentioned i... |
2,077,303 | 2,077,469 | QProgressbar and QNetworkReply signals | i'm writing an application in C++ with the Qt Framework.
It should download a File over http and display the download progress with a QProgressbar - but I don't get that part to work!
Sample code:
QProgressBar* pbar = new QProgressBar();
//calls the website and returns the QNetworkReply*
QNetworkReply* downloader = Dow... | Yeah, it's right, you have to set matching arguments in your SIGNAL/SLOT methods... Anyway, in the Qt Examples And Demos, you can find the following code in the exemple "FTP Client" :
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64, qint64)));
...
void FtpWindow:... |
2,077,664 | 2,077,784 | implicit linking DLL question | I started studying DLL's with implicit linking. I don't really fully understand how it works. Please correct me where I'm wrong.
I failed to compile the next code(3 modules):
MyLib.h
#ifdef MYLIBAPI
#else
#define MYLIBAPI extern "C" __declspec(dllimport)
#endif
MYLIBAPI int g_nResult;
MYLIBAPI int Add(int nLeft... | #include <tchar.h> to solve the linker error.
Your header file should look like this:
#ifdef BUILDING_DLL
# define MYLIBAPI extern "C" __declspec(dllexport)
#else
# define MYLIBAPI extern "C" __declspec(dllimport)
#endif
MYLIBAPI int __stdcall Add(int nLeft, int nRight);
Right-click your DLL project in Solution Exp... |
2,077,919 | 2,078,013 | Is there an algorithm for moving ranges? | In C++98, I can copy ranges with the std::copy algorithm.
std::copy(source.begin(), source.end(), destination.begin());
Is there an algorithm in C++0x that moves the elements from source to destination? Or is std::copy somehow overloaded to accept something like rvalue iterators -- is there even such a thing?
The algo... | It seems to be in the latest draft (see section 25.3.2).
I have a hard copy of C++03 which is exactly the same as C++98 (sections 25.2.x) where you can see the same algorithms (without 'move' obviously).
|
2,078,087 | 2,078,121 | Local classes inside inline non-member function produces LNK2005 with MSVC2005 | Apparently, MSVC2005 fails to inline local classes' member functions which leads to LNK2005.
I'm facing this LNK2005 error when compiling the following:
common.h content:
inline void wait_what()
{
struct wtf
{
void ffffuuu() {}
} local;
}
foo.cpp content:
#include "common.h"
void foo()
{
wait_what();
}
... | it was a bug in visual studio 2005, it was fixed in vs 2008
|
2,078,220 | 2,078,288 | Help in converting AA script to C++ | I've this AA script (Cheat Engine scripting language):
[ENABLE]
alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(exit)
00415e19:
jmp newmem
returnhere:
newmem:
mov [00451104],0//moves 0 to the clock variable
//nop//nops the clock increaser
exit:
jmp returnhere
[DISABLE]
dealloc(newmem)
00415e19:
mo... | The opcode for moving an immediate (like you are trying to do) is longer (9 bytes) than the game's original code that moves from a register (4 bytes). The extra 5 bytes are most likely overwriting an instruction or two after the original mov causing the program to crash.
Just like in Cheat Engine you'll need to allocat... |
2,078,290 | 2,078,331 | Efficient Way to Process Simple but Large Files in C++ | I'm working on a project that has me a bit over my head performance-wise. I'm tasked with reading large (50MB or so) files of particle coordinates and displaying them. I'd like to use C++ for this because I am learning it already.
The coordinate structure in the files are simple, there's just alot (say a million or... | You might want to preallocate the vector using .reserve if you have an idea of how large the "average" file is.
Efficiency is a tricky game. Don't play tricks early on, and design a good basic algorithm. If it's not fast enough, you start looking at the IO routines, whether you're creating any "extra" objects (explic... |
2,078,365 | 2,078,387 | Resources to Write ANSI C++ Code | The last time I heavily used C++ was years ago, and it was strictly done on the Windows platform. Specifically, I used Microsoft Visual Studio as my IDE and developed some habitual patterns to use Microsoft's C++ version. For example, I used void main() instead of the standard int main().
Now, I am taking a class whe... | I would highly recommend these two:
comp.lang.c++ Usenet newsgroup. If you can get hold of a good Usenet service provider, and use a news reader, you should be able to get rid of the spam. I use eternal-september.org, and like it a lot.
Read the C++ FAQ. It has a lot of great information.
Granted, they both are no... |
2,078,474 | 2,078,627 | How to use boost normal distribution classes? | I'm trying to use boost::normal_distribution in order to generate a normal distribution with mean 0 and sigma 1.
The following code doesn't work as some values are over or beyond -1 and 1 (and shouldn't be). Could someont point out what I am doing wrong?
#include <boost/random.hpp>
#include <boost/random/normal_distrib... |
The following code doesn't work as some values are over or beyond -1 and 1 (and shouldn't be). Could someont point out what I am doing wrong?
No, this is a misunderstanding of the standard deviation (the second parameter in the constructor1) of the normal distribution.
The normal distribution is the familiar bell cur... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.