C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

Share tech news, updates, or what's on your mind.

Sign up to Post

How to avoid dll-Hijack issue  ?

We have a normal C++ MFC application but we kept a .dll file in the same path where our application resides. When we start the application the dll file present in the current directory also loaded and fall in an infinite loop and our real application is non-responsive because the name of the dll is one of the System module dll that is loaded by the framework from the system path.

The reason is it look in the currentdir instead of the system path on Priprity of Dll search.
How we can avoid this dll hijack issue in Windows ?

Means how to avoid the search of dll from current directory rather look at system path at first priority
0
Free Tool: Path Explorer
LVL 12
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Hello

is there a way to set gdb filename:line_number such that the filename is a path?

thanks
0
I have ported some code from an old application that I wrote years ago to receive IP4 multicast data on a local area network using Indy 9.

The same code using Indy 10 on C++ builder XE10.1 Berlin doesn't work. No data is received in the OnIPMCastRead event handler (the event handler isn't triggered).
I have confirmed with wireshark that the network traffic is there on 244.0.0.166 port 60 as per the attached wireshark trace.
My code is as follows and the configuration of the Indy 10 IdIPMCastClient component is shown in the attached image file.
Can anyone explain why it isn't working please ?

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdGlobal.hpp>
#include <IdIPMCastBase.hpp>[embed=file 1332006][embed=file 1332007]
#include <IdIPMCastClient.hpp>
#include <IdSocketHandle.hpp>
#include <IdUDPBase.hpp>
#include <IdUDPServer.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TIdIPMCastClient *IdIPMCastClient1;
	TButton *Button1;
	void __fastcall IdIPMCastClient1IPMCastRead(TObject *Sender, const TIdBytes AData,
          TIdSocketHandle *ABinding);
	void __fastcall Button1Click(TObject *Sender);
private:	// User declarations

Open in new window

0
std::function as a parrameter in delegate constructor
      i want to know why control does not goes to AB() if i passed abc(AB) in main() as control goes for initialization of i as 10 when abc(10) is passed

class abc { int i;

    std::function<void(void)>func = nullptr;
public: abc(){}
    abc(std::function<void(void)>&fb):func(fb){}

    abc(int i):i(i){}
};
void AB() { cout<< "fun_AB"; }

int main() { abc(AB); abc(10); }

Open in new window

0
I wish to send a message to all client connected to my server application which uses an Indy 10 TCP Server component in Embarcadero C++ builder  XE 10.2 .

I have written the following function  which is meant to iterate through all the client connections to my server but it doesn't work.

I need some help in how to iterate through the list returned by the  IdTCPServer1->Contexts->LockList()  function.
I have seen an example in Delphi but my attempt in translating to C++ builder doesn't work.


void TForm1::BroadcastMessage(UnicodeString mess)
{
	TList *ls;
	int n;
	TIdContext *c;

	try
	{
		ls = IdTCPServer1->Contexts->LockList();
                n = ls->Count;
		for(int i=0;i<n;i++)
		{
			c = (TIdContext *)(ls->Items[i]); // <------ This line  is where the coding is wrong
			c->Connection->IOHandler->WriteLn(mess);
		}
		IdTCPServer1->Contexts->UnlockList();
	}
	catch(...)
	{
		IdTCPServer1->Contexts->UnlockList();
	}
}
//---------------------------------------------------------------------------

Open in new window

0
I need some assistance in writing a TCP Server in Embarcadero C++ builder XE 10.1 using  an Indy 10 TCP server VCL control.
How do I accept a connection from a client when using an Indy 10 VCL control TIdTCPServer ?
I imagine that I need to write some code in the OnConnect Event handler although logically one might expect a "BeforeConnect"  event handler .I haven't found any methods anywhere in the AContext or its members called Accept() ?
Also, my understanding is that  when a connection is established, the Execute event is invoked which supplies an AContext parameter which equates to a thread. Can I let the Execute event handler terminate and have a separate thread that manipulates the saved value of the AContext parameter in a list. the separate thread would poll round each AContext in the list  to independently send/receive data to/from the remote clients ?
0
Good day! I'm trying to display an image in the Picture Control in the MFC with pixel data. Tell me what's wrong.

image = new DicomImage(str);
		
		image->setMinMaxWindow();
		Uint8 *pixelData = (Uint8 *)(image->getOutputData(8));
		if (pixelData != NULL){
			int w = image->getWidth();
			int h = image->getHeight();

			HBITMAP hBitmap = NULL;

			BITMAPINFOHEADER bmih;
			bmih.biSize = sizeof(BITMAPINFOHEADER);
			bmih.biWidth = 1024;
			bmih.biHeight = -512;
			bmih.biPlanes = 1;
			bmih.biBitCount = 8;
			bmih.biCompression = BI_RGB ;
			bmih.biSizeImage = 0;
			bmih.biXPelsPerMeter = 10;
			bmih.biYPelsPerMeter = 10;
			bmih.biClrUsed = 0;
			bmih.biClrImportant = 0;

			BITMAPINFO dbmi;
			ZeroMemory(&dbmi, sizeof(dbmi));  
			dbmi.bmiHeader = bmih;
			dbmi.bmiColors[0].rgbBlue = 0;
			dbmi.bmiColors[0].rgbGreen = 0;
			dbmi.bmiColors[0].rgbRed = 0;
			dbmi.bmiColors[0].rgbReserved = 0;
			void* bits = (void*)&(pixelData[0]); 

			// Create DIB
			HDC localDC = ::GetDC(NULL);
			hBitmap = CreateDIBSection(localDC, &dbmi, DIB_RGB_COLORS, &bits, NULL, 0);
			if (hBitmap == NULL) {
				::MessageBox(NULL, __T("Could not load the desired image image"), __T("Error"), MB_OK);
				return;
			}

			unsigned char* dest = new unsigned char[w*h];
			dest =	(unsigned char*)bits;
			const unsigned char* src  = pixelData;
			for (int j=0; j<w; j++){
				for (int i=0; i<h; i++, src++){
					*dest++ = *src;
					*dest++ = *src;
					*dest++ = *src;
				}
			}	

			

Open in new window

0
Hi everybody,

I have a question about in-class initialization and thread-safety. I searched a lot in the net about this but wasn't able to figure it out.

I (accidentally) found a IMO nice way to implement somehting like an instance counter using in-class initialization like this:
// sample 1 using a static class member
struct Test1
{
	static int current;
	int num{ current++ };
};

int Test1::current{ 0 };

// sample 2 using singleton desing pattern
struct Test2
{
	static int& current()
	{
		static int curr{ 0 };
		return curr;
	}

	int num{ current()++ };
};

Open in new window

Both methods work fine:
void foo()
{
	for ( int n = 0; n < 5; n++ )
	{
		std::cout << "T1: " << Test1{}.num << " T2: " << Test2{}.num << std::endl;
	}
}

// output is as expected:
// T1: 0 T2: 0
// T1: 1 T2: 1
// T1: 2 T2: 2
// T1: 3 T2: 3
// T1: 4 T2: 4

Open in new window

Now I'm curious if this is thread safe. I know the instantiation of current itself is thread-safe, but I'm not sure what's about the ++ operator call: especially in the second example I would guess the ++ called for the returned reference is not thread safe, but on the other side I think compilers do a lot of complicated things to make statics thread safe, so probably my suspection is wrong.

JFI: I'm not sure since which C++ standard this can be used, I use C++17 (VS 2017), but maybe it works with older versions too.

Does anyone of you know better?

Best regards,

ZOPPO
0
how to get the SwapTotal for solaris in C or C++?
0
Hi,
I am making a Doodle Jump game in c++ using sfml,
I started building the umlaut and decided to go with a STRATEGY pattern. I don't really know if this is the right choice.
I basically got to a point where I don't know how to continue,
please if someone could take a look at my UML and tell me what they think it will be greatly appreciated.



0
Free Tool: ZipGrep
LVL 12
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

I have a DLL that is simply using some pretty common code to count files in a directory. On all our test computers, and 98% of people using it, there is no problem. But a few people experience a crash to desktop from this code. I am looking for some possibilities of why this could happen in these isolated cases.

Here is the code:
int FMSGaugeCallback::getFltPlnsInFolder(wchar_t szPath[MAX_PATH])
{
	WIN32_FIND_DATA		ffd;
	wchar_t				szFileName[MAX_PATH];
	HANDLE				hFind = INVALID_HANDLE_VALUE;
	DWORD				dwError = 0;
	wchar_t				szError[255];
	wchar_t				szDir[MAX_PATH];
	int					nLen = 0, nDir = 0, nCount = 0;

	if (!PathIsDirectory(szPath))
		return 0;

	PathAddBackslashW(szPath);
	swprintf(szDir, sizeof szDir,  L"%s*.pln", szPath);
	hFind = FindFirstFileW(szDir, &ffd);								// Open filefind
	if (INVALID_HANDLE_VALUE == hFind)								// if process fails record error
	{																// and discontinue function
		dwError = GetLastError();
		swprintf(szError, sizeof szError, ERR_SEARCH_FLT_PLNS, szPath,getLastWinError(dwError));
		writeToErrorLog(szError);
		return 0;
	}

	do																		
	{																		
		if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)					
		{
			nDir++;															// the flight plan array
		}
		else
		{//-
			nCount++;
			
		}//-
	} while (FindNextFileW(hFind, &ffd));

	FindClose(hFind);												// Close filefind
	return nCount;
}

Open in new window


It is crashing in the do while loop, not at FindFirstFile.

Any ideas?
0
I am working on developing a Linux app for iPhones that will tell the user about the phone's lock status i. e. whether the phone is locked to a carrier or not, when connected to system
Also, if the phone is locked to a carrier then it's ESN status will also be reported.

This will help user to know the status of the phone before purchasing a used device.

I am aware that there are multiple websites providing this service.
I want to integrate this feature in my app,

I am developing this app in C++ in Linux environment.
I want to know if there is any API available to integrate this feature in my app.
If the API is available then from where I can get it.
0
Hello

I run into this problem with C++ code when on WIndows only.
Severity      Code      Description      Project      File      Line      Source      Suppression State
Error      C2664      'DWORD GetFileAttributesW(LPCWSTR)': cannot convert argument 1 from 'const char *' to 'LPCWSTR'      

This is when reading a string path , converting to char and calling the GetFileAttributes function. I am on windows 10 and compiling for a 32 bit arch (x86)
myfunc(const std::string & path){
DWORD  fileAttr=
GetFileAttributes(path.c_str()); //error list above!
}

Is there a elegant way to handle this? I donot want to be caught up in too much windows specific tailoring too much since my code is supposed to cross compile and run on linux and osx.

I understand the general problem = it is looking for a LPCWSTR long ptr to a 2 byte char. But how can i get it to work inside a #ifdef _WIN32 tag ,so that it stops complaining?
0
ardunio on board memory manipulation have a arduino mega now what is the best way to do the following, i want to have the program running and then update the array on board the arduino with out reloading the program, so lest say i have an array with 10 numbers and depending on the feed back from the card i am going to change location #4 of the in the 10 mem locations that i have set up how is the best way to do this please from the code running on the pc , would i access the arduino then the mem location and go from there, any ideas in this correct direction would be helpful
0
I had this question after viewing Explorer.exe crashing.
Hi, I have a simular issue on Windows 2016 Server RDS. I however do not have Microsoft Visual C++ 2008 installed but I do have the x86 and x64 versions of 2010 and 2012 installed. Do you suggest that is is a general issue with the Microsoft Visual C++ software of specific for Microsoft Visual C++ 2008?

Error:
The program iexplore.exe version 11.0.14393.2007 stopped interacting with Windows and was closed. To see if more information about the problem is available, check the problem history in the Security and Maintenance control panel.
 Process ID: a54
 Start Time: 01d3ec5f951cd3ff
 Termination Time: 8
 Application Path: C:\Program Files (x86)\Internet Explorer\iexplore.exe
 Report Id: e0176242-5852-11e8-90fe-001dd8b74bda
 Faulting package full name:
 Faulting package-relative application ID:
0
Unable to Debugg C++ ATL dll in C# . The ATL dll is not getting loaded. C# aplication is loading a interop but no pdb for interop is getting created.
Please let me know how to resolve this issue.
0
Dear experts,

Can some experts please refer a url for downloading 'dec-c++'.
It could be either a paid or a free version.

I am learner of C/c++ program, so i am happy to go with minimum cost to start the process with.

Thank you
0
https://m.youtube.com/watch?v=4UKkuO9iuq8

I am new to qt creator. The video shows a secondhand moving smoothly . QT creator comes with demos with secondhand ticking once per second. Can you point me to some code that will rotate a line around the center point as smooth as in that video and at varying speeds maybe ?
0
I have the following variadic macro code in a file named main.cc

#define DEBUG_PRINTF(fmt, ...) \
    do { if (verbose_flag) {\
        time_t t;\
        struct tm *t_info;\
        char buff[80];\
        time(&t);\
        t_info = localtime(&t);\
        strftime(buff, sizeof(buff), "%I:%M:%S", t_info);\
        std::string str(buff);\
        std::cout << str << " S" << my_server_instance << " ";\
        printf(fmt,__VA_ARGS__);}} while (0)

when I use g++ version 2.95.3-5 in CYGWIN like g++ -std=c++11 main.cc -c -o main.o to compile it, I get the compile error badly punctuated parameter list in #define and the error line is at printf(fmt,__VA_ARGS__);}} while (0). I have tried to fix it but I have not succeeded. How can this problem be fixed. I would like your directions on this.
0
Keep up with what's happening at Experts Exchange!
LVL 12
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

hello

i m a begineer in Qt based GUI development..
i m developing one simple gui based on am-5728 ti sitara arm cortex EVM board..

in my GUI app. i want to use pushbutton function link to the hardware gpio pushbutton.
means i can select that push button through pressing hardware button.
but cudnt link the event of hardware to my Qt app.

can u please suggest me the solution regarding this in Qt how to link both app to hardware button..


waiting for your valuable reply..

regards
Hardik
0
Dear All,

Can anyone have idea on mattermost webRTC integration. I am getting error while connecting video calls.

Thanks
0
using Visual Studio Web Page.  I have a DataGridView with a checkmark box in the 11th column.  I want to color the row red if checked..  here is the code I have found to do this but nothing is happening.  THANKS

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        CheckBox chk = (sender as CheckBox);
            if (chk.ID == "chkALL")
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    row.Cells[10].Controls.OfType<CheckBox>().FirstOrDefault().Checked = chk.Checked;
                    row.BackColor = System.Drawing.Color.Red;
                }
                else
                {
                    row.BackColor = System.Drawing.Color.White;
                   
                }
 
            }
        }
       
    }
0
Using Visual Studio 2010 Pro at work. That is, using C++03.

In this article https://www.experts-exchange.com/articles/3183/An-Introduction-to-STL-Algorithms.html is the code:
#include <iostream>
#include <list>
#include <iterator>
#include <algorithm>

int main()
{
    std::cout<<"Creating intList with values 0-9.\n";
    std::list<int> intList;
    for (int i = 0; i < 10; ++i)
        intList.push_back(i);
    
    std::cout<<"Displaying values held in list before modification:\n";
    std::copy(intList.begin(), intList.end(), std::ostream_iterator<int>(std::cout, " "));
    
    std::cout<<std::endl<<std::endl<<"Using find_if with unary predicate to display odd list items.\n";
    while (true) {
        std::list<int>::iterator found = std::find_if(intList.begin(), intList.end(), std::bind2nd(std::modulus<int>(), 2));    
        if (found != intList.end()) {
            std::cout<<"Found even #: " << *found <<". --> Removing it now"<<std::endl;
            intList.remove(*found);
        } 
        else
            break;
    }
    
    std::cout<<std::endl<<"Displaying values held in list after modification:\n";
    std::copy(intList.begin(), intList.end(), std::ostream_iterator<int>(std::cout, " "));
    
    std::cout<<std::endl<<std::endl<<"Replacing values that are divisible by 4 with 99.\n";
    std::replace_if(intList.begin(), intList.end(), std::bind2nd(std::modulus<int>(), 4), 99);
    
    std::cout<<"Displaying values held in list after 

Open in new window

0
pc to usb development, using c++ as the back ground code. i  am just starting so i need to be pointed towards a good cheapish usb development board, not sure what software and how this operates,
also some good reading materials, have down loaded a few books on the subject but not sure were to start.
at the moment all i need to do is to send some code to a board and turn some leds on and off just to get the code started
any help would be appreciated
0
This is how my program looks like:
_RecordsetPtr pRsUser = NULL;
if (m_AccessRepositoryMgr.Get_UserByName (&pRsUser, sName))
{
//dosomething;
}

/** User stub definition for function: bool CAccessRepositoryManager::Get_UserByName(_Recordset **, const CString &) */
bool (::CAccessRepositoryManager::CppTest_Stub_Get_UserByName) (::_Recordset ** ppUserList, const ::CString & sName)
{
bool __return = true;
return __return;
}

Here I want to set the value in ** ppUserList such that upon return from User stub function, in the code pRsUser should not be NULL.
0

C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.