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 |
|---|---|---|---|---|
1,262,404 | 1,330,801 | Access Motherboard information without using WMI | I need to access motheroard identification (serial, manufacture, etc) in my application on multiple processes. I have been able to successfully query this using WMI, but I'm looking for an alternative.
If you care to know situation:
I have some application behavior that is different depending on the hardware configura... | Apparently there is no way to do this, which is unfortunate.
|
1,262,715 | 1,262,750 | Reading std::string from binary file | I have a couple of functions I created a while ago for reading and writing std::strings to a FILE* opened for reading in binary mode. They have worked fine before (and WriteString() still works) but ReadString() keeps giving me memory corruption errors at run-time. The strings are stored by writing their size as an uns... | Biggest major problem that jumped out at me:
// Create a char pointer for temporary storage.
char* text = new char;
// ...
// Read [size] number of characters from the string and store them in text.
fread(text, 1, size, t_fp);
This creates text as a pointer to a single character, and then you try to read an arbitrary ... |
1,262,808 | 1,263,122 | Which STL container should I use for a FIFO? | Which STL container would fit my needs best? I basically have a 10 elements wide container in which I continually push_back new elements while pop_front ing the oldest element (about a million time).
I am currently using a std::deque for the task but was wondering if a std::list would be more efficient since I wouldn'... | Since there are a myriad of answers, you might be confused, but to summarize:
Use a std::queue. The reason for this is simple: it is a FIFO structure. You want FIFO, you use a std::queue.
It makes your intent clear to anybody else, and even yourself. A std::list or std::deque does not. A list can insert and remove anyw... |
1,262,859 | 1,262,883 | Intercepting mouse clicks when the mouse is hovering above a control | I'm working on a MFC C++ dialog where I need to respond to right mouse click events for a dialog even if the mouse is hovering over a control.
I could write event handler code for each control to delegate the work to the parent dialog, but I'm hoping there is a more elegant solution?
I'm hoping there is some way to int... | You could set up a hook to intercept mouse messages. Take a look at SetWindowsHookEx and WH_MOUSE
|
1,263,292 | 1,263,324 | multidimensional array in C++ hang | I wanna to declare an array:
int a[256][256][256]
And the program hang. (I already comment out all other codes...)
When I try int a[256][256], it runs okay.
I am using MingW C++ compiler, Eclipse CDT.
My code is:
int main(){
int a[256][256][256];
return 0;
}
Any comment is welcomed.
| This might happen if your array is local to a function. In that case, you'd need a stack size sufficient to hold 2^24 ints (2^26 bytes, or 64 MB).
If you make the array a global, it should work. I'm not sure how to modify the stack size in Windows; in Linux you'd use "ulimit -s 10000" (units are KB).
If you have a go... |
1,263,447 | 1,263,463 | Copying C-Style String to Free Store Using Only Dereference | As said in the title, the goal is to copy a C-style string into memory without using any standard library functions or subscripting.
Here is what I have so far [SOLVED]
#include "std_lib_facilities.h"
char* strdup(const char* p)
{
int count = 0;
while (p[count]) ++count;
char* q = new char[count+1];
fo... | C-style string ends with '\0'. You need to traverse the string inside the function character by character until you encounter '\0' to know how long it is. (This is effectively what you would do by calling strlen() to work it out.) Once you know how long the string is, you can allocate the right amount of memory, which ... |
1,263,521 | 1,263,529 | What is #pragma used for? | Can anyone help me understand #pragma?
ifndef TARGET_OS_LINUX
#pragma once
endif
What,when, where, why, an example?
The above is in some code that I am refactoring....
| #pragma is just the prefix for a compiler-specific feature.
In this case, #pragma once means that this header file will only ever be included once in a specific destination file. It removes the need for include guards.
|
1,263,599 | 1,263,627 | GDI+ leaks memory when deleting pointers as GdiplusBase*? | I'm trying to work with GDI+ and I'm running into a weird memory leak. I have a vector of GdiplusBase pointers, all of them dynamically created. The odd thing is, though, is that if I try to delete the objects as GdiplusBase pointers, e.g.,
vector<GdiplusBase*> gdiplus;
gdiplus.push_back(new Image(L"filename.jpg"));
de... | I would imagine the problem is that GdiplusBase does not have a virtual destructor, and thus when you call delete like that, no destructor is called. And the destructor of Image is likely releasing some other resources (such as bitmap handles etc). So the memory for the Image object itself is freed correctly, but other... |
1,263,607 | 1,263,619 | C, C++ preprocessor macro | Can anyone please explain how this works
#define maxMacro(a,b) ( (a) > (b) ) ? (a) : (b)
inline int maxInline(int a, int b)
{
return a > b ? a : b;
}
int main()
{
int i = 1; j = 2, k = 0;
k = maxMacro(i,j++); // now i = 1, j = 4 and k = 3, Why ?? Where is it incremented ?
//reset values
i = 1; j = 2, k =... | The issue is the preprocessor does just straight text substitution for macros.
maxMacro(i, j++)
becomes
( (i) > (j++) ) ? (i) : (j++)
As you can see, it does two increments when j is greater.
This is exactly why you should prefer inline functions over macros.
|
1,263,825 | 1,264,004 | Is this valid C++ code? | I had the following code, which was basically,
class foo {
public:
void method();
};
void foo::foo::method() { }
I had accidentally added an extra foo:: in front of the definition of foo::method. This code compiled without warning using g++(ver 4.2.3), but errored out using Visual Studio 2005. I didn't have a... | If I read the standard correctly, g++ is right and VS is wrong.
ISO-IEC 14882-2003(E), §9.2 Classes (pag.153): A class-name is inserted into the scope in which it is declared immediately after the class-name is seen. The class-name is also inserted into the scope of the class itself; this is known as the injected-class... |
1,263,899 | 1,263,910 | Where do you track the developments of new c++ standards? | Where do you guys generally look for developments in C++, most importantly, developments in new standard and its approx/scheduled release data? also boost (well, boost.com)
Is there a centralized place?
thx
| C++ has been updated much here lately. I would recommend wikipedia's article on C++ though. It usually is kept up to date (not that a lot's changed). I guess the closest thing to a specification that I've found is Bjarne Stroustrup's book (the creator of the C++ language) on, what else, the C++ language.
|
1,264,052 | 1,264,055 | How to determine whether it is EOF when using getline() in c++? | string s;
getline(cin,s);
while (HOW TO WRITE IT HERE?)
{
inputs.push_back(s);
getline(cin,s);
}
| Since I'm too lazy to give a full answer today, I'll just paste what the really useful bot in ##c++ on Freenode has to say:
Using "while (!stream.eof()) {}" is almost certainly wrong. Use the stream's state as the tested value instead: while (std::getline(stream, str)) {}. For further explanation see http://www.parash... |
1,264,059 | 1,264,344 | In C++, what is the difference between 1 and 1i64? | I'm converting some 32-bit compatible code into 64-bit - and I've hit a snag. I'm compiling a VS2008 x64 project, and I receive this warning:
warning C4334: '<<' : result of 32-bit shift implicitly converted to 64 bits
(was 64-bit shift intended?)
Here's the original line of code:
if ((j & (1 << k)) != 0) {
And here... | 1 has type int according to C++ Standard. On 64-bit Microsoft compiler int has sizeof = 4 bytes, it means that int is 32-bit variable. 1i64 has type __int64.
When you use shift operator the type of the result is the same as the type of the left operand. It means that shifting 1 you'll get 32-bit result. Microsoft comp... |
1,264,405 | 1,264,416 | error: non-lvalue in unary `&' in C++ | We are using a macro wrapper to Bind Where Parameter function.
#define bindWhereClause(fieldName, fieldDataType, fieldData) _bindWhereClause(fieldName, fieldDataType, sizeof(fieldData), &fieldData)
void _bindWhereClause(const char *name, int dataType, int dataSize, void *data)
{
// Implementation
}
Database.bindWhe... | You can't take the address of the return value of a function - it is ephemeral.
You need to use a real variable:
Nametype first_name = name.getFirstName();
Database.bindWhereClause( "FIRST_NAME", SQL_VARCHAR, first_name);
// ... and maybe name.setFirstName(first_name); here
Using an inline function would make it comp... |
1,264,596 | 1,264,744 | Decode WMA with FFMpeg to PCM | I want to decode a WMA stream to 16 Bit PCM. Now i have a Question concerning FFMpeg- what is the output format of ..
len = avcodec_decode_audio2(c, (int16_t *)outbuf, &outbuf_used, inbuf_ptr, size);
is this the right function for this task?
Thank you
| A remark : try to ask this question on ffmpeg user list. You will certainly find ffmpeg gurus there.
I mainly use ffmpeg to encode/decode video. To decode, the "avcodec_decode_*" are the right things to use for ... decoding. What you get is ... 16 bits PCM.
What I mean is that decoding a multimedia stream can be trick... |
1,264,723 | 1,265,960 | How to add menu command handler in VC 2008? | how to add a menu command handler in vc 2008?
| Is this a trick question?
alt text http://img197.imageshack.us/img197/5603/93284930.png
|
1,265,099 | 1,265,678 | How to find if an document can be OPENed via ShellExecute? | I want to check if a particular file can be successfully "OPEN"ed via ShellExecute, so I'm attempting to use AssocQueryString to discover this.
Example:
DWORD size = 1024;
TCHAR buff[1024]; // fixed size as dirty hack for testing
int err = AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".mxf", NULL ,buff , &size);
openActi... | I always use FindExecutable() to get the registered application for a given document.
|
1,265,338 | 1,436,355 | How to retrieve cookies for a specific site and path in winhttp | I would like to retrieve the cookies stored in the winhttp session cache based upon a specific host and path that I am about to send a request to. I want to retrieve those cookies before I send the request, so I don't have the request handle yet, all I have is the session and connection handles and of course the path a... | Use the WINHTTP_CALLBACK_STATUS_SENDING_REQUEST notification as a chance to inspect the cookie headers winhttp put by default on the request and then add the md5 header before returning from the callback.
|
1,265,354 | 1,265,424 | How to design a state machine in face of non-blocking I/O? | I'm using Qt framework which has by default non-blocking I/O to develop an application navigating through several web pages (online stores) and carrying out different actions on these pages. I'm "mapping" specific web page to a state machine which I use to navigate through this page.
This state machine has these transi... | Sounds like you want the state machine to have an event queue. Queue up the events, start processing the first one, and when that completes pull the next event off the queue and start on that. So instead of the state machine being driven by the client code directly, it's driven by the queue.
This means that any logic w... |
1,265,574 | 1,266,739 | #define _AFX_NO_DEBUG_CRT causes a stream of compilation errors | I have an MFC C++ project compiler under Visual Studio 2008.
I'm adding a _AFX_NO_DEBUG_CRT in my stdafx.h before the #include to avoid all the debug new and deletes that MFC provides (I wish to provide my own for better cross platform compatibility).
However when I do this I get a stream of errors such as the follo... | I've come up with one method which involves using the /FORCE:MULTIPLE command line to force it to use mine instead of the MFC one. It all seems to be working quite nicely. I can, now, even track "mallocs" and "new"s performed by functions not owned by me :)
If anyone has any better solutions then please post them but... |
1,265,650 | 1,265,817 | What is a callback? What is it for and how is it implemented in for example C++ | I realise this is a newbie question, but as I'm trying to learn C++ I'm stumpling upon this expression "callback" frequently. I've googled it and checked wikipedia, but without finding a good explination. I am familiar with some Java and C#, but how unlikely it sounds, I have never really understood what a callback mea... |
I am familiar with some Java and C#
A callback is an event or delegate in those languages - a way to get your code run by somebody else's code in it's context. Hence, the term "callback":
You call some other piece of code
It runs, perhaps calculating an intermediate value
It calls back into your code, perhaps giving... |
1,265,666 | 1,265,681 | Reason why not to have a DELETE macro for C++ | Are there any good reasons (except "macros are evil", maybe) NOT to use the following macros ?
#define DELETE( ptr ) \
if (ptr != NULL) \
{ \
delete ptr; \
ptr = NULL; \
}
#define DELETE_TABLE( ptr ) \
if (ptr != NULL) \
{ \
delete[]... | Personally I prefer the following
template< class T > void SafeDelete( T*& pVal )
{
delete pVal;
pVal = NULL;
}
template< class T > void SafeDeleteArray( T*& pVal )
{
delete[] pVal;
pVal = NULL;
}
They compile down to EXACTLY the same code in the end.
There may be some odd way you can break the #defin... |
1,265,702 | 1,265,730 | Comparing two vectors of maps | I've got two ways of fetching a bunch of data. The data is stored in a sorted vector<map<string, int> >.
I want to identify whether there are inconsistencies between the two vectors.
What I'm currently doing (pseudo-code):
for i in 0... min(length(vector1), length(vector2)):
for (k, v) in vector1[i]:
if v !... | Something like the std::mismatch algorithm
You could also use std::set_difference
|
1,265,864 | 1,265,952 | What could be a reason to not use bracket classes in C++? | It's often needed to accomplish the following task: change the state of something, do action, then change the state back to original. For example, in Win32 GDI it's needed to change background color, then do some drawing, then change the color back.
It can be either done directly:
COLORREF oldColor = SetBkColor( device... | I'm nitpicking here, but:
Code size, your code will be bigger because of the exception handler.
You need to write a lot of class to handle all sort of switches.
Bigger stack.
Always preforming code on all exceptions, even if its not need (for example you just want the application to crash)
|
1,265,951 | 1,265,972 | What are preprocessor macros good for? | After reading another question about the use of macros, I wondered: What are they good for?
One thing I don't see replaced by any other language construct very soon is in diminishing the number of related words you need to type in the following:
void log_type( const bool value ) { std::cout << "bool: " << value; }
void... |
compile different code under different conditions ( #ifdef __DEBUG__ );
guards to include each header once for each translation unit ( #pragma once );
__FILE__ and __LINE__ - replaced by the current file name and current line;
structuring the code to make it more readable (ex: BEGIN_MESSAGE_MAP() );
See interesting m... |
1,266,233 | 1,266,308 | What is activation record in the context of C and C++? | What does it mean and how important to know about it for a C/C++ programmers?
Is it the same across the platforms, at least conceptually?
I understand it as a block of allocated memory used to store local variable by a function...
I want to know more
| An activation record is another name for Stack Frame. It's the data structure that composes a call stack. It is generally composed of:
Locals to the callee
Return address to the caller
Parameters of the callee
The previous stack pointer (SP) value
The Call Stack is thus composed of any number of activation records th... |
1,266,277 | 1,266,335 | How to implement a stacktrace in C++ (from throwing to catch site)? | Is the trickery way that we can show the entire stack trace (function+line) for an exception, much like in Java and C#, in C++?
Can we do something with macros to accomplish that for windows and linux-like platforms?
thanks
| On Windows it can be done using the Windows DbgHelp API, but to get it exactly right requires lots of experimenting and twiddling. See http://msdn.microsoft.com/en-us/library/ms679267(VS.85).aspx for a start. I have no idea how to implement it for other platforms.
Hope this helps a bit.
Regards,
Sebastiaan
|
1,266,534 | 1,663,424 | C++ plus VS plus WORKFLOW? | I have seen there is Workflow Foundation for .NET. Is there some kind of a tool for creating work flow with C++ on VS? Or there maybe there are similar tools which helps to architect application business processes? Thanks in advance ! :)
| Creating workflows can be done in the Visual Studio Designer.
For architecting applications you should look at Visual Studio Architect Edition
http://ajdotnet.wordpress.com/2009/03/29/visual-studio-2010-architecture-edition/
You can download the Beta 2 version from here:
http://msdn.microsoft.com/en-us/vstudio/dd582936... |
1,266,570 | 1,266,621 | Python non-trivial C++ Extension | I have fairly large C++ library with several sub-libraries that support it, and I need to turn the whole thing into a python extension. I'm using distutils because it needs to be cross-platform, but if there's a better tool I'm open to suggestions.
Is there a way to make distutils first compile the sub-libraries, and ... | I do just this with a massive C++ library in our product. There are several tools out there that can help you automate the task of writing bindings: the most popular is SWIG, which has been around a while, is used in lots of projects, and generally works very well.
The biggest thing against SWIG (in my opinion) is ... |
1,266,861 | 1,267,439 | C++0x noise, bloat and portability | At first when I saw the upcoming C++0x standard I was delighted, and not that I'm pessimistic, but when thinking of it now I feel somewhat less hopeful.
Mainly because of three reasons:
a lot of boost bloat (which must cause hopeless compile times?),
the syntax seems lengthy (not as Pythonic as I initially might have ... |
Edit: do I (and others like me) have to keep a very close eye on build times, unreadable code and lack of portability and do massive prototyping to ensure that it's safe to move on with the new standard?
Yes. But you have to do all these things with the current standard as well. I don't see that it is getting any wor... |
1,267,019 | 1,267,220 | Is there a way to use macros to add additional values to an enum from elsewhere at compile time? | We use one big enum for message passing and there are optional parts of our code base that use specific messages that really only need to be added to the enum if those parts are to be compiled in. Is there a way to define a macro that could do this or something similar? I would like to be able to just add REGISTER_MSG... | I would rethink this design, but if you really want to do it this way you can construct the enum header at compile time using Make.
BigEnum.h:
# First put in everything up to the opening brace,
cat BigEnumTop > $@
# then extract all of the message names and add them (with comma) to BigEnum.h,
cat $(OP... |
1,267,067 | 1,268,043 | C++ style menu bar in VB.NET? | Ive been looking a long time for this, but can't seem to find it. When I add a menu strip in vb .net, it looks like this:
http://img19.imageshack.us/img19/4341/menu1sbo.jpg http://img19.imageshack.us/img19/4341/menu1sbo.jpg
and I want it to look like the WinRar, Calculator, Notepad etc menus like this:
http://img8.ima... | You may have to get dirty and create a CustomRenderer(ToolStripProfessionalRenderer) to apply to the ToolStripManager
Without rehashing to much, this doc looks like a nice overview or you can always opt for the Microsoft tutorial
menustrip is derived from toolstrip
|
1,267,173 | 1,268,011 | How do I find resource leaks in Win32? | After running some hours my application fails in creating a new font object:
CreateFontIndirect() returns NULL.
I know how to find memory leaks (i.e. using parallel inspector or another profiler - most of them include leak detection). But how can I locate a resource leak in Win32?
| Grab yourself a copy of GDI View - this useful tool can show all the GDI objects used by your app, including details on the font name, size, etc. This has proved very handy in the past.
For Win32 apps you might want to look at the WTL framework - this wraps GDI objects with lightweight C++ classes that will handle obj... |
1,267,354 | 1,273,320 | GTK Window configure events not propagating | I'm attempting to capture an event on a GTK window when the window is moved. I'm doing so with something that looks like this:
void mycallback(GtkWindow* parentWindow, GdkEvent* event, gpointer data)
{
// do something...
}
...
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_add_events(GTK... | Luke, as you have discovered, returning FALSE allows the event to propagate. This is explained in the gtk tutorial here
|
1,267,541 | 1,276,394 | Adding C++ custom action in Visual studio installer | due to some constraints i want to write a custom action in c++ and add its assembly in Visual Studio installer... is it possible?
as i know about c# or vb in those one can create classes inherited from Installer and it worked but now i want the same with C++....
| figured out that the assembly should contain a function named Install() in c++... it serves as an installer entry point.. added as Install custom action MSI installer executes that function .
|
1,267,697 | 1,267,723 | finding why a DLL is being loaded | I have a winxp process which has all sorts of dlls and static libs. One of our libs is calling ms debug dlls, I have a suspicion which one it is but want to prove it in a tool like Process Explorer. How can I get a tree of my process, to see exactly who is loading what modules?
| You can use tools like Dependency Walker
|
1,267,811 | 1,267,880 | __declspec(dllimport/dllexport) and inheritance | Given a DLL with the following classes :
#define DLLAPI __declspec(...)
class DLLAPI Base
{
public:
virtual void B();
};
class Derived : public Base
{
public:
virtual void B();
virtual void D();
};
Will my "Derived" class be visible outside of the dll even if the "DLLAPI" keyword is not applied t... | class Derived won't be exported by your DLL. Classes don't inherit exporting. Add DLLAPI to that too.
Note too that class members default to private accessibility, so none of your methods should be accessible. However, I do see Base::B() being exported in my test. The C++ header in the DLL-using code would flag the err... |
1,267,915 | 1,268,132 | Cast from size_t to int, or iterate with size_t? | Is it better to cast the iterator condition right operand from size_t to int, or iterate potentially past the maximum value of int? Is the answer implementation specific?
int a;
for (size_t i = 0; i < vect.size(); i++)
{
if (some_func((int)i))
{
a = (int)i;
}
}
int a;
for (int i = 0; i < (int)vect.... | I almost always use the first variation, because I find that about 80% of the time, I discover that some_func should probably also take a size_t.
If in fact some_func takes a signed int, you need to be aware of what happens when vect gets bigger than INT_MAX. If the solution isn't obvious in your situation (it usual... |
1,268,005 | 1,268,074 | AfxGetAppName() returns garbage characters | I have the following line of code in my application:
CString strAppName = AfxGetAppName();
Sometimes it fills strAppName up with garbage characters, and I can't figure out why.
Anyone have any ideas?
TIA.
| That is possible if you change m_pszAppName manually.
At the very beginning of application initialization, AfxWinInit calls CWinApp::SetCurrentHandles, which caches the current value of the m_pszAppName pointer as follows:
pModuleState->m_lpszCurrentAppName = m_pszAppName;
That is, the module state struct holds a cop... |
1,268,077 | 1,268,965 | MinGW compile for MS DOS | I'm using Code::Blocks with MinGW to write my C++ applications in Windows XP.
Now I want to compile my code to run under an MS DOS environment, so I can put it on my DOS formatted floppy disc. Can anyone help me?
Thanks in advance.
P.S. I don't mean the Command Prompt, but really the good old MS DOS Operating System.
| It's pretty old, but DJGPP exists precisely for DOS development. I hasn't been updated since 2000, but it works.
It's basically the same as MinGW, but exclusively for DOS.
|
1,268,101 | 1,268,189 | Why does the library compiled on two slightly different machines behaves slightly different? | Here's the setup:
My coworker has a Fedora x64_86 machine with a gcc 4.3.3 cross compiler (from buildroot).
I have an Ubuntu 9.04 x64_86 machine with the same cross compiler.
My coworker built an a library + test app that works on a test machine, I compiled the same library and testapp and it crashes on the same test... | If your code crashes (I assume you get a sigsegv), there seems to be a bug. It's most likely some kind of undefined behaviour, like using a dangling pointer or writing over a buffer boundary.
The unfortunate point of undefined behaviour is, that it may work on some machines. I think you are experiencing such an event h... |
1,268,216 | 1,268,230 | How to pass a C# Reference to COM Object to a C++ DLL | I am writing a Visual Studio add-in to process C++ code, and think that COM interop is slowing me down to much. I therefore want to pass a C# reference to a COM object to a small C++ DLL, have the DLL perform the necessary calculations and return back a string.
I would be passing a CodeFunction2 object to the DLL and ... | Maybe you should write a Managed C++ dll instead (using the /clr switch), then you can directly pass managed objects into the C++ dll and do whatever COM magic you like without worrying about passing them between dlls.
|
1,268,504 | 1,268,905 | Why is the template argument deduction not working here? | I created two simple functions which get template parameters and an empty struct defining a type:
//S<T>::type results in T&
template <class T>
struct S
{
typedef typename T& type;
};
//Example 1: get one parameter by reference and return it by value
template <class A>
A
temp(typename S<A>::type a1)
{
return a... | Just as first note, typename name is used when you mention a dependent name. So you don't need it here.
template <class T>
struct S
{
typedef T& type;
};
Regarding the template instantiation, the problem is that typename S<A>::type characterizes a nondeduced context for A. When a template parameter is used only i... |
1,268,541 | 1,268,556 | BOOST_FOREACH: is there a trick to avoid the all-caps spelling? | BOOST_FOREACH is really neat, but the C macro style of writing is somewhat off-putting.
Is there a trick to avoid the all-caps spelling?
| Actually, a little more googling and reading revealed the answer right in the Boost foreach documentation:
Making BOOST_FOREACH Prettier
People have complained about the name
BOOST_FOREACH. It's too long. ALL CAPS
can get tiresome to look at. That may
be true, but BOOST_FOREACH is merely
following the Boost Na... |
1,268,604 | 1,268,978 | vs 2008 623 compiler errors | I have a c++ console app that has been doing just fine and upon clean make started throwing compiler errors. Obviously I've redefined or omitted something, but I'm not sure what.
------ Rebuild All started: Project: alpineProbe, Configuration: Release Win32 ------
Deleting intermediate and output files for project 'ab... | Found it. Thanks to Michael Burr and his suggestion to use /showIncludes.
The problem was that the file \CodeAnalysis\sourceannotations.h in the C++ installation had gotten clobbered. Reinstalling should fix it.
Thanks for the help
|
1,268,682 | 1,268,707 | Writing to user documents folder C++ | I'm trying to write some info to the user's documents folder (eg. C:\Documents and Settings\[userName]), but I can't seem to find out how to grab the path programmatically. Is there any way to do this? C++, not using .NET.
Thanks!
| SHGetFolderPath with CSIDL_PERSONAL can be used to get the user's Documents folder.
WCHAR path[MAX_PATH];
HRESULT hr = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL,
SHGFP_TYPE_CURRENT, path);
|
1,269,019 | 1,269,049 | What should happen to the negation of a size_t (i.e. `-sizeof(struct foo)`))? | I'm dealing with some code at work that includes an expression of the form
-(sizeof(struct foo))
i.e. the negation of a size_t, and I'm unclear on what the C and C++ standards require of compilers when they see this. Specifically, from looking around here and elsewhere, sizeof returns an unsigned integral value of ty... | Both ISO C and ISO C++ standards guarantee that unsigned arithmetic is modulo 2n - i.e., for any overflow or underflow, it "wraps around". For ISO C++, this is 3.9.1[basic.fundamental]/4:
Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2n where n is the number of bits in the value repres... |
1,269,131 | 1,269,336 | Template's member typedef use in parameter undeclared identifier in VS but not GCC | I'm looking at some codes which makes heavy uses of templates. It compiles fine on GCC, but not on VS (tested on 2003 - 2010 beta 1), where it fails during syntax analysis. Unfortunately I don't know enough of the code structure to be able reduce the problem and reproduce it in only a few lines, so I can only guess at ... | I think this can be caused by a few circumstances
unbounded_int_type is a non-dependent type (defined at 14.6.2.1)
Its declaration appears in the class template. Because it's non-dependent, its name has to be resolved to a declaration at the time the member function is defined.
I suspect that Visual C++ is not able ... |
1,269,216 | 1,269,235 | Error passing 2D char* array into a function | I'm trying to pass a 2D array of char* into a function. I am getting this error:
"cannot convert 'char* (*)[2]' to 'char***' for argument '1' to 'int foo(char***)'"
Code:
int foo(char*** hi)
{
...
}
int main()
{
char* bar[10][10];
return foo(bar);
}
| Your array is an array of 10 char* arrays, each storing 10 char* pointers.
This means that when passing it to a function whose parameter is not a reference, it is converted to a pointer to an array of 10 char*. The correct function parameter type is thus
int foo(char* (*hi)[10])
{
...
}
int main()
{
char* ba... |
1,269,325 | 1,269,365 | Boost regex not working as expected in my code | I just started using Boost::regex today and am quite a novice in Regular Expressions too. I have been using "The Regulator" and Expresso to test my regex and seem satisfied with what I see there, but transferring that regex to boost, does not seem to do what I want it to do. Any pointers to help me a solution would be ... | The basic problem is that you are using regex_match when you should be using regex_search:
The algorithms regex_search and
regex_match make use of match_results
to report what matched; the difference
between these algorithms is that
regex_match will only find matches
that consume all of the input text,
... |
1,269,352 | 1,269,379 | C++: Looking for a concise solution to replace a set of characters in a std::string with a specific character | Suppose I have the following:
std::string some_string = "2009-06-27 17:44:59.027";
The question is: Give code that will replace all instances of "-" and ":" in some_string with a space i.e. " "
I'm looking for a simple one liner (if at all possible)
Boost can be used.
| You could use Boost regex to do it. Something like this:
e = boost::regex("[-:]");
some_string = regex_replace(some_string, e, " ");
|
1,269,378 | 1,699,635 | tutorials about WinAPI unicode? | I'm wondering if you guys are aware of any article of some sort that shows how to make code fully unicode? Reason I ask is because I'm dealing with winapi right now and it seems that everything's supposed to be unicode like L"blabla" .. Functions that I've encountered won't work properly by simply using the standard st... | When one of my projects need to be compiled with UNICODE on and off, I usually use the following definition to create an STL string that uses TCHAR instead of CHAR and wchar_t:
#ifdef _UNICODE
typedef std::wstring tstring;
#else
typedef std::string tstring;
#endif
or the following may also work:
typedef std::b... |
1,269,480 | 1,269,533 | Globbing in C++/C, on Windows | Is there a smooth way to glob in C or C++ in Windows?
E.g., myprogram.exe *.txt sends my program an ARGV list that has...ARGV[1]=*.txt in it.
I would like to be able to have a function (let's call it readglob) that takes a string and returns a vector of strings, each containing a filename.
This way, if I have files a.t... | Link with setargv.obj (or wsetargv.obj) and argv[] will be globbed for you similar to how the Unix shells do it:
http://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
I can't vouch for how well it does it though.
|
1,269,568 | 1,269,651 | How to pass a constant array literal to a function that takes a pointer without using a variable C/C++? | If I have a prototype that looks like this:
function(float,float,float,float)
I can pass values like this:
function(1,2,3,4);
So if my prototype is this:
function(float*);
Is there any way I can achieve something like this?
function( {1,2,3,4} );
Just looking for a lazy way to do this without creating a temporary v... | You can do it in C99 (but not ANSI C (C90) or any current variant of C++) with compound literals. See section 6.5.2.5 of the C99 standard for the gory details. Here's an example:
// f is a static array of at least 4 floats
void foo(float f[static 4])
{
...
}
int main(void)
{
foo((float[4]){1.0f, 2.0f, 3.0f, 4... |
1,269,751 | 1,269,757 | How to verify if a window of another program is minimized? | How can I do this? I've tried IsWindowVisible() but that doesn't seem to do the job.
| To check whether a window is minimized, use IsIconic(HWND).
|
1,269,801 | 1,269,814 | delete[] and memory leaks | I am wondering about the delete[] operator in C++. (I am using Visual Studio 2005).
I have an unmanaged DLL that is being called by a managed DLL. When I close this program after performing a few tasks while debugging, I am getting many (thousands?) of memory leaks, mostly 24 bytes - 44 bytes in size.. I suspect it mig... | First question set:
char* pointer = new char[500]
/* some operations... */
delete[] pointer;
Then all the memory for it is freed up
correctly, am I right?
right.
Second question set:
char* pointer = new char[500];
char* pointerIt = pointer;
/* some code perhaps to iterate over the whole memory block, like so *... |
1,269,806 | 1,270,305 | Qt Widget being resized twice upon initialization? | My "EditorView" (a QGLWidget) is being resized twice when it's created. It starts at say 846x630, then shrinks to 846x607 (losing 23 pixels in height). Created like this:
EditorWindow::EditorWindow() {
Q_INIT_RESOURCE(icons);
readSettings();
setWindowTitle("Q2D Map Editor");
createActions();
crea... | You should set a breakpoint in the resizeGL method, and check the call stack, to see, in both cases, what was the reason for calling resizeGL. From code you provided, it is not obvious.
|
1,269,819 | 1,269,851 | Implementing Skip List in C++ | [SOLVED]
So I decided to try and create a sorted doubly linked skip list...
I'm pretty sure I have a good grasp of how it works. When you insert x the program searches the base list for the appropriate place to put x (since it is sorted), (conceptually) flips a coin, and if the "coin" lands on a then that element is ad... |
Just store 2 pointers. One called above, and one called below in your node class.
Not sure what you mean.
According to wikipedia you can also do a geometric distribution. I'm not sure if the type of distribution matters for totally random access, but it obviously matters if you know your access pattern.
I am unsure of... |
1,269,911 | 1,269,940 | Have you used boost::tribool in real work? | tribool strikes me as one of the oddest corners of Boost. I see how it has some conveniences compared to using an enum but an enum can also be easily expanded represent more than 3 states.
In what real world ways have you put tribool to use?
| While I haven't used C++, and hence boost, I have used three-state variables quite extensively in a network application where I need to store state as true/false/pending.
|
1,269,994 | 1,270,011 | nanoseconds to milliseconds - fast division by 1000000 | I'm wanting to convert the output from gethrtime to milliseconds.
The obvious way to do this is to divide by 1000000.
However, I'm doing this quite often and wonder if it could become a bottleneck.
Is there an optimized divide operation when dealing with numbers like 1000000?
Note: Any code must be portable. I'm using... | Division is not an expensive operation. I doubt very much if a divide-by-1000000 operation will be anywhere near the main bottleneck in your application. Floating-point processors will be way faster than any sort of "tricks" you can come up with than just doing the single operation.
|
1,270,285 | 1,270,609 | Trouble debugging C++ using Eclipse Galileo on Mac | I am trying to debug C++ code using Eclipse Galileo on my MacBook Pro running Mac OS X v10.5 (Leopard). It's my first time trying this. I have a complicated C++ program I'd like to debug, but to test things out, I just tried to debug and step through the following:
#include <iostream>
using namespace std;
int main()
{... | In my experience the gdb/dsf launcher is still quite unusable. I can't get it to show variables too, it seems still very buggy.
Did you try the Standard Create Process Launcher? For me this works fine.
|
1,270,449 | 1,270,519 | How would you replace the 'new' keyword? | There was an article i found long ago (i cant find it ATM) which states reasons why the new keyword in C++ is bad. I cant remember all of the reasons but the two i remember most is you must match new with delete, new[] with delete[] and you cannot use #define with new as you could with malloc.
I am designing a language... | Problem match new, delete, new[], delete[]
Not really a big deal.
You should be wrapping memory allocation inside a class so this does not really affect normal users. A single obejct can be wrapped with a smart pointer. While an array can be represented by std::Vector<>
cannot use #define with new as you could with mal... |
1,270,517 | 1,283,308 | Porting project to my laptop results in a blank screen | So I'm making something in openGL using SDL. I'm about to take a long flight, and I can't seem to get the project to work on my laptop. I've used SDL on my laptop before, so I'm left thinking it is openGL's fault. The laptop is on win xp pro, and has an intel 945 graphics "card." I've tried updating the drivers, but to... | You might need to provide a bit more info, but at a guess I'd say your textures are invalid. OpenGL draws white when there is a texture problem. Possible reasons are...
Image size is bigger than the max texture size of the graphics chip
Image isn't power of 2 and the card doesn't support rectangular textures.
You hav... |
1,270,798 | 1,271,883 | How to create data fom image like "Letter Image Recognition Dataset" from UCI | I am using letter_regcog example from OpenCV, it used dataset from UCI which have structure like this:
Attribute Information:
1. lettr capital letter (26 values from A to Z)
2. x-box horizontal position of box (integer)
3. y-box vertical position of box (integer)
4. width width of box ... | I am not familiar with OpenCV's letter_recog example, but this appears to be a feature vector, or set of statistics about the image of a letter that is used to classify the future occurrences of the letter. The results of your segmentation should leave you with a binary mask with 1's on the letter and 0's everywhere e... |
1,270,927 | 1,270,948 | Are function static variables thread-safe in GCC? | In the example code
void foo()
{
static Bar b;
...
}
compiled with GCC is it guaranteed that b will be created and initialized in a thread-safe manner ?
In gcc's man page, found the -fno-threadsafe-statics command line option:
Do not emit the extra code to use the
routines specified in the C++ ABI for
thread-... |
No, it means that the initialization of local statics is thread-safe.
You definitely want to leave this feature enabled. Thread-safe initialization of local statics is very important. If you need generally thread-safe access to local statics then you will need to add the appropriate guards yourself.
|
1,271,122 | 1,271,142 | How to get ShowState of a window in c# or c++? | I am trying to get showstate of a window.
I know that I can maximize, minimize, or close a window by ShowWindow API in c# or c++. How do I get ShowState of a window?
| In C++:
WINDOWPLACEMENT wp;
GetWindowPlacement( hWnd, &wp );
UINT showCmd = wp.showCmd;
|
1,271,144 | 1,271,227 | Is 'using namespace' inside another namespace equivalent to an alias? | Consider the following two statements:
namespace foo = bar;
and
namespace foo {
using namespace bar;
}
Are those two statements equivalent, or are there some subtle differences I'm not aware of?
(Please note that this is not a question about coding style - I'm just interested in C++ parsing).
| namespace foo=bar;
This does not affect any name lookup rules. The only affect is to make 'foo' an alias to 'bar'. for example:
namespace bar
{
void b();
}
void f () {
bar::b (); // Call 'b' in bar
foo::b (); // 'foo' is an alias to 'bar' so calls same function
}
The following does change lookup rules
name... |
1,271,248 | 1,271,692 | C++: When (and how) are C++ Global Static Constructors Called? | I'm working on some C++ code and I've run into a question which has been nagging me for a while... Assuming I'm compiling with GCC on a Linux host for an ELF target, where are global static constructors and destructors called?
I've heard there's a function _init in crtbegin.o, and a function _fini in crtend.o. Are thes... | When talking about non-local static objects there are not many guarantees. As you already know (and it's also been mentioned here), it should not write code that depends on that. The static initialization order fiasco...
Static objects goes through a two-phase initialization: static initialization and dynamic initializ... |
1,271,307 | 1,271,953 | Why is VC++ C4150 (deletion of pointer to incomplete type) only a warning? | Of course, warning must be treated, but why is VC++ C4150 (deletion of pointer to incomplete type) only a warning?
| Because standard says it's legal, although dangerous: 5.3.5
If the object being deleted has
incomplete class type at the point of
deletion and the complete class has a
non-trivial destructor or a
deallocation function, the behavior is
undefined.
|
1,271,335 | 1,271,456 | Inline Function (When to insert)? | Inline functions are just a request to compilers that insert the complete body of the inline function in every place in the code where that function is used.
But how the compiler decides whether it should insert it or not? Which algorithm/mechanism it uses to decide?
Thanks,
Naveen
| Some common aspects:
Compiler option (debug builds usually don't inline, and most compilers have options to override the inline declaration to try to inline all, or none)
suitable calling convention (e.g. varargs functions usually aren't inlined)
suitable for inlining: depends on size of the function, call frequency o... |
1,271,367 | 1,271,587 | Radix Sort implemented in C++ | I am trying to improve my C++ by creating a program that will take a large amount of numbers between 1 and 10^6. The buckets that will store the numbers in each pass is an array of nodes (where node is a struct I created containing a value and a next node attribute).
After sorting the numbers into buckets according to... | I think you're severely overcomplicating your solution. You can implement radix using the single array received in the input, with the buckets in each step represented by an array of indices that mark the starting index of each bucket in the input array.
In fact, you could even do it recursively:
// Sort 'size' number ... |
1,271,513 | 1,271,691 | C++ code visualization | A sort of follow up/related question to this.
I'm trying to get a grip on a large code base that has hundreds and hundreds of classes and a large inheritance hierarchy. I want to be able to see the "main veins" of the inheritance hierarchy at a glance - not all the "peripheral" classes that only do some very specific ... | Why not just do it manually, it is a great learning experience when starting to work with a large code base. I usually just look at what class inherits from what, and what class contain what instances, references or pointers to other classes. Have a piece of paper next to you and get drawing...
|
1,271,784 | 1,272,723 | using QTextStream to read stdin in a non-blocking fashion | Using Qt, I'm attempting to read the contents of the stdin stream in a non-blocking fashion. I'm using the QSocketNotifier to alert me when the socket has recieved some new data. The setup for the notifier looks like this:
QSocketNotifier *pNot = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read, this);
connect(p... | Line buffering.
Default is flushing after a "\n". If you write 5 lines to your process, your slot gets called 5 times. If you want to avoid that, you have to call setbuf(stdin, _IOFBF). But even then it is not guaranteed you can read arbitrarily large amounts of data in one chunk.
Edit: It would probably better to use ... |
1,272,073 | 1,272,122 | boost interprocess : shared memory and stl types | I have a simple struct :
struct MyType
{
std::string name;
std::string description;
}
and I'm putting it in a shared memory :
managed_shared_memory sharedMemory(open_or_create, "name", 65535);
MyType* pType = sharedMemory.construct<MyType>("myType")();
// ... setting pType members ...
If the two applications ... | Boost.Interprocess often offers replacements for STL types, for usage in shared memory. std::string, especially when just a member of a struct, will not be accessible from another process. Other people also had such a problem.
|
1,272,120 | 1,283,446 | What are the error messages for breaking the GLSL shader instruction limits? | We're a small dev team working with some GLSL that may be too large for older graphics cards to compile. We want to display a sensible error message to the user (rather than just dump the info log or output a generic 'this shader didn't work' type of message) when this happens based on the type of error.
The question ... | Even if you know what the error messages look like now, nVidia and ATI are under no obligation to keep them the same in the next version(s) of their drivers. They basically can't be relied on for anything except debugging purposes.
I would look and see if the vendor extensions might be able to provide you with more spe... |
1,272,161 | 1,272,341 | Unlocked access to stl vector::size safeness | I've several writers(threads) and one reader on a stl vector.
Normal writes and reads are mutex protected, but I would like to avoid contention on a loop I have and I was wondering if vector::size would be safe enough, I suppose it depends on implementations, but since normally vector dynamic memory is for the stored i... | I don't know off-hand of an implementation in which concurrent reads and writes to an integer segfault (although the C++03 standard does not prohibit that, and I don't know whether POSIX does). If the vector uses pImpl, and doesn't store the size in the vector object itself, you could maybe have problems where you try ... |
1,272,398 | 1,278,465 | How to send a notification that's handled by ON_NOTIFY? | I'm trying to post a LVN_ ITEMCHANGED to my custom gridlist's owner. I know how to send a WM_ User message using PostMessage (as shown here)
::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_REFRESH, (WPARAM)pBuffer, (LPARAM)GetOutputIdx() );
When I use this same code to send a LVN_ITEMCHANGED message though,
::PostM... | I found out that I could override the message handler in my derived class and pass the message on to my parent control simply by using this code in the message map:
ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnListItemChanged)
Then in OnListItemChanged, I first call the base class function then return FALSE. This causes t... |
1,272,680 | 1,272,707 | What does a colon following a C++ constructor name do? | What does the colon operator (":") do in this constructor? Is it equivalent to MyClass(m_classID = -1, m_userdata = 0);?
class MyClass {
public:
MyClass() : m_classID(-1), m_userdata(0) {
}
int m_classID;
void *m_userdata;
};
| This is a member initializer list, and is part of the constructor's implementation.
The constructor's signature is:
MyClass();
This means that the constructor can be called with no parameters. This makes it a default constructor, i.e., one which will be called by default when you write MyClass someObject;.
The part :... |
1,272,775 | 1,272,790 | Printing the value of a float to 2 decimal places | I have a float with the value of e.g 57.400002. I use sprintf_s to display the value on my GUI.
sprintf_s(xPosition, 19, "%f", xPositionValue);
How can I format the float so it displays as 57.40?
| sprintf_s(xPosition, 19, "%.2f", xPositionValue);
|
1,273,026 | 1,273,034 | limit size of Queue<T> in C++ | I notice the thread of similar question: Limit size of Queue<T> in .NET?
That's exactly what I want to do, but I am not using .net but GNU C++. I have no reference to the base class in GNU C++, so java like super.***() or .net like base.***() will not work. I have been trying to inherit from queue class but it turns ou... | Make a new class that encapsulates the queue and enforce a size limit in the new class.
|
1,273,148 | 1,273,163 | C++ constructor definition | All of the constructors methods here do the same thing. I mostly use method2 but saw method3 for the first time today. Have seen method1 in some places but dont know what are the exact differences between them ?
Which one is the best way to define constructors and why ? Is there any performance issues involved ?
1 cl... | For the types you use, there will probably be no difference in performance. However for non-POD data (classes with constructors) the form:
Test(int &vara, char *& varb) : a(vara), b(varb){}
will be the most efficient. This is because non-POD data will be initialised whther you provide an initialisation list or not. Th... |
1,273,295 | 1,273,355 | Java FAQ equivalent of C++ FAQ lite? | Is there any Java FAQ equivalent of the Parashift C++ FAQ lite ?
(Books like Effective Java are handy to have around, but I'm looking for a comprehensive online (advanced) Java FAQ that I could use)
| There is nothing quite like it that I know of, but Angelika Langer's Generics FAQ covers generics pretty well.
Also, you might find Roedy Green's Java Glossary handy.
|
1,273,548 | 1,274,893 | How is Non-Virtual Interface pattern imlemented in C++? | I am curious about both, a h single and multi-threaded implementation.
Thanks
| Your question is vague, but it sounds like you want the Curiously recurring template pattern
There are a lot better people than I to explain this on the web it is used a lot in the boost library. check out boost.iterator documentation and code for a good example
|
1,273,572 | 1,273,601 | Will pthreads become obsolete once std:thread makes into C++Ox | Obviously we will still maintain it, but how useful will it be, once the C++ standard guarantees is.
What about synchronization primitives (Mutex, conditional variables) with advent of the new standard?
Do you consider pthread harder to master as opposed to std::thread?
| C isn't going away. POSIX isn't going away. Multithreaded code written in C for POSIX isn't going away. So pthreads isn't going away.
Many implementations of std::thread will use pthreads under the hood.
"The Pthreads API is defined in the ANSI/IEEE POSIX 1003.1 - 1995 standard." -- POSIX Threads Programming https://co... |
1,273,687 | 1,273,749 | Why or why not should I use 'UL' to specify unsigned long? | ulong foo = 0;
ulong bar = 0UL;//this seems redundant and unnecessary. but I see it a lot.
I also see this in referencing the first element of arrays a good amount
blah = arr[0UL];//this seems silly since I don't expect the compiler to magically
//turn '0' into a signed value
Can someone provide some ... | void f(unsigned int x)
{
//
}
void f(int x)
{
//
}
...
f(3); // f(int x)
f(3u); // f(unsigned int x)
It is just another tool in C++; if you don't need it don't use it!
|
1,273,833 | 1,273,892 | How to send output of native executable programs into the world of Web Services? | I have many C/C++ old native .exe and .dll programs running on Windows servers of my company.
Some .exe programs (I will designate with E) get results on the console or into a file and most of .dll programs (D) return results in arrays of structures.
My boss has asked me for the possibility to “also” send the results g... | First of all, you should be aware that there are different kinds of webservices. The most common ones are REST and SOAP. I assume that you want to use SOAP. In that case every message has to be encoded, but that will be handled by your SOAP library/framework. The same is true for the client. He will usually not decode ... |
1,273,900 | 1,274,208 | delete boost function while in use | I have a situation where a boost::function and boost::bind (actually a std::tr1::function and bind) are being deleted while still in use. Is this safe? I would normally avoid it, but the offending code is a bit entrenched and my only other option is adding a new thread.
typedef function<int(int)> foo_type;
foo_type*... | boost::function or std::tr1::functions are copyable objects. So, generally there is absolutly no reason to allocate them -- just pass them by value.
They are well optimized for most of real cases... So just pass them by value:
typedef function<int(int)> foo_type;
foo_type global_foo;
int actual_foo( int i, Magic* m )... |
1,274,022 | 1,276,295 | Getting the size of a Qt Object | I'm using Qt and C++, I need to find out the amount of memory used by instances of certain Qt classes, this is usually done using sizeof, however in Qt each class holds a pointer to an another class containing the actual implementation, the definition of this private implementation class is not found in headers but onl... | There's no exact answer to the question, since the amount of memory allocated for different objects of the same type might not even be the same (e.g. QSomething A might be able to reuse some data from a cache whereas QSomething B might have to allocate it separately, etc).
What you could do, I suppose, is write a trivi... |
1,274,036 | 1,276,419 | Generating C++ BackTraces in OS/X (10.5.7) | I've been utilizing backtrace and backtrace_symbols to generate programmatic stack traces for the purposes of logging/diagnosis. It seems to roughly work, however, I'm getting a little bit of mangling and there are no accompanying file/line numbers associated with each function invocation (as I'd expect within a gdb b... | The backtraces typically come back from backtrace_symbols in the following format:
./MyApp(_ZN4test3fooEv+0x8) [0x821c874]
abi::__cxa_demangle expects only the function name. Thus, some parsing must first be done on the trace:
std::string trace(backtrace[idx]);
// attempt to demangle
{
std::... |
1,274,189 | 1,279,814 | Why is CoCreation of a COM+ component failing with 0x8007007e "The specified module could not be found"? | I have a COM dll that is working fine as an in-proc server and I install it in Component Services COM+ Applications. Now when I try to CoCreate it from my client app, I get HRESULT 0x8007007e "The specified module could not be found". What could be causing this?
| The dll was registered on a ClearCase dynamic view, similar to a mapped drive, not available to COM+. Solution was to move the dll and the proxy/stub dll to a local drive and register them there.
|
1,274,428 | 1,274,441 | Can you declare a pointer on the heap? | This is the method for creating a variable on the heap in C++:
T *ptr = new T;
ptr refers to a pointer to the new T, obviously. My question is, can you do this:
T *ptr = new T*;
That seems like it could lead to some very, very dangerous code. Does anyone know if this is possible/how to use it properly?
| int** ppint = new int*;
*ppint = new int;
delete *ppint;
delete ppint;
|
1,274,460 | 1,274,483 | QApplication without display | I using Qt3.3 and I'm trying to create an QApplication without display.
I need to check signals from QSocket objects, and this is the reason that I need the QApplication.
I'm trying to do QApplication( 0, 0 ), but I'm getting "QApplication: invalid Display* argument.".
How is the correct way to do it?
| From the docs:
QApplication::QApplication ( int &
argc, char ** argv, bool GUIenabled )
Constructs an application object with
argc command line arguments in argv.
If GUIenabled is TRUE, a GUI
application is constructed, otherwise
a non-GUI (console) application is
created.
Set GUIenabled to FALSE for progr... |
1,274,484 | 1,274,853 | Avoiding global variables in embedded programming | In the type of embedded programming I'm getting into, determinism and transparency of the running code are highly valued. What I mean by transparency is, for instance, being able to look at arbitrary sections of memory and know what variable is stored there. So, as I'm sure embedded programmers expect, new is to be av... | If you want to unit test such code first I would recommend reading Working Effectively With Legacy Code Also see this.
Basically using the linker to insert mock/fake objects and functions should be a last resort but is still perfectly valid.
However you can also use inversion of control, without a framework this can pu... |
1,274,549 | 1,274,882 | C++ Spin Image Resources | Does anyone know of a good resource that will show me how to load an image with C++ and spin it?
What I mean by spin is to do an actual animation of the image rotating and not physically rotating the image and saving it.
If I am not clear on what I am asking, please ask for clarification before downvoting.
Thanks
| You could use SDL and the extension sdl_image and/or sdl_gfx
|
1,274,910 | 1,275,260 | does (w)ifstream support different encodings | When I read a text file to a wide character string (std::wstring) using an wifstream, does the stream implementation support different encodings - i.e. can it be used to read e.g. ASCII, UTF-8, and UTF-16 files?
If not, what would I have to do?
(I need to read the entire file, if that makes a difference)
| C++ supports character encodings by means of std::locale and the facet std::codecvt. The general idea is that a locale object describes the aspects of the system that might vary from culture to culture, (human) language to language. These aspects are broken down into facets, which are template arguments that define h... |
1,274,912 | 1,274,978 | Base-to-derived class typecast | I have a base class:
class RedBlackTreeNode
{
// Interface is the same as the implementation
public:
RedBlackTreeNode* left;
RedBlackTreeNode* right;
RedBlackTreeNode* parent;
Color color;
TreeNodeData* data;
RedBlackTreeNode():
left(0),
right(0),
parent(0),
colo... | Are you sure that RedBlackTree::rootHolder.left has been initialized?
I think you somewhere initialized IndIntRBNode::left, but when you are accessing RedBlackTree::rootHolder.left you are accessing RedBlackTreeNode::left, which is not the same field.
|
1,275,864 | 1,275,869 | Is there any cool project written in STL? | I want to learn STL by quick browsing of real project source.
Where can I find a high quality project that uses STL?
| Notepad++: pure Win32 + STL only!
Based on a powerful editing component
Scintilla, Notepad++ is written in C++
and uses pure Win32 API and STL which
ensures a higher execution speed and
smaller program size. By optimizing as
many routines as possible without
losing user friendliness, Notepad++ is
trying ... |
1,276,020 | 1,276,993 | Skipping a C++ template parameter | A C++ hash_map has the following template parameters:
template<typename Key, typename T, typename HashCompare, typename Allocator>
How can I specify a Allocator without specifying the HashCompare?
This won't compile :(
hash_map<EntityId, Entity*, , tbb::scalable_allocator>
| There's one trick you can use which will at least save you having to work out what the default is, but it does require that you know the name of the type as it is defined in hash_map.
The hash_map will probably be declared something like:
class allocator {};
class hash_compare {};
template<typename Key
, typename T
... |
1,276,339 | 1,276,358 | Operator templates in C++ | If I want to create a function template, where the template parameter isn't used in the argument list, I can do it thusly:
template<T>
T myFunction()
{
//return some T
}
But the invocation must specify the 'T' to use, as the compiler doesn't know how to work it out.
myFunction<int>();
But, suppose I wanted to do some... | This should work:
class C
{
public:
template <class T>
T operator[](int n)
{
return T();
}
};
void foo()
{
C c;
int x = c.operator[]<int>(0);
}
But it's of no real value because you'd always have to specify the type, and so it looks like a very ugly function call - the point of an ope... |
1,276,687 | 1,276,861 | How can I find out the current color depth of a machine running vista/w7? | I want to check the current color depth of the OS to warn users if they try to run my application with a "wrong" color depth (using c++ & Qt).
I guess there's a win api call to get this information, but I couldn't find anything.
| On Windows you could use GetDeviceCaps with the BITSPIXEL flag but you'll need a screen DC first (GetDC could fetch you one).
HDC dc = GetDC(NULL);
int bitsPerPixel = GetDeviceCaps(dc, BITSPIXEL);
ReleaseDC(NULL, dc);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.