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 |
|---|---|---|---|---|
4,432,029 | 4,513,832 | C++ CreateProcess SW_HIDE firefox, chrome, safari | I'm writing a web testing framework for windows that uses multiple browsers to test web apps.
I want to launch the browsers hidden but it's not working.
I'm using CreateProcess to start the browsers with the SW_HIDE flag
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;... | The problem is that the value of wShowWindow is used only when the function ShowWindow is called with the command SW_SHOWDEFAULT, additionally as FastAl said the browser create some additional process to do additional tasks.
Based on you idea and the answer of FastAl, you can do this to hide the windows created by the ... |
4,432,793 | 4,432,865 | Size of stringstream | Is there any direct way to calculate size of internal string in stringstream?
Here, str() returns a copy and then it gets the size of string.
std::stringstream oss("String");
oss.str().size();
| std::stringstream oss("String");
oss.seekp(0, ios::end);
stringstream::pos_type offset = oss.tellp();
This is for the write pointer, but the result is the same for read pointer on Visual C++ v10.
|
4,432,968 | 4,432,983 | efficiency in multithreading | suppose I have a code like this
for(i = 0; i < i_max; i++)
for(j = 0; j < j_max; j++)
// do something
and I want to do this by using different threads (assuming the //do something tasks are independent from each other, think about montecarlo simulations for instance). My question is this: is it necessarily bett... | The best way to apportion the workload is workload-dependent.
Broadly - for parallelizable workload, use OpenMP; for heterogeneous workload, use a thread pool. Avoid managing your own threads if you can.
Monte Carlo simulation should be a good candidate for truly parallel code rather than thread pool.
By the way - i... |
4,432,989 | 4,433,031 | C++ header files for UDP in Windows? | I have a linux applications which sends data over UDP protocol. It uses these header files:
#include <stdio.h>
/* standard C i/o facilities */
#include <stdlib.h>
/* needed for atoi() */
#include <unistd.h>
/* defines STDIN_FILENO, system calls,etc */
#include <sys/types.h> /* system data type definitions */
#include ... | At compile-time, you need to use Winsock2.h instead of the Unix headers.
At link-time, include ws2_32.lib to provide linkage to the required system DLL.
|
4,433,011 | 4,570,564 | Rvalue refs in concurrency | I've been getting a little down to grips with the new Visual Studio native Concurrency runtime (ConcRT). Is it just an oversight, or is there a valid reason that no cross-thread movement of data has movement semantics? They're all copy semantics. You can't move into a concurrent queue, you can't move with asend, etc. Y... | I don't know this specific framework, but generally for inter thread queues you must have copy semantics.
Imagine I create an object, take a reference/pointer to it then move it to the queue. Then the other thread moves it out of the queue. Then both threads can access it at the same time.
I think that in the general... |
4,433,155 | 4,433,359 | Can I write a C++ functor that accepts both a raw pointer and a smart pointer? | Given the following:
struct Foo
{
int bar() const;
};
struct IsEqual : public std::unary_function<Foo*, bool>
{
int val;
IsEqual(int v) : val(v) {}
bool operator()(const Foo* elem) const
{
return elem->bar() == val;
}
};
I have a container of Foo* and I use std::find_if and std::not1 ... | // --*-- C++ --*--
#include <vector>
#include <algorithm>
#include <iostream>
// Template unary function example.
template <typename T>
struct IsEqual : public std::unary_function<T, bool>
{
int v;
IsEqual (int v) : v (v) {}
bool operator () (const T & elem) const
{
return elem ? elem->bar (... |
4,433,244 | 4,433,578 | How To Enumerate All coclasses That Implement A Particular COM Interface? | I will describe the problem as simple as i can;
Let's say we have a com client that defines several interfaces.
In order to improve our com client's functionality; several, independent companies develops & deploys com servers that implements the interface. It is possible that the target machine may have com servers tha... | There's no standard COM cataloging service that I know of, although COM+ might have something. Take a look at HKCR\Component Categories, you'll find GUIDs of type of components. Like 0DE86A57-2BAA-11CF-A229-00AA003D7352, described as "Class implements IPersistPropertyBag". A coclass declares this same guid in its CL... |
4,433,545 | 4,433,592 | c++ non-fatal exception handling | I was told in a comment in another thread that I should be using exceptions whenever anything out of the ordinary happens, even if it isn't fatal to the script. This came up as I was using constructs akin to the following:
return err("File could not be loaded");
which would print the error to the screen, and return fa... | try
{
validate(code);
process(code);
}
catch(...)
{
return false;
}
return true;
Assuming that validate throws, process won't happen.
|
4,433,778 | 4,433,830 | Is it possible to C++ compiler inline method calls across DLLs? | Is it possible to C++ compiler inline method calls across DLLs?
Is it possible for .NET JIT ?
| That's a definite Yes for a .NET jitter. It merely loads IL from a DLL, just-in-time code generation makes the fact that it came from a DLL disappear. All code from any DLL goes into the same loader heap. One consequence of this is that a DLL cannot be unloaded unless the entire AppDomain is unloaded.
A definite N... |
4,433,891 | 4,434,603 | optimizing modular arithmetic computations in C++ | I am developing some linear algebra code that that is templated on the
matrix coefficient type. One of the possible types is a class to do
modular arithmetic, naively implemented as follows:
template<typename val_t> // `val_t` is an integer type
class Modular
{
val_t val_;
static val_t modulus_;
public:
Modular... | Yes. It is possible. What you want to look up is "expression templates" and start from there. From that point you're going to have to build some metaprogram logic to optimize/simplify the expression. Far from a trivial task, but that's not what you asked.
NVM - it's way trivial:
int count = 0;
int modulus() { count... |
4,434,036 | 4,434,114 | How to fix header file error? | So, my question is how to fix some error in header file, to run program normally? For example I use c++ builder 2010 and when winuser.h file is included, the program always get error like this
Checking project dependencies...
Compiling Project7.cbproj (Debug
configuration) [BCC32 Error]
winuser.h(47): E2257 , ex... | The message is hard to read but the actual error is "E2257 , expected" (coma expected)
From the RAD studio documentation:
A comma was expected in a list of declarations, initializations, or parameters.
This problem is often caused by a missing syntax element earlier in the file
or one of its included headers.
The e... |
4,434,050 | 4,434,125 | Multithreading and Critical Sections Use - C++ | I'm a little confused as to the proper use of critical sections in multithreaded applications. In my application there are several objects (some circular buffers and a serial port object) that are shared among threads. Should access of these objects always be placed within critical sections, or only at certain times?... | If you share a resource across threads, and some of those threads read while others write, then it must be protected always.
It's hard to give any more advice without knowing more about your code, but here are some general points to keep in mind.
1) Critical sections protect resources, not processes.
2) Enter/leave c... |
4,434,140 | 4,690,988 | Narrowing conversions in C++0x. Is it just me, or does this sound like a breaking change? | C++0x is going to make the following code and similar code ill-formed, because it requires a so-called narrowing conversion of a double to a int.
int a[] = { 1.0 };
I'm wondering whether this kind of initialization is used much in real world code. How many code will be broken by this change? Is it much effort to fix ... | I ran into this breaking change when I used GCC. The compiler printed an error for code like this:
void foo(const unsigned long long &i)
{
unsigned int a[2] = {i & 0xFFFFFFFF, i >> 32};
}
In function void foo(const long long unsigned int&):
error: narrowing conversion of (((long long unsigned int)i) & 4294967295... |
4,434,150 | 4,434,184 | Why is the string version of getline a non-member function? | The getline function has a character version that is a member function, as well as a global version that takes strings. Why aren't they both member functions? The current way makes it seems as though there isn't a string version.
| istream& istream::getline(char* s, streamsize n) is part of the stream interface.
istream& getline(istream& is, string& str) is an extension method from the string library (just like the istream &operator>>(istream&, string&)).
This design was probably chosen in order to decouple iostreams from string, as fstream::open... |
4,434,241 | 4,434,388 | libcurl POST - CURLOPT_READFUNCTION & CURLOPT_WRITEFUNCTION for posting XML | I am attempting to use libcurl to post XML data to a sort-of web service. I'm using tinyxml to create an xml document, and I'd like to be able to POST that using curl and parse the XML response with tinyxml as well. I have searched stackoverflow, but none of the existing questions match my scenario.
I can't figure out ... | Try this instead:
typedef struct
{
void *data;
int body_size;
int body_pos;
} postdata;
size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream)
{
if (stream)
{
postdata *ud = (postdata*) stream;
int available = (ud->body_size - ud->body_pos);
if (avail... |
4,434,282 | 4,434,362 | Visual C++ equivalent of __FILE__ , __LINE__ and __PRETTY_FUNCTION__ | GCC compiler gives me the following macros:
__FILE__ so that I can print out the file name + directory.
__LINE__ so that I can print out the line number of where I'm printing from.
__PRETTY_FUNCTION__ so that I can print out the pretty function name
Does Visual C++ have the equivalent of these macros? A side question... | In VS2008, this:
struct A
{
bool Test(int iDummyArg)
{
const char *szFile = __FILE__;
int iLine = __LINE__;
const char *szFunc = __FUNCTION__; // Func name
const char *szFunD = __FUNCDNAME__; // Decorated
const char *szFunS = __FUNCSIG__; // Signature
printf("%s\... |
4,434,296 | 4,434,397 | C++ 3D perfect collision detection | I'm having hard time learning collision detection by experience. I'm making a box game, à la Minecraft, and am at the stage of implementing collision detection.
I've done x and y axis', since everything consists of cubes I would like to make my own collision detector and make it as light as possible.
Is there a way to ... | You've identified one of the problems of using discrete mathematics to model the path of an object. At time t the object is "here" and at time t + delta it's "there" - without actually having passed through the points in between.
You can get more accuracy by decreasing delta, but ultimately you are going to hit the lim... |
4,434,335 | 4,434,438 | QuadTree for 2D collision detection | I'm currently working on a 2D shoot them up type of game, and I'm using a quad tree for my collision detections. I wrote a working quad tree that correctly pushes my actors into the nodes/leaves they belong to in the tree. However, I've got a few problems.
Firstly, how do I actually use my quadtree to select against wh... | You can establish a convention that every element is contained in the smallest quadtree node which contains it fully.
Then when you check the collisions for node A, you proceed like this:
current node = root node
check collisions of A with each element directly in current node
if A can be contained entirely in any of ... |
4,434,386 | 4,434,429 | Communication with a script from a C++ program | I have a c++ program (very complicated, and lengthy both in code and execution time).
Once in a while this program stops and calls a user-specified shell script.
Before calling the script, my program creates a .out file with current data. I call the script via system() command. The script then reads the .out file, and ... | On a unix-like system? Perhaps pipe (2) will work for you?
From the man page (Mac OS X 10.5 version):
SYNOPSIS
#include <unistd.h>
int pipe(int fildes[2]);
DESCRIPTION
The pipe() function creates a pipe (an object that allows unidirectional
data flow) and allocates a pair of file descriptors. Th... |
4,434,395 | 4,434,497 | C++ passing Dynamically-sized 2D Array to function | I'm trying to figure out how to pass 2D array, which is constructed dynamically to a function.
I know that number of columns must be specified, but it my case it depends on user input.
Are there any workarounds?
Example:
// Some function
void function(matrix[i][j]) {
// do stuff
}
// Main function
int N;
cout << "Size:... | If you're on C++, the reasonable options are to:
use boost::multi_array (recommended), or
make your own 2D array class. Well, you don't have to, but encapsulating 2D array logic in a class is useful and makes the code clean.
Manual 2D array indexing would look like this:
void func(int* arrayData, int arrayWidth) {
... |
4,434,569 | 4,434,734 | Is it possible to use SFINAE/templates to check if an operator exists? | I'm trying to check if an operator exists at compile time, if it doesn't I just want it ignored, is there any way to do that?
example operator:
template <typename T>
QDataStream& operator<<(QDataStream& s, const QList<T>& l);
| I ended up using a fallback namespace :
namespace operators_fallback {
template <typename T>
inline QDataStream& operator<<(QDataStream& s, const T &) { return s; }
template <typename T>
inline QDataStream& operator>>(QDataStream& s, T &) { return s; }
template <typename T>
inline QDebug operator<<(QDebug d, const T ... |
4,434,604 | 4,435,678 | Determining Qt stylesheet options programmatically? | Is it possible to look up stylesheet values at runtime in Qt?
I'm working on a custom button derived from QPushButton that has some stylesheet properties set. I'd like to be able to look up some stylesheet settings like border width, margin, padding-top, padding-left, padding-right, etc. Is this at all possible to do ... | Don't think so, you might be able to find something by stepping through the drawing code. But the parsing and the application of stylesheets is pretty optimised and uses a lot of preprocessing. I don't even think that you can get to the stylesheet of a widget if it was actually set in a parent.
|
4,434,607 | 4,434,750 | C/C++ API ODBC process ID | I would like to know if it's possible to get the current process id of an SQL connection through ODBC C/C++ API.
Under SqlServer it is @@spid, connection_id() with MySQL.
Cannot find that in ODBC documentation.
Thanks...
| You can write a stored procedure to return @@spid on the connection
CREATE PROC
GetSPID
AS
SELECT @@SPID AS 'ID';
Then exec as per usual OBDC API
|
4,434,609 | 4,434,727 | How to determine whether a file has been closed | I'm writing a unit test, and I'm trying to find a way to test whether my class has properly closed a file handle (it uses old-style open() and close()). Ideally I'd like to be able to do it without having access to the actual handle - I want to be able to check a file in the file system and determine whether it is curr... | It's not a proper unit-test if you're relying on opening \ closing files like this - such tests can randomly fail for a variety of reasons, leading to false positives and general confusion.
Instead, consider abstracting away the file operations and ensuring that close is called on your representation of the file.
|
4,435,067 | 4,456,576 | Adding Boost Library to a C++ project in OS X Eclipse | I am have been attempting to get a C++ project setup using boost file system library using eclipse. I followed these directions to install boost on my system. The directions where pretty much
download
extract
run bootstrap.sh
run ./bjam architecture=combined
That seemed to go fine, no errors. I then fired up ecli... | Not sure where you do this in Eclipse these days, but under the include paths for Eclipse should be the path to the main boost directory (/Users/jacobschoen/Library/boost_1_45_0?). The compiler line should have something like the following in it, I would think:
Invoking: GCC C++ Compiler
g++ -I/Users/jacobschoen/Libra... |
4,435,075 | 4,435,126 | C++ - stat(), access() not working under gnu gcc | I've got a pretty basic console program here, to determine if a folder or file exists or not using stat:
#include <iostream>
#include <sys/stat.h>
using namespace std;
int main() {
char path[] = "myfolder/";
struct stat status;
if(stat(path,&status)==0) { cout << "Folder found." << endl; }
else { cout << "Ca... | Right before your stat call, insert the code:
system("pwd"); // for UNIXy systems
system("cd"); // for Windowsy systems
(or equivalent) to check your current directory. I think you'll find it's not what you think.
Alternatively, run the executable from the command line where you know what directory you're in. IDEs ... |
4,435,091 | 4,435,481 | sh_none is not a member of 'std::basic_filebuf<_Elem,_Traits>' | I am trying to use the Microsoft Specific filebuf::sh_none variable to open an fstream in an exclusive mode (another Microsoft specific function). I am getting the above error. I am importing <fstream>. How can I fix this error?
UPDATE: I found this thread, where it was suggested that I try _SH_DENYNO instead. The code... | What version of Visual C++ are you using?
The Visual C++ 6 documentation you linked to is the pre-standard version of iostreams, from #include <fstream.h>. It's no longer available, and even in Visual C++ 6.0 was only there for backward compatibility.
Also, _SH_DENYNO is the opposite of exclusive mode. You want _SH_D... |
4,435,159 | 4,435,618 | Why are these templates ambiguous? | The book C++ Templates : The Complete Guide has an example on page 275 that I'm having trouble wrapping my head around.
Quoting excerpts from the book...
template <typename T>
class Promotion<T,T> {
public:
typdef T ResultT;
};
template<typename T1, typename T2>
class Promotion<Array<T1>, Array<T2> > {
public:... | Maybe your confusion stems from how the relation "is more specialised than" works. It's a partial order, not a total order -- that means that given 2 template specialisations, it's not always the case that one is more specialised than the other.
Anon's comment is right: Suppose that 3rd specialisation didn't exist, an... |
4,435,192 | 4,435,214 | How to understand the output? | int a[2][3];
cout << a+1 << " " << a << " " << (a+1) - a << endl;
Output:
0029FAC0 0029FAB4 1
Shouldn't (a+1)-a be 0029FAC0-0029FAB4=12 ?
| No, because pointer arithmetic is scaled depending on the thing you're pointing to. In this case, you're pointing to a three-element array of integers, each four bytes long, for a total of twelve bytes. But that's scaled back to one "element" in your arithmetic.
It's the same reason that you get 0029FAC0 rather than 00... |
4,435,268 | 4,435,348 | CreateFile fails with error ERROR_SHARING_VIOLATION | Im using the CreateFile api and some times it randomly fails with the error: ERROR_SHARING_VIOLATION.
I have googled and there is almost nothing about this error. The strange thing is next time it is quite happy to open the same file.
Here is my code:
void FileHandle::open(const char* fileName, FILE_MODE mode)
{
if... | There is nothing wrong with CreateFile - a sharing violation means that something else has the same file open. Which could be your own program, if you have the file open with a share mode of 0, you won't be able to open it again.
When you get the error you can use Process Explorer to determine what processes have the ... |
4,435,275 | 4,435,300 | How do you find a particular piece of functionality in a large codebase? | I was fascinated by the "press Tab to search site" feature in chromium, so naturally I wanted to see how exactly it was implemented in code.
A little background for anybody who aren't familiar with this. After navigating to some site, say wikipedia, and doing a search, chromium remembers the name of the query variable... | There is no one size fits all approach to this sort of problem. But for this one I would try these:
If there are any unique messages associated with the operation, grep all the source files for that string. A common pitfall of this technique is that messages might be assembled from pieces within the application, so ... |
4,435,456 | 4,435,491 | Makefile always thinks project is up to date - but files don't even exist | I have the following makefile:
CCC = g++
CCFLAGS = -ansi
driver: driver.o graph.o
$(CCC) -o driver driver.o graph.o
graph.o: graph.h
driver.o: graph.h
adjl:
rm -f graph.h graph.cc
ln -s adjl/graph.cc .
ln -s adjl/graph.h .
touch graph.cc graph.h
adjm:
rm -f graph.h gra... | The problem is that you have directory named the same as your targets in Makefile.
When you issue make adjl make checks for file adjl which it finds and does nothing.
Rename targets to something else and try again.
|
4,435,635 | 4,435,711 | c++ 2D array row sort based on average row value | Helo,
I'm wondering if there's any working method for this?
I'm trying make this work, but no luck.
int mat[3][3];
mat[0][0] = 4;mat[0][1] = 5;mat[0][2] = 3;
mat[1][0] = 3;mat[1][1] = 2;mat[1][2] = 1;
mat[2][0] = 1;mat[2][1] = 8;mat[2][2] = 9;
Any idea? :)
| You should create a temporary data structure that is an array of tuples. The tuples would be the row index and the average of that row index. Then sort this tuple array based on the average using the standard sort() function. Then, run through the sorted tuple array to recompute the sorted matrix.
This would give you p... |
4,435,911 | 4,435,963 | Passing Member Function Pointers Between Modules | Just a curiosity question! This seems to suggest that member function pointers are in fact different sizes pending compiler and compile options used, and this seems to suggest that function pointers are passed just fine between modules, so what about member function pointers? I mean with all the hassles that are alre... | If you use two different compilers, then unless they have compatible ABI (application binary interface), you cannot sensibly mix-and-match any object code created by them, whether or not member function pointers are involved.
|
4,436,083 | 4,437,545 | Why can't I call a class's start function from within itself? | I'm totally new to programming with threads, and since the class is using QThreads, I'm wondering why I cannot call a QThread's start function from within itself and have its run function start executing independently of another thread (the program seems to crash when I do this). Instead, I have to call the start funct... | QThread should be derived only if you want to extend thread capability, not to specialize it for your job like this. This article would help you to understand the use of QThread.
So you must create a QThread and start it from outside and then move an object to it that will do the job. Read this example: http://labs.qt.... |
4,436,805 | 4,436,845 | Does dereferencing a pointer make a copy of it? | Does dereferencing a pointer and passing that to a function which takes its argument by reference create a copy of the object?
| In this case the value at the pointer is copied (though this is not necessarily the case as the optimiser may optimise it out).
int val = *pPtr;
In this case however no copy will take place:
int& rVal = *pPtr;
The reason no copy takes place is because a reference is not a machine code level construct. It is a higher... |
4,436,820 | 4,488,901 | Multicast is not working on Windows Vista | While I try to Multicast something to range of IP in win XP , it works fine but while I run the same application on Win VIsta I am unable to multicast. Do I need to configure or add a publisher info for Win Vitsa?
Edit:
struct sockaddr_in staddr;
memset(&staddr, 0, sizeof(struct sockaddr_in));
staddr.sin_family... | Well after lotz of experiments I was not able to figure out why Multi casting was not working, and found out suddenly this is because Network Discovery was off on my Vista.
So If here what I did , Go to Control Panel->SetUp File Sharing(Under Network and Internet) ->Sharing and Discovery and then switch on or off the n... |
4,436,892 | 4,436,952 | How do I get a function to be called when a menu item is clicked? | In Qt, I have a menubar that looks something like this:
|File|
+-------------------+
|Do Something |
|Do Something Else |
+-------------------+
I have a function doSomething that I want to be called when the user clicks on the Do Something in the file menu, and a function doSomethingElse that I similarly want t... | Generally speaking, your menu items are QActions. Connect the QAction signal triggered() with the doSomething() that you want called.
This is a pretty full-fledged description of how this works. But this section of the address book tutorial is good for a quick explanation.
|
4,437,007 | 5,152,366 | how to create a QT plugin using Meego Touch Framework? | I'm new to QT plug ins and Meego Touch Framework. My goal is to be able to create a QT plug in that reads CSS files to customize any application loaded in a terminal. So if user wants to customize any application, all he has to do is create a css file and load it. Can somebody give me a jumpstart how to do this using M... | By default meegotouch does support "per application" stylesheets so if i understand your question, its already implemented.
|
4,437,042 | 4,437,103 | Second argument to std::vector | Looking at vector, I realized that I have never used the second argument when creating vectors.
std::vector<int> myInts; // this is what I usually do
std::vector<int, ???> myOtherInts; // but is there a second argument there?
Looking at the link above it says that it is for:
Allocator object to be used instead of con... | The default allocator, std::allocator<>, will handle all allocations made by std::vector<> (and others). It will make new allocations from the heap each time a new allocation is needed.
By providing a custom allocator, you can for instance allocate a big chunk of memory up front and then slice it up and hand out smalle... |
4,437,051 | 4,443,639 | Tools used for programming in Linux | I would like to start programming using the Linux operating system and all the free stuff out there.
What is the most common and the best language to use with Linux, C or C++ or C#?
What tools are similar to Turbo C, or Visual Studio in Windows?
| For the language it really depends what you want to do :
C is good for low level software, specially if performance is a priority, otherwise syntax can be painful for a first programming experience.
C++ is good for high level software and has a lot of good qualities that C misses (e.g. classes, operator/function overl... |
4,437,265 | 4,437,389 | C++ 'wrapper class' for XML library | So I've been attempting to create some classes around the xerces XML library so I can 'hide' it from the rest of my project the underlying xml library stays independent from the rest of my project.
This was supposed to be a fairly easy task, however it seems entirely impossible to hide a library from the rest of a pr... | I would recommend avoiding the wrapper in the first stage. Just make sure that the layers and their borders are clear, i.e. the network layer takes care of serializing/deserializing the XML, and from there on you only use your internal types. If you do this, and at a later stage you need to replace xerces with any othe... |
4,437,292 | 4,438,141 | how to get the header files for graphicsmagick | i am developing an image processing tool using QT. Am new to both QT & graphicsmagick(magick++) c++ library. i have planned to use c++ as my development language. can anyone suggest me how to get the graphicsmagick header files?
| You download the graphicsmagick package for your platform from sourceforge.
|
4,437,507 | 4,732,729 | Compiling C++ with Soundtouch | I am trying to write an application in C++ that uses soundtouch libraries. I am unable to figure out what library to use to link it with. Specifically, I am using SoundTouch.h.
I have this code compiled in C as well. The library I used then was lsoundtouch4c to link. I have not been able to find information on this a... | Code written in C++ that uses sound touch libraries can be linked using the following libraries:
/usr/local/lib
SoundTouch
So, the linking in a makefile will look something like this:
main: <some-dependencies>
g++ <your g++ options> <object files> -L/usr/local/lib -lSoundTouch
Sriram.
|
4,437,527 | 4,437,555 | Why do we use volatile keyword? |
Possible Duplicate:
Why does volatile exist?
I have never used it but I wonder why people use it? What does it exactly do? I searched the forum, I found it only C# or Java topics.
| Consider this code,
int some_int = 100;
while(some_int == 100)
{
//your code
}
When this program gets compiled, the compiler may optimize this code, if it finds that the program never ever makes any attempt to change the value of some_int, so it may be tempted to optimize the while loop by changing it from while(s... |
4,437,598 | 4,437,702 | What is the right way to include Qt headers? | So far I know several ways to #include Qt classes:
#include <QtModule>
This brings all classes of a specific module, for example QDomDocument, QDomElement, QDomNode and numerous others from #include <QtXml>.
#include <QClassName>
This adds declaration of a specific class one may want to use, e.g. QEvent, QStringList,... | As a rule, the more header files there are, the longer it takes the compiler to parse each module. (Obviously precompiled headers render some of this moot.) So you generally want to include the fewest header files necessary to build your app correctly.
If you are only using a few classes in a given compilation unit, ... |
4,437,688 | 4,437,705 | Linux system call getifaddr c++ | in my c++ application I've wrriten this code:
struct ifaddrs *ifap;
if (0 != getifaddrs(&ifap)) {
error = errno;
return -1;
}
addresses.clear();
for (struct ifaddrs *ifa = ifap; ifa; ifa = ifa->ifa_next) {
sockaddr *s=ifa->ifa_addr;
PRINT(" LocalIP sockaddr %u.%u.%u.%u \n",s->sa_data[2],s->sa_data[3],... | Change %d's to %hhu's.
%d is signed integer.
%u is unsigned integer.
%hhu is unsigned char.
This code shows why:
#include <cstdio>
int main()
{
char i = 192;
printf("%u, %hhu, %d", i,i,i);
}
Output: 4294967232, 192, -64
|
4,437,753 | 4,439,994 | How to optimize building speed in visual studio 2008 | Could someone give me tips to increase building speed in visual studio 2008?
I have a large project with many module with full source. Every single time it's built, every files are rebuilt, some of them were not changed. Can i prevent these file to be rebuilt?
I turned the property "Enable Minimum rebuild" /Gm on but t... | One simple way is to compile in debug mode(aka zero optimizations), this of course is only for internal testing.
you can also use precompiled headers* to speed up processing, or break off 'unchanging' segments into static libs, removing those from the recompile.
*with /MP you need to create the precompiled header befor... |
4,437,852 | 4,437,893 | C++: difference between 0. and 0.0? | I am well aware of the difference between 0 and 0.0 (int and double).
But is there any difference between 0. and 0.0 ( please note the . )?
Thanks a lot in advance,
Axel
| There is no difference. Both literals are double. From the C++-Grammar:
fractional-constant:
digit-sequenceopt . digit-sequence
digit-sequence .
See: Hyperlinked C++ BNF Grammar
|
4,437,862 | 4,437,976 | What's the advantage of multimap over map of vectors? | I don't understand why multimap exists if we can create map of vectors or map of sets.
For me only differences are:
using equal_range in multimap for getting elements of a key and in map of vectors we simply use [] operator and have vector of elements.
using multimap.insert(make_pair(key,value)) in multimap for adding... | I would say it depends on whether all the values with same key have a relationship that you want to address.
So for example, do you often go through all elements with key X, or pass them to a function, and so on? Then it is more convenient to already have them in their separate container, that you can address directly.... |
4,437,952 | 4,438,265 | What cause memory reservation | I have an application written in c++ that reserved 1.2GB memory but only 600MB are committed.
The application use COM/DCOM, ADO.
I would ask you if you have any idea why so many memory are reserved and never committed?
Thanks
| The application might intentionally reserve a large region for some allocator and only commit smaller regions as they are actually needed. If that's the case - they won't be committed until you make the application actually ask the allocator for memory allocation and it does commit memory.
|
4,437,954 | 8,489,438 | Access violation in MSVBVM60.dll with VB6 and C++ dll | I am investigating a crash of an application I am working on. The visual basic part is a simple form, which creates PictureBoxes and buttons. Calls are made to the C+ dll upon button clicks. The PictureBoxes provide handles to the DLL which uses them to create windows using WINAPI and displays in OpenGL.
Initially view... | From you text file:
(134c.1344): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=034b0ebc ebx=00000000 ecx=7352e100 edx=00000000 esi=02e6813c edi=02e6813c
eip=7349fdd2 esp=0012fc20 ebp=0012fc44 iopl=0 ... |
4,437,955 | 4,438,093 | AF_UNIX usage with SOCK_DGRAM creates a problem with the unix socket name length | my question is about IPC using AF_UNIX and SOCK_DGRAM.
my server code after removing some error checks from the code is:
sd = socket(AF_UNIX, SOCK_DGRAM, 0);
memset(&serveraddr, 0, sizeof(serveraddr));
serveraddr.sun_family = AF_UNIX;
strcpy(serveraddr.sun_path, SERVER_PATH);
length = BUFFER_LENGTH;
rc = setsocko... | I suspect the problem has to do with sizeof(struct sockaddr). On my system that allows 14 characters for the address field. Try sizeof(struct sockaddr_un).
|
4,438,084 | 4,439,209 | std::this_thread::sleep_for() and GCC | When I try to compile this simple program:
#include<thread>
void f() {
std::this_thread::sleep_for(std::chrono::seconds(3));
}
int main() {
std::thread t(f);
t.join();
}
with gcc version 4.4.3 on Ubuntu 10.04 (32 bit):
$ g++ -std=c++0x -pthread a.cpp -o a
I get:
error: ‘sleep_for’ is not a member of ‘std::thi... | Confirmed that it doesn't work here as well. (Recent GCC 4.6 snapshot).
You could do the obvious and simply define it before you include any std:: headers. A bit dirty but will work until GCC fixes it (unless this is intended behavior). The #define shouldn't break anything anyways. Either in source or -D_GLIBCXX_USE_NA... |
4,438,115 | 4,438,493 | Linux system call getname info return EAI_AGAIN | In my C++ application I use getnameinfo and it returns EAI_AGAIN - what causes this error?
struct sockaddr_storage ss;
socklen_t salen = sizeof(ss);
struct sockaddr *sa;
struct addrinfo hints, *paddr, *paddrp;
sa = (struct sockaddr *)&ss;
if (getpeername(sock, sa, &salen) != 0) {
error = errno;
return -1;
}
... | According to getnameinfo:
[EAI_AGAIN] The name could not be resolved at this time. Future attempts may succeed.
The most likely reason would be some kind of timeout during the DNS lookup.
|
4,438,281 | 4,438,384 | Calling a function overloaded in several namespaces from inside one namespace | I have the following code snippet:
void foo(double a) {}
namespace bar_space
{
struct Bar {};
void foo(Bar a) {}
}
foo(double) is a general function from a library.
I have my own namespace bar_space with my own struct, Bar. I would like to implement an overloading of foo() for Bar, thus making Bar more similar t... | In C++, there is a concept called name hiding. Basically, a function or class name is "hidden" if there is a function/class of the same name in a nested scope. This prevents the compiler from "seeing" the hidden name.
Section 3.3.7 of the C++ standard reads:
A name can be hidden by an explicit
declaration of tha... |
4,438,511 | 4,439,283 | Protected External Resource Usage | I'm working with some code where I have the following setup.
struct data
{
void change_safe_member(){}
void read_data(){}
void change_unsafe_member(){}
};
struct data_processor
{
std::shared_ptr<data> get_data(){}
void return_data(std::shared_ptr<data> my_data)
{
my_data->ch... | You can make this happen with inheritance.
struct Y;
struct X {
friend struct Y;
private:
change_unsafe_member() {}
};
struct Y {
protected:
change_unsafe_member(X& x) { x.change_unsafe_member(); }
};
struct some_other : Y {
X x;
change_safe_member() { change_unsafe_member(x); }
};
Any class that i... |
4,438,540 | 4,438,570 | Error compiler, cannot convert parameter 2 from MyStruct1 to const void*, for memcpy | I am trying to copy the data from on structure to another. The bytes are identical that each struct can handle are the same. My declarations and the memcpy are below:
typedef struct{
CString strNumber;
CString strAlpha;
} _Number;
typedef struct{
CString strIterration;
_Num... | You need to use & on both structs:
memcpy(&Data2, &Data1, sizeof(_Store));
Beware: _Store contains CString member variable which (if it is like MFC CString) is not bitwise copyable. You should only use memcpy() on types that are bitwise copyable, otherwise you risk running into undefined behavior.
|
4,438,977 | 4,439,101 | Which protobuf optimization? | Using google's protocol buffer compiler for c++ its not clear which is faster: optimize for speed:
option optimize_for = SPEED;
or optimize for light runtime:
option optimize_for = LITE_RUNTIME;
if speed is faster, what makes it faster?
does anyone have hard data on the subject?
| The way I read the documentation,
optimize for CODE_SIZE does not generate fast accessor methods for everything, but relies on slow reflection,
optimize for SPEED will give you the fast accessors
and optimize for LITE_RUNTIME will also give you fast accessors, but does not support the full functionality of protobuf, ... |
4,439,011 | 4,439,030 | Packet logging on windows | Are there any methods to log incoming packets other than wincap?
| Netmon is a free download.
Network Monitor 3.4 is a protocol
analyzer. It allows you to capture
network traffic, view and analyze it.
|
4,439,022 | 4,439,070 | Is it possible to define a function pointer to a constructor? | I'm using shared library with explicit linking (loading shared lib with dlopen) in order to implement plugin pattern in C++.
Is it possible to define a function pointer to a constructor of a class defined in the shared library or I would have to define factory method, within shared lib, that would instantiate (and in... | The answer to the question is no, you can not define a member or function pointer to the constructor.
For dlopen, you need to provide a function with c linkage and load it dynamically, which you can use to create the objects, and you also need another function to delete objects.
More about it here
|
4,439,096 | 4,439,284 | C++ Template : Choosing overloaded functions using implicit conversion to template instantiated type! | Consider these overloaded functions,
void fun(Int2Type<1>) {}
void fun(Int2Type<2>) {}
void fun(Int2Type<3>) {}
void fun(Int2Type<4>) {}
I want to call these in this way,
fun(1); // this should call first function
fun(4); // this should call fourth function
Is there a way to do that? If yes, so can we do the same wit... | You can do it a little differently:
template<int N> void func();
template<> void func<1>(){/*the body*/}
template<> void func<2>(){/*the body*/}
And then you may call: func<1>().
Or you may call the original code this way: func(Int2Type<1>()).
Anyway all of this only works with compile time constants.
|
4,439,127 | 4,439,202 | Better way to structure/new keyword | Some time ago I came across the following construct which I have rarely seen since, though I use it relatively frequently. I use it typically when checking on a whole list of conditions are true and it prevents large levels of indentation. Essentially it uses a for loop to provide a kind of structured goto. My quest... | I don't think it's the most readable way of doing it. Chained if-else if looks much better. But if you want to stick with it and don't want to be so close to an infinite loop, you could do something like this:
do
{
if (...)
break;
...
} while (false);
|
4,439,214 | 4,439,240 | OpenGL glTranslate and glRotate | I need a function that applies a translation like glTranslate() to a point.
Does someone know of a function like glTranslate() and glRotate() to modify and retrieve a matrix to multiply?
| There are thousands of free matrix classes out there. Have a hunt round google and then you can set up a translation and rotation without using the gl* functions at all ...
edit: If you really just want to create the matrix without using a more than handy matrix class then you can define glRotatef( angle, x, y, z ) a... |
4,439,273 | 4,439,330 | How does this reinterpret_cast work? (Porting C++ to Java) | I have some C++ code I'm trying to port to Java, that looks like this:
struct foostruct {
unsigned char aa : 3;
bool ab : 1;
unsigned char ba : 3;
bool bb : 1;
};
static void foo(const unsigned char* buffer, int length)
{
const unsigned char *end = buffer + length;
while (buffer < end)
{
... | its basically saying the 8 bits represented at the current pointer should be interpreted as a "foostruct".
In my opinion it would be better written as follows:
const unsigned char aa = *buffer & 0x07;
const bool ab = (*buffer & 0x08) != 0;
const unsigned char ba = (*buffer & 0x70) >> 4;
const bool bb ... |
4,439,375 | 4,439,675 | Finding memory violations/leaks | I have an application developed in VC 2008 (C++) which uses axis dlls, which use openssl dlls. And someone in the chain corrupts heap - a situation which ends up giving me "memory access violation" in my application in places where violation shouldn't/couldn't happen. So, someone in the chain axis-ssl corrupts somethin... | If you get the debug versions of the libraries, MSVC offers a debug malloc and free, as well as a debug new and delete. These contain things like overwrite detection.
http://msdn.microsoft.com/en-us/library/bebs9zyz.aspx
|
4,439,493 | 4,440,017 | C++ Qt editor question | I have the case when I have to manually close the persistent editor for the QTableWidget.
By default, closing the editor this doesn't result in saving the changes to the QTableWidgetItem (it simply discards them).
I wish to save these changes along with the closePersistentEditor call - how should it be done?
I tried e... | Looks like you can write something like this
void MyTableWidget::commitAndClosePersistentEditor(const QTableWidgetItem* item)
{
if (!item)
return;
QModelIndex index = indexFromItem(item);
QWidget* editor = indexWidget(index);
commitData(editor);
closePresistentEditor(item);
}
|
4,440,165 | 4,440,217 | Partial Specialization of Operator() | One of my classes declares a templated function:
template<class A, class B>
A do_something(const std::vector<B> &data)
which I'd like to partially specialize on typename A. B is a family of types that implement a pretty minimal interface, and we use a lot of them, so I'd like my specialization to be generic on B. I su... | Usually, it goes like this:
template <typename A, typename B>
struct DoSomethingHelper
{
static A doIt(const std::vector<B> &data);
};
template <typename B>
struct DoSomethingHelper<double, B>
{
static double doIt(const std::vector<B> &data) { ... }
};
template <typename B>
struct DoSomethingHelper<int, B>
{
... |
4,440,296 | 4,440,331 | What case is better? | I have a list of MyClass:
struct MyClass {
bool is_old_result(int lifetime);
};
std::list<MyClass> results;
int lifetime = 50; // or something else
What case of removing is better (c++ design and perfomance):
results.remove_if(
std::bind2nd(std::mem_fun_ref(&MyClass::is_old_result), lifetime));
or
results.re... | In terms of design, the one using bind is definitely the clearest. (followed by the explicit function object). Why? Succinct.
In terms of performance, the function object should be unbeatable (everything can be easily analysed and inlined). Depending on how the compiler optimizes, the one using bind could possibly matc... |
4,440,769 | 4,441,291 | build managed c++ project in .net 3.5 using vs2010 (msbuild4) | Is it possible to build a managed c++ project in .net 3.5 using vs2010 ?
There are different opinions around but I haven't being able to do this. Any ideas?
| The build system for VS2010 was dramatically changed and only directly supports building for 4.0. Targeting 3.5 requires having VS2008 on your machine. More about this in this answer.
|
4,440,770 | 4,441,236 | Problems Building Application as Release in Visual Studio 2008 - C++ | I'm having a little trouble building my application as Release in Visual Studio 2008. It builds fine without any errors or warning as Debug. The application is primarily Win32 with a little MFC and ATL mixed in here and there. Most of the projects in the solution generate a LIB and DLL.
This is one of the errors I a... | The project property changes you've made to get it to build in the Debug configuration are not automatically applied to the Release configuration as well. Note the "Configuration" combo in the upper left corner of the dialog. Altered property values are shown in bold type.
If you cannot remember what changes you've m... |
4,440,887 | 4,441,240 | Given an array of uint8_t what is a good way to extract any subsequence of bits as a uint32_t? | I have run into an interesting problem lately:
Lets say I have an array of bytes (uint8_t to be exact) of length at least one. Now i need a function that will get a subsequence of bits from this array, starting with bit X (zero based index, inclusive) and having length L and will return this as an uint32_t. If L is sma... | Only the first and last bytes in the subsequence will involve some bit slicing to get the required bits out, while the intermediate bytes can be shifted in whole into the result. Here's some sample code, absolutely untested -- it does what I described, but some of the bit indices could be off by one:
uint8_t bytes[];
i... |
4,441,110 | 9,227,915 | How do I resolve xsl:include directives in c++ (can't use .NET framework) | I need to load an xslt from a database and hold it in memory so that it can be included by another xslt.
I know you can do this using the .NET framework and the xmlPreLoadedResolver class, but unfortunately, we're not allowed to write this as a .NET dll.
Does anyone know if its possible to do this using the msxml6 C+... | In the end, the only way we could find to get around this was to write some code on loading the top-level xslts which could load up all the dependencies and 'explode' them into the main xslt. These exploded xlsts are then held in memory as required..
|
4,441,342 | 4,441,502 | feof() returning true when EOF is not reached | I'm trying to read from a file at a specific offset (simplified version):
typedef unsigned char u8;
FILE *data_fp = fopen("C:\\some_file.dat", "r");
fseek(data_fp, 0x004d0a68, SEEK_SET); // move filepointer to offset
u8 *data = new u8[0x3F0];
fread(data, 0x3F0, 1, data_fp);
delete[] data;
fclose(data_fp);
The problem ... | Opening a file in text mode, like you're doing, makes the library translate some of the file contents to other stuff, potentially triggering a unwarranted EOF or bad offset calculations.
Open the file in binary mode by passing the "b" option to the fopen call
fopen(filename, "rb");
|
4,441,666 | 4,442,117 | TRACE Macro Not Compiled Out Properly in Release Build - C++ | When I do a Release build of my Visual Studio 2008 solution I get a bunch of errors like this:
error C2059: syntax error : ','
This is how I typically use TRACE:
TRACE(_T("My error message.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
There is also an instance where I use... | The definition of your __WFILE__ macro is causing the problem. There are two ways to solve this. First, you can define the macro as shown here:
http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx
Note they don’t wrap the macro in #ifdef _DEBUG, which makes sense since the corresponding __FILE__ macro is not ... |
4,441,688 | 4,441,720 | Mixed project solutions in VS2010- managed and native | I've been writing a program that serves in two primary parts- managed UI and native back-end (C# and C++). However, suddenly, Visual Studio thinks that when I try to run the solution, I'm tryng to run the native back-end (a DLL) and throws an error. When I start the exe manually, it won't break on my breakpoints, and s... | It sounds like you just need to set the managed project as the startup project in Visual Studio.
Open Solution Explorer
Right click on the project and select "Startup Project"
|
4,441,797 | 4,441,829 | implementing an abstract base class function in another template base class | I have a Visual Studio 2008 C++ project where I have a class that inherits from an abstract base class and another template class that implements a function in the abstract base class. For example:
class Foo;
struct Buzz
{
virtual ~Buzz() {};
virtual void Buzz_Do( Foo* ) = 0;
};
class Base
{
public:
virtu... | If possible let the Bar<> derive from Base,
and Foo derive only from Bar<T>.
|
4,441,879 | 4,442,000 | Curious behaviour of std::string::operator[] in MSVC | I've been using some semi-iterators to tokenize a std::string, and I've run into a curious problem with operator[]. When constructing a new string from a position using char*, I've used something like the following:
t.begin = i;
t.end = i + 1;
t.contents = std::string(&arg.second[t.begin], &arg.second[t.end]);
where a... | You're not taking a pointer to one past the end, you're ACCESSING one past the end and then getting the address of that. Entirely different and while the the former is well defined and well formed, the latter is not either. I suggest using the iterator constructor, which is basically what you ARE using but do so with... |
4,442,157 | 4,442,452 | How to initialize msvcrt.dll? | If I do a LoadLibrary("msvcrt.dll") do I need to initialize the CRT somehow? Section 2 in the following document seems to say that I do, but I just get an undefined symbol error for _CRT_INIT when I try to call _CRT_INIT:
http://support.microsoft.com/kb/94248
Edit: I should have said that this is for a program that dyn... | If you're working in C++, have you declared _CRT_INIT as extern "C"?
Have you tried using the DUMPBIN utility ( http://support.microsoft.com/kb/177429 -- if you haven't your PATH up yourself, you'll have to use the Visual Studio Command Prompt I think) with the /EXPORTS switch to see which functions are available from ... |
4,442,474 | 4,442,609 | Sharing a struct safely amongst multiple threads | Under Windows/C++, if I have a struct:
struct ListItem {
ListItem* next;
ListItem* prev;
...
}
together with multiple threads running in both the main process and in several dynamically loaded DLLs, and all of those threads need to share the above struct, how do I stop them stomping on each other? Somethin... | There are two main ways. One, possibly the simplest, is to simply send each thread it's own copy of the data structure. This way you won't have to use synchronization to protect the data, since no thread shares another thread's data.
But that won't work in a lot of situations. Sometimes you really do need to share a... |
4,442,477 | 4,442,491 | Remove ith item from a C++ std::vector | How do I remove the ith item from a std::vector?
I know I want to delete the ith element. I have int i; and std::vector<process> pList; where process is a struct. I want to do something equivalent to the following:
pList.remove(i);
| pList.erase(pList.begin()+i);
To remove element with index i.
|
4,442,597 | 4,442,654 | How do you call a function once a day at a certain time in c++? | Well i need to figure out how to call a function at a certain time if my application is running.
it will probably be in a while loop and check the time but i don't want it to check the time every minute but i don't want it to miss the exact time, say 18:00.
is there any way do to this?
| EDIT: I don't know why I assumed this was Windows. I don't see anywhere that it says so. The API info below is only applicable for Windows but the principle is the same. Boost.Asio has portable async timers, if not Windows.
Windows Info : When your app starts up, check the interval remaining to your desired event an... |
4,442,658 | 4,442,669 | c++ parse int from string |
Possible Duplicate:
How to parse a string to an int in C++?
I have done some research and some people say to use atio and others say it's bad, and I can't get it to work anyways.
So I just want to ask flat out, whats the right way to convert a string to a int.
string s = "10";
int i = s....?
Thanks!
|
In C++11, use std::stoi as:
std::string s = "10";
int i = std::stoi(s);
Note that std::stoi will throw exception of type std::invalid_argument if the conversion cannot be performed, or std::out_of_range if the conversion results in overflow(i.e when the string value is too big for int type). You can use std::stol o... |
4,442,680 | 4,442,747 | Prgrammably making excel spreadsheets (97 - 2003 format) | I was wondering how difficult it would be to make an application like this. Basically, I have some old html files that use tables. I want to put these tables into excel for easier reading and manipulation. I only have text, I have no numbers of formulas or anything.
Are there any tutorials on how to do this sort of thi... | You have three options:
Output a CSV file. While not an XLS file, Excel is more than capable of opening such a file, and it's extremely easy to create. You need nothing more than standard C++ to implement this solution. This is by far the easiest and quickest way to output to Excel (or any spreadsheet program, for tha... |
4,442,934 | 4,443,495 | acquire-release pair out of order execution | I'm thinking of whether or not it is possible for atomic variable to load the old value in acquire-release pair.
Let's suppose we have atomic variable x, and we store that variable with release semantics and later load it with acquire semantics is it possible in theory to read the old value?
std::atomic<int> x = 0;
vo... | You might consider store/load functions with release/acquire memory order as the following pseudo-code:
template<class T>
struct weak_atomic
{
void store(T newValue)
{
ReleaseBarrier();
m_value = newValue;
}
T load()
{
T value = m_value;
AcquireBarrier();
return value; ... |
4,442,985 | 4,443,203 | Qt: Does a QReadWriteLock work as shown? | I have four threads that need to be syncronized. In order to achieve this, I am looking to pass each thread the same bool array. Each thread will change the 'corresponding' value to true once it has reached a certain point in the thread, then constantly check to see if the rest of the values are true. If so, enter the ... | No the QReadWriteLock doesn't do exactly what you want to do, after reading your comment above you really dont need any lock for writting data, you just need to assure that the reads are volative on your array. If you need the threads to run at the same time why not a count down latch? That ensures that all threads (po... |
4,443,702 | 4,443,809 | c++ How could I properly predefined array of char*? | I am doing it that way:
int argc = 9;
char* argv[argc];
argv[0] = "c:/prog.exe";
but I get notice, that it is deprecated. What is better way?
| You have to either make it const:
const char *argv[] = { "Arg1", "Arg2", "..." };
... or not use the constant string literals:
int argc = 9;
char* argv[argc];
char prog_name[] = "c:/prog.exe";
argv[0] = prog_name;
|
4,443,756 | 4,443,827 | Importing Function From Unmanaged DLL in C# Application | I need to import a function that I wrote in C++, and is now compiled into a DLL, into my C# application. Everything builds without errors or warnings, but when I step through the code the first function call into the DLL throws an Exception with a message of "Unable to find an entry point named 'CreateScanEngine" in D... | Don't use Dependency Walker, it unmangles the exported name of the function and doesn't tell you the real export name. Note that it is smart enough to see that it takes no arguments and has no return value. It can only do this if it sees the name as decorated by the C++ compiler.
Use Dumpbin.exe /exports on the DLL t... |
4,443,988 | 4,444,099 | Forcing the Qt GUI to update | I am coding a boardgame in Qt where, after the player makes a move, the computer AI must pause and think for some time. However, while it is thinking, it seems the screen will not be updated until every line of code has been executed. Thus, the user would click on a square, see nothing happen for a few seconds, and the... | The cause of the crash can be a variety of reasons but if I had to take a guess I'd say you're probably calling methods of a GUI object (label, textbox, your game board, etc.) from the AI thread.
The way threads communicate with one another in Qt is through a mechanism called signals and slots: the AI thread should exp... |
4,444,010 | 4,444,321 | Calling C++ member functions with the thiscall convention | I have an application written in C++ that loads my DLL that is written in Delphi. The application calls an exported function of the DLL and passes it a pointer to an object of a class that has several member functions that I want to call from my Delphi DLL. I have written a Delphi class equivalent of the C++ class:
CCl... | The asm looks fine, that's how we call a thiscall interface. But this is a class. I don't think there's any reason to assume CClass.A actually calls void A(int). You'd have to figure out the correct offset. Having a Delphi class won't help I think: you should find out the offsets in C++, add that offset to ptr and call... |
4,444,083 | 4,444,401 | How to Divide Control Class into Implementation vs. Public Interface? | I've created an MFC control class, which I derived from CWnd.
The control is written from scratch and does not use any child controls. This single class implements all the control logic, including state maintenance, painting, responding to events, etc.
In addition, I need a more "public" interface to be used by the cod... | You might try splitting the class in two, with the more complicated implementation class being a child of the public class.
Ordinarily I'd suggest making a separate pure virtual interface class and using multiple inheritance to connect it to MFC, but I'm guessing you'll want to be able to use the standard CWnd methods ... |
4,444,088 | 4,444,114 | Does Boost or STL provide a functionlity similar to QString? | Using QString, one can do the following:
QString const sentence = QString("First name: %1, Last name: %2")
.arg("John")
.arg("Doe");
// sentence is now "First name: John, Last name: Doe"
Does Boost / STL have something similar? I would like to construct a string ... | Seems like you want boost.format
|
4,444,090 | 4,444,102 | Measuring time with a resolution of microseconds in C++? | I'm looking for a way to measure microsecs in C++/Windows.
I read about the "clock" function, but it returns only milliseconds...
Is there a way to do it?
| Use QueryPerformanceCounter and QueryPerformanceFrequency for finest grain timing on Windows.
MSDN article on code timing with these APIs here (sample code is in VB - sorry).
|
4,444,098 | 4,444,159 | Trouble getting working directory | This is how I am trying to get the current working directory:
char* ch;
if( (ch = _getcwd( NULL, 0 )) == NULL )
{
cout << "Could not get working directory!" << endl;
}
// skonvertujme char* na string, s tym sa nizsie bude lahsie pracovat
stringstream ss;
string workingDirectory;
... | The >> operator stops at the first space. Instead of the stringstream manipulation try
string workingDirectory(ch);
|
4,444,214 | 4,444,297 | Am I marshalling this C function correctly in C#? | In C#, I am trying to PInvoke the following C method:
// C code:
BOOL VstSetLineDetail(
tVstHdl pDataHdl, // type is void*
long pLineItemNo,
tVstTransType pTransType, // enum type
tVstTransSubType pTransSubType, // enum type
tVstTransCd pTransCd, // enum type
char *pTransDate,
tVstTaxedGeo *pTaxe... | No, it's not right, because long in C isn't 8 bytes like it is in C# (it's often 4 bytes). Also, a char* isn't necessarily a string, because strings are meant to be immutable, and you can only safely marshal them to const char*, since only that can guarantee that the C code won't modify them. If you need to make them m... |
4,444,293 | 4,444,510 | Registering callbacks from text configuration file | I have a general problem where I have an array of function pointers. The challenge is to bind the functions to locations in the array based on a text configuration file. Is there a better way to do this than a gigantic if-else-else-...-else block?
Is it easier to implement functors and bind locations to instances of ... | Assuming a file format like
a
c
a
b
this should parse it and put function pointers into a std::vector accordingly:
// Beware, untested code ahead!
typedef void (*func_t)();
typedef std::map<std::string, func_t> func_map_t;
typedef func_map_t::value_type func_map_entry_t;
void f1() {}
voi... |
4,444,427 | 4,444,447 | Variable name from template argument? | Is there any way to generate the name of a variable inside a class based on a template argument?
template<class T, (someconstruct) t>
class Item {
public:
T t;
};
Item<float, "Position"> myItem;
myItem.Position = 0.123f;
Such that what I have instantiated is a variable of type T, with the identi... | No, you can't achieve this with templates. Variable names (known as "identifiers") cannot be programatically manipulated by templates. Only the preprocessor can do that.
Regardless, this seems like a bad idea. Why do you want to do this?
|
4,444,486 | 4,444,552 | Replace backward slashes with forwards slashes or double backward slashes in C++ | So I have a string:
string path = "C:\Users\Richard\Documents\Visual Studio 2010\Projects\Client\Debug";
I want to replace all backward slashes in it with forward ones so it looks like:
C:/Users/Richard/Documents/Visual Studio 2010/Projects/Client/Debug
This does not work:
string toReplace = "\\";
path.replace(path.f... | I get a compiler error on your path string with g++, since it contains invalid escape codes. Apparently, MSVC produces warnings but no errors for that (see Michael Burr's answer). So if you are really using the path you have posted, change the backslashes to double backslashes.
Correcting that, I find that your code re... |
4,444,692 | 4,451,616 | Linking against clang-llvm | I've been working on a small tool with clang/llvm but I haven't been able to successfully get g++ and gnu's linker to properly link my code against clang.
my linker is generating the following errors:
undefined reference to `clang::FileManager::~FileManager()'
undefined reference to `clang::FileManager::FileManager()'... | When I've built some stuff against llvm / clang, this is what I've used to build it. Perhaps you can compare the two build lines.
Also, the llvm-config command I've used has been: llvm-config --cxxflags --ldflags --libs backend.
Finally, this is likely partially related to an ordering issue. You probably want to includ... |
4,444,694 | 4,444,833 | Best way of adding SNMP support to your own application on Debian | I am working on Debian and I have this server we want to monitor.
The application is ours and there are around a hundred real-time counters we want to export for monitoring purposes, graphs and alarms.
I've been looking at the Debian way of doing this because we do use Debian packaging to install the app, and Debian ... | net-snmp supports both the smux and agentx agent extension protocols, allowing sub-agents to live in different processes. They also have a tutorial on writing AgentX subagents in C.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.