Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

Unable rebuild solution in Visual Studio

$
0
0

Hi All,

The following error message is occurring again and again while rebuilding my VS-2019 solution since last Wednesday day. I have done all my possible troubleshoot at my end. However, issue still persist. Could you please help me on this?

1. Giving full access to solution folder 

2. Remove read-only access to the folder 

3. Disable security essentials/firewall 

4.Provide full access to the hard disk driver 

ErrorCS0009Metadata file 'E:\.............................ces.dll' could not be opened -- Access to the path 'E:\............................................ces.dll' is denied.

Thank you!


Memory checking tool

$
0
0

I need some tool to detect where memory is leaking.

Can anybody recommend some tool in Visual Studio or separate one?

MFC requires C++ compilation (use a .cpp suffix)/ C-files in a MFC-project?

$
0
0

Hi!

I working with a MFC project in VS2010, the project compiling and the program is working.

Now I will try to add this project to a solution where we already have about 20 old c project. I do this because it belongs with that solution and I also want to use some functions in some of these c-files.

I have included the c-file (massivecfunctions.c ), with the functions I want to use, in my project with the /Tc flag only on that file(rest of my MFC project I have /Tp). When compiling  with #include "stdafx.h" I getting this error:

Error1 error C1189: #error :  MFC requires C++ compilation (use a .cpp suffix)c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afx.h15

When compiling without #include "stdafx.h" and "Not Using Precompiled Headers" on that file(rest of my MFC project I have Create (/Yc)).  I get this error:

Error4 error LNK2019: unresolved external symbol "int __cdecl getint(int)" (?getint@@YAHH@Z) referenced in function "protected: __thiscall CStartupThrd::CStartupThrd(void)" (??0CStartupThrd@@IAE@XZ)C:\StartupThrd.obj

Is it possible to use C-files in a MFC-project? 

Regards

Whane


Creating Virtual Directory in IIS

$
0
0

I am working in installer. I need to create one application/Virtual Directory under my own "MySite" . it is not under "Default Web Site". following are code using for same..But I am unable to create. My requirement is as below in IIS.

sites

       MySite

            TestApp

                 reports

      Default Web Site.

           asp-net

My requirement is to create TestApp entry and Virtual directory for this under MySite. I am able to create under Default Web Site but unable to create under MySite. Can anybody please suggest ?

physicalPath = "AM\\MH"

virtualpath = "TestApp"

altVirtualPath = "reports"

HRESULT CreateIIS7VirtualDirectory(BSTR physicalPath, BSTR virtualPath, BSTR altVirtualPath)
{
CComPtr<IAppHostWritableAdminManager> adminManager;
HRESULT hr = adminManager.CoCreateInstance(__uuidof(AppHostWritableAdminManager));


if(FAILED(hr))
return hr;

CComBSTR sitesSection("system.applicationHost/sites");
CComBSTR path("MACHINE/WEBROOT/APPHOST/MySite");

CComPtr<IAppHostElement> sitesElement;
hr = adminManager->GetAdminSection(sitesSection, path, &sitesElement);

CComPtr<IAppHostElement> siteElement;
hr = GetSiteElement(sitesElement, siteElement);

CComPtr<IAppHostElementCollection> applications;
hr = siteElement->get_Collection(&applications);

CComPtr<IAppHostElement> application;
hr = GetApplicationElement(virtualPath, applications, application);

hr = SetApplicationVirtualDirectory(application, physicalPath, CComBSTR("/"));

SetApplicationVirtualDirectory(application, physicalPath, altVirtualPath);

hr = adminManager->CommitChanges();

SetApplicationPermissions(virtualPath);

return S_OK;
}

Very strange phenomenon: output file filled or truncated with binary zeros. What could cause that?

$
0
0

Very strange phenomenon: output file filled or truncated with binary zeros

I have recently encountered a very strange phenomenon which I'm at a loss to account for.  I have had reports in the last few weeks from 4 users who say that they have lost data from the file that my application writes to.  I have been able to see two of the files.  One of them is about 34KB and viewed in a binary editor it contains nothing but binary zeros.  The other is about 40MB and if I view it in a binary editor, it is fine up to offset 02600000 (hex), but from 02600000 onwards it contains nothing but binary zeros.

I don't know for sure that all 4 have experienced the same thing, but it sounds as if 3 of them have had very similar truncation, and the 4th has lost everything.

The way my app saves is like this: the app writes to a temporary file.  If any error occurs, the save is aborted. If the save succeeds, the original file is deleted and the temporary file is renamed to replace it.  None of the users reported any problems when they saved.  The problem occurred the next time they tried to view their data.

I estimate the chance that this was caused by a bug in my code as approaching zero.  I am a very experienced coder and I have checked it meticulously and can find no way that my code could have done this.  The code uses CFile::Write to write to the file.  The truncated file actually split a keyword that was being written out.  Low-level buffering code might conceivably have done that, and my code does do its own buffering, but this part of the code has not been changed in over 10 years, and has behaved faultlessly throughout that time.  If an error did occur, I can think of no way that it would result in binary zeros being output.  Also, why do zeros start at hex 02600000?  Surely it can't be a coincidence that it starts at a round number that ends in 5 zeros?  But this is a round number only in hex terms, and my code doesn't use hex for buffer sizes (or any sizes). All sizes are specified in decimal values.

So I ask myself - Why after years of working fine have I had 4 reports like this in a window of less than 3 weeks? Why binary zeros?  Why in the truncation case I say did they start on a (hex) round number?

I have not been able to confirm that they're all using the same version of my software, but it looks like that.  That version has been around for just under a year.  Why problems now?  I only know the Windows versions for two of them.  One had Windows 7 and another had Windows 10.  One user said they hard recently run a defrag on their hard drive.  Could that be relevant?  An attempt to defrag an SSD maybe? (I don't know if they have SSDs).  A virus?  A weird new fault in a service patch, miraculously affecting both Windows 7 and Windows 10?

Any ideas anyone?


Simon

pthread link error

$
0
0

I made some code for multithreading from Visual Studio 2019.

I installed pthread using NuGet installer.

Compile succeeded but errors occur in link like following.

Can anybody let me know what file should I add to the project and how to do that?

How to compare two files line by line after storing them in vector

$
0
0

i have two text files named totalfiles.txt and uploaded.txt i am storing both of them in a vector now offcourse when this program will run for a very first time uploaded.txt will be made and it will be empty and first file will be written in it after its successfully uploaded to the server what i want is some kind of method to compare both .txt files so if files that are already uploaded to server don't get uploaded again so is there any method to do that in c++? again at the beginning i am going to store the files in vector and i need to do above operation via vector and not using .txt files directly with fstream

ifstream read2("ScannedFiles.txt");
ofstream read3("Problem.txt", ios::app);
fstream uploaded("Uploaded.txt", ios::app);
vector<string>filen2;
vector<string>upl;
string st3;
string st2;
while (getline(read2, st2))
{
if (st2.size() > 0)
filen2.push_back(st2);
else
break;

}
while (getline(uploaded,st3))
{
if (st3.size() > 0)
upl.push_back(st3);
else
break;
}
<pre>for (vector<string>::iterator t = filen2.begin(); t != filen2.end(); t++)

Managed c++ use unmanaged c++ static member cause link error

$
0
0

I'm using managed c++/cli to wrap a C++ class with a static string member to save current project directory location, like the following:

namespace Core {

   class Application {

   public:

     static string ProjectPath;

      …

   }

}

and I've initialized it at the top of the cpp file:

   string Application::ProjectPath = "D:\\Documents\\Path"; 

When trying to access this static var in my cli wrapper class, like the following:

namespace Wrapper {

    ...

void Application::ProjectPath::set(String^ path) {

     // to_string() is my function to convert cli String^ to string 

     Core::Application::ProjectPath = to_string(path); // <-- cause a link error!

     ...

it caused 2 link errors said: error LNK2020: unresolved token (0A000BB9) "public: static class std::basic_string 

and  error LNK2001: unresolved external symbol "public: static class std::basic_string.

Any clue for this?




ComStat.cbInQue always returns 0

$
0
0

I just started working on serial communication in VC++ and am facing an issue while reading the data (surprise surprise) from the receiver port.

All the code is supposed to do is take input from one edit box, send it to COM2, COM2 is linked with COM3, and this data should be read from COM3. I have used the Serial Class made by Tom Archer and Rick Leinecker, from this link http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2503/CSerial--A-C-Class-for-Serial-Communications.htm

In their definition of their ReadData function, they use the ComStat.cbInQue function determine the number of bytes read. This always remained 0. So I added aWaitforData function to wait for some data to arrive. But the number of bytes read is still 0.

Any ideas why this might be happening?

This is the definition for the ReadData function:

int CSerial::ReadData( void *buffer, int limit )
{

      if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );

      BOOL bReadStatus;
      DWORD dwBytesRead, dwErrorFlags;
      COMSTAT ComStat;
      CCommTestDlg::WaitForData(17, 50); // I have specified the exact number of bytes it is supposed to receive: 17
      ClearCommError( m_hIDComDev, &dwErrorFlags, &ComStat );
      if( !ComStat.cbInQue ) return( 0 );

      dwBytesRead = (DWORD) ComStat.cbInQue;
      if( limit < (int) dwBytesRead ) dwBytesRead = (DWORD) limit;

      bReadStatus = ReadFile( m_hIDComDev, buffer, dwBytesRead, &dwBytesRead, &m_OverlappedRead );
      if( !bReadStatus ){
            if( GetLastError() == ERROR_IO_PENDING ){
                  WaitForSingleObject( m_OverlappedRead.hEvent, 2000 );
                  return( (int) dwBytesRead );
                  }
            return( 0 );
            }

      return( (int) dwBytesRead );	




}

This is where it applies in the main code:

CSerial serial;
CSerial serial2;
serial.Open(2, 9600); // Handle.Open(port number, baudrate)
serial2.Open(3, 9600);

if (serial.Open(2, 9600))
{
 static char szMessage[] = "This is test data";
 int nBytesSent = serial.SendData(szMessage, strlen(szMessage));
 ASSERT(nBytesSent == strlen(szMessage));
}
else
 AfxMessageBox("Failed to open port!");

if (serial2.Open(3, 9600))
{ 
char* lpBuffer = new char[500]; // Things start going downhill from here.
	int nBytesRead = serial.ReadData(lpBuffer, 500);
 
    if(nBytesRead>0)
	  AfxMessageBox("Done");
    else
      AfxMessageBox("Not Done");

    delete []lpBuffer;
}

else
 AfxMessageBox("Failed to open port!");
 serial.Close();
 serial2.Close();

PS:

I can see that COM3 is receiving the exact number of bytes, I just am not able to gain access to it.

How to set an image to a button in a ribbon using MFC VC++ ?

$
0
0
 I am changing the look of my CMFCRibbonBar. I want to add icon to its button, so i added my png images as resources and gave them IDs, but i can't seem to connect them to buttons.

I added this code to my CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) function:

CButton *pButton = (CButton *)GetDlgItem(m_Print);
if (pButton && pButton->GetSafeHwnd())
{
    pButton->SetIcon((HICON)LoadImage(AfxGetApp()->m_hInstance,
        MAKEINTRESOURCE(IDB_Print),
        IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR));
}
pButton = (CButton *)GetDlgItem(m_SaveSett);
if (pButton && pButton->GetSafeHwnd())
{
    pButton->SetIcon((HICON)LoadImage(AfxGetApp()->m_hInstance,
        MAKEINTRESOURCE(IDB_SaveSettings),
        IMAGE_BITMAP, 32, 32, LR_COLOR));
}

c101008d error

$
0
0

I often get error c101008d when building my project.  The only way to recover is to reboot the PC, which in my case takes almost three minutes.  After that the project builds and runs correctly.  Until the next error, usually some time later in the day.  Then it's boot, boot, ....

Does anyone know a better way to recover from this error, or better yet, how to prevent it?  I use Malwarebytes and SUPERAntiSpyware on Windows 10.  I do not use Norton's.

Missing component VS 2017

$
0
0

When building a project, I am getting a linker error" fatal error LNK1104: cannot open file 'libcpmt.lib'". in VS 2017. Could someone please tell, which is the particular component of Visual Studio Installer that contains the library so that I ca install it.

The difference between LTEXT and RTEXT

$
0
0
What is the difference between LTEXT and RTEXT name in RC file for dialog window?

After adding header #include , linker displays error: LINK : fatal error LNK1104: cannot open file 'concrtd.lib'

$
0
0

I want to use concurrent_queue, but after including the header #include <concurrent_queue.h> in *.cpp file where I want to use concurrent_queue instance and compiling the project, the linker displays the following error: LINK : fatal error LNK1104: cannot open file 'concrtd.lib'. I had tryed to add to Project Properties\Linker\General\Additional Library Directories the following path:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\store

or

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86

and add to Project Properties\Linker\Input\Additional Dependencies the following name: concrtd.lib

but this didn't help me. By the way, when I try to include #include<concurrent_vector.h>, the same story arises. What do I need to do to fix this error? I will be very grateful for your help.

Visual C++ functions

$
0
0

Hi;

I am learning about C++ functions and I confront to some problems , so I need some help.

Here is my code:

#include "stdafx.h"


int main()
{
	int num1;
	printf("Enter your number.");
	scanf_s("%d", &num1);
	printf("\nYour answer is:");
	printf("%d", sqr(num1));
}

int sqr(int x)
{
	int y;
	y = x*x;
	return(y);
}

When I run this application , I confront to the following error:

"error C3861: 'sqr': identifier not found"

What can I do to solve this problem ?



PipeClient compilation problem

$
0
0

I need a PipeClient-Server pair for my C++ application. To say it is mine is an overstretch, the codes are from the GitHub.This is the Client. While attempting to compile it I get a note that warnings will be treated as errors. I went into the Project Properties and turned it off, besides I turned ALL the warnings off, nonetheless I get two errors after warnings WERE treated as errors. I have VS2017 Community Edition.

In this code slice (CPipeCLient.cpp, line 47 :

void CPipeClient::SetData(std::wstring& sData)
{
	memset(&m_buffer[0], 0, AU_DATA_BUF);
	//memcpy(&m_buffer[0], sData.c_str(), __min(AU_DATA_BUF, sData.size()));
	wcsncpy(&m_buffer[0], sData.c_str(), __min(AU_DATA_BUF, sData.size()));   // <== error
}

This ia the error message:

Severity	Code	Description	Project	File	Line	Suppression State
Warning	C4996	'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	MFCaptureD3D	c:\cplusplus_projects\mfcaptured3d\mfcaptured3d\cpipeclient.cpp	47	

But when I try to use wcsncpy_s I get another error. This time the Intellisense says that there is no such overload.

How to handle it?

Thanks, - MyCatAlex

Can we declare a const variable only once and then use it in same exe whenever it runs?

$
0
0

i am curious is there any way by which i declare a global constant variable and then change it only once when the .exe of my cpp code is ran for first time.

This const variable is suppose to store the time of first run time of exe and then never change it and store it permanently and use this value whenever that const variable is accessed by any where in the code?

if its not possible is there any other way without using .txt files to store the first run time of my exe because that won't be suitable at all user

plus i don't want to store this info in database of any kind

fatal error LNK1104: cannot open file

$
0
0

Link error occur like following

fatal error LNK1104: cannot open file ....


Here is the codes.

#include <iostream>
#include <cstring>
using namespace std;

class String
{
private:
    char* s;
    int size;
public:
    String(const char* str = NULL); // constructor 
    ~String() { delete[] s; }// destructor 
    String(const String&); // copy constructor 
    void print() { cout << s << endl; } // Function to print string 
    void change(const char*);  // Function to change 
};

String::String(const char* str)
{
    size = strlen(str);
    s = new char[size + 1];
    strcpy(s, str);
}

void String::change(const char* str)
{
    delete[] s;
    size = strlen(str);
    s = new char[size + 1];
    strcpy(s, str);
}

String::String(const String& old_str)
{
    size = old_str.size;
    s = new char[size + 1];
    strcpy(s, old_str.s);
}

int main()
{
    String str1("GeeksQuiz");
    String str2 = str1;

    str1.print(); // what is printed ? 
    str2.print();

    str2.change("GeeksforGeeks");

    str1.print(); // what is printed now ? 
    str2.print();
	return 0;
}

What should I do?

Does this error occur due to the visual studio version is community?

Could someone please help me injecting interface as smart pointer into the constructor using Dependency Injection is feasible to implement in C++?

$
0
0

Hello all,

I wanted to implement dependency injection in my project as part of the requirement.

Below is my understanding before proceeding with the implementation:

We have Windows Management Instrumentation (WMI) implementation as a separate interface and using that we are reading WMI data (i.e., machine name, bios serial no etc.). Herewmi_interface is the separate module and making it loosely coupled. So that I can inject this class into the top layer to use thewmi_interface functionality(i.e., manager_impl).

wmi_interface implementation:

wmidata.h

class wmi_interface
{
public:

virtual read_wmi_data() = 0;

virtual ~wmi_interface();
};

manager_impl implementation:

In the top  layer i.e., in manager_impl class, we are injecting thewmi_interface as a smart pointer into the constructor.

manager.h file

class manager_interface
{
public:
virtual ~manager_interface();

virtual create_subscription() noexcept = 0;

};
// Below is the global function outside of the class

std::unique_ptr<subscription_manager_interface> get_manager_interface(
std::unique_ptr<wmi_interface> wmi);
}

manager.cpp file

class manager_impl : public manager_interface
{
public:
explicit manager_impl(std::unique_ptr<wmi_interface> wmi) :
m_wmi{ std::move(wmi) })
{
}

private:
std::unique_ptr<wmi_interface> m_wmi;
};

std::unique_ptr<manager_interface> get_manager_interface(std::unique_ptr<wmi_interface> &wmi)
{
return std::unique_ptr<manager_interface>(std::make_unique<manager_impl>(std::move(wmi)));
}

Using dependency injection, I wanted to make this application module as plug and play so that at the later point of time i can create some other interfaces likeprodut_data (to get the product information) and device_data (to get the device information). So that i can inject this data also tomanager_impl class constructor.

Is my proposed implementation is valid?

Do we need interface with virtual function to implement dependency injection?

Could someone please help me injecting interface as smart pointer into the constructor using Dependency Injection is feasible?

And also in future if i am creating new interfaces, Can I inject those interfaces also in the constructor of the top layer?

Thanks in advance.

How to use unmanaged C++ dll in the C++/CLI project?

$
0
0

Hi,

How Can I can use dll generated by unmanaged C++ library into C++/CLI project.

Viewing all 15302 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>