c++

programatically evaluating the value of somaxconn, to set the listen backlog parameter.

For server side programming I use the listen function as: int listen(int sockfd, int backlog); I understand that the backlog should be less than or equal to the somaxconn set on the host system where I would run my server program. If I use SOMAXCONN as the backlog, it will be equivalent to hard-coding it to the value of SOMAXCONN that ...

C API for getting CPU load in linux

In linux, is there a built-in C library function for getting the CPU load of the machine? Presumably I could write my own function for opening and parsing a file in /proc, but it seems like there ought to be a better way. Doesn't need to be portable Must not require any libraries beyond a base RHEL4 installation. ...

std::auto_ptr, delete[] and leaks

Why this code does not cause memory leaks? int iterCount = 1000; int sizeBig = 100000; for (int i = 0; i < iterCount; i++) { std::auto_ptr<char> buffer(new char[sizeBig]); } WinXP sp2, Compiler : BCB.05.03 ...

How to convert string to LPWSTR in c++

Hi Can any ne Help converting string to LPWSTR string command=obj.getInstallationPath()+"" Now i wat to pass it as parameter for CreateProcessW(xx,command,x.......) But cretaeProcessW() accepts only LPWSTR so i need to cast string to LPWSTR Thanks in Advance ...

creating zip file from a folder - in c++

I want to create a program that , when executed, will compress a selected folder. Can it be done? Thanks, Oded ...

How to open the registry and get the specific value in c++

Hi Ineed to open this key" HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\" and get the "VerSpecificRootDir" value using c++ ....How can i do this I have no knowledge abt it can any one help me in this regard.. After Getting All The Support I did it as unsigned long type=REG_SZ, size=1024; char res[1024]=""; HKEY...

Who takes ownership of the IErrorInfo?

We use Native COM support in our code havily. Everything's fine except that we don't like the fact that on error _com_raise_error() is called which throws a _com_error exception. Since we have our own hierarchy of exceptions catching this _com_error is inconvenient - it's not in our hierarchy and even doesn't inherit from std::exception....

Access to global data in a dll from an exported dll function

Hello, I am creating a C++ Win32 dll with some global data. There is a std::map defined globally and there are exported functions in the dll that write data into the map (after acquiring a write lock, ofcourse). My problem is, when I call the write function from inside the dll DllMain, it works without any problems. But when I load the...

How linker resolves the symbol in assembly code

Hi, I wanted to know how linker resolves the printf symbol in the following assembly code. #include<stdio.h> void main() { printf("Hello "); } .file "test.c" .def ___main; .scl 2; .type 32; .endef .section .rdata,"dr" LC0: .ascii "Hello \0" .text .globl _main .def _main; .scl 2; .type 32; .endef _main: ...

Is it possible to make both a managed and unmanaged versions of the same C++ assembly?

We use a software from another company for one of our products. A developer from that company is kinda 'old' and works in C (no offence). We work in .Net 3.5 (C#). He asked me if it is possible, with the same source code (presumably in C, maybe C++), to create an assembly that he could compile both a managed and unmanaged version. Ar...

cancellation handler won't run if pthread_exit called from C source instead of C++ source

I'm linking a C++ source with a C source and a C++ source. I create a thread with pthread, a cancellation point and then I call pthread_exit either through the C or the C++ source file. If the pthread_exit call comes from the C source, the cancellation handler does not fire! What may be the reason for this? b.cc: #include <cstdio> #in...

Restart a process [exe] in Windows

I have a C++ exe; under a particular scenario I need to stop the exe and start it up again. This has to be done from within the same exe and not from outside. What is the best way to achieve this? My guess is to start a new instance of the process and then kill the running process. But is there any straight forward API to do this, like ...

How to check if a SQL query is valid for writing with ADO?

My app has an advanced feature that accepts SQL queries written by the user. The feature should include a "Validate" button to check if the query is valid. The most simple way I found to do this using ADO is just trying to run the query and catch possible exceptions. But how can I also check if the query enables to add new records or to...

How to Find CPU Utilization of a Single Thread within a Process

Hi All, I am looking a Tool on How to Find CPU Utilization of a Single Thread within a Process in VC++. It would be great full if any one could provide me a tool. Also it could be better if you guys provide how to do programmatically. Thank you in Advance. ...

Small question about precompiled headers

Looking at an open source code base i came across this code: #include "StableHeaders.h" #include "polygon.h" #include "exception.h" #include "vector.h" ... Now the StableHeaders.h is a precompiled header which is included by a 'control' cpp to force it's generation. The three includes that appear after the precompiled header are also ...

Error on dlopen: St9bad_alloc

I have some c++ code I'm using for testing in which the first line is a call to dlopen in an attempt to load my shared object. Upon hitting this line I get the following error: Terminate called after throwing an instance of std::bad_alloc: what() : St9bad_alloc I've upped the memory (free -m now reports that I have ~120 MB free wh...

How to convert std::string to LPCSTR?

Hi How can I convert a std::string to LPCSTR? Also, how can I convert a std::string to LPWSTR? I am totally confused with these LPCSTR LPSTR LPWSTR LPCWSTR? Are LPWSTR and LPCWSTR are the same? ...

RDP communication via C/C++

Hi guys. I need to write a basic RDP client in C/C++, doesn't need GUI it can be CLI, it only needs to connect to specified hosts - if connection is successfull, to confirm it and if it isn't to output an error message like the pass is not correct. Can someone point me to somewhere so i can read more about this ? Thanks. ...

Non-threadsafe file I/O in C/C++

While troubleshooting some performance problems in our apps, I found out that C's stdio.h functions (and, at least for our vendor, C++'s fstream classes) are threadsafe. As a result, every time I do something as simple as fgetc, the RTL has to acquire a lock, read a byte, and release the lock. This is not good for performance. What's ...

overload operator<< within a class in c++

I have a class that uses a struct, and I want to overload the << operator for that struct, but only within the class: typedef struct my_struct_t { int a; char c; } my_struct; class My_Class { public: My_Class(); friend ostream& operator<< (ostream& os, my_struct m); } I can only compile when I declare the operator<< ove...