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

Program crashes on delete

$
0
0
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class iint
{
public:
    iint();
   ~iint();
    iint(int);
    iint(iint&);
    iint& operator=(iint&);
    iint& operator+(int);
    void display();
protected:
    int val;
};

iint::iint() : val(0) {}
iint::iint(int i) : val(i) {}
iint::~iint()
{
    cout << "Destroying iint " << hex << this << endl; 
}
iint::iint(iint& i0)
{
    val = i0.val;
}
iint& iint::operator=(iint& i0)
{
    val = i0.val;
    return *this;
}
iint& iint::operator+(int i0)
{
    iint *i1 = new iint(val);
    i1->val += i0;
    return *i1;
}
void iint::display()
{
    cout << dec << val << "_" << endl;
}

int main()
{
    string s;
    
    iint ii0(7);
    ii0.display();
    
    iint ii1 = ii0 + 7;
    ii1.display();
    delete &ii1;  //program crashes here when trying to exit destructor
    cout << "Press <ENTER> to exit." << endl;
    getline(cin,s);
}

I am running this program in a VS2017 environment.

This program crashes when it executes the delete &ii1 instruction.  Why?

Of course I could simply define a local object in the + operator and return the result by value.  But I want to know why the program does not run as written.

Sometimes (not every time) I get the following message: "HEAP: Invalid address specified to RtlValidateHeap()".


Can't make _wfopen_s work

$
0
0

I have made a program in VS express 2010 with Windows 7 using _wfopen command, and which has been working fine. I have now transferred the program to VS Community 2019 with Windows 10, and some commands that previously gave a warning now give an error, among them _wfopen. I therefore switched to using _wfopen_s, but which I don't understand why doesn't work. The code is the following:

static FILE * licensefile; static TCHAR userpath[MAX_PATH]; patherror = SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, userpath); error = PathAppend (userpath, TEXT("DhruvaNada\\gnsh.dat")); hFile = CreateFile(userpath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ |

FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

Errorcheck = _wfopen_s(&licensefile, userpath, L"r");

hFile do not give INVALID_HANDLE_VALUE. 

Errorcheck gives the value 13, which should give "Permission denied". 

Thanks in advance.

Sincerely



Every Project I make fails to build with an "object reference not set to instance of object" error

$
0
0

I've decided to start learning C++ and since I'm already familiar with Visual Studio 2017 for sake of C#, I decided to stick with it for C++.

Unfortunately, every single project I make fails to build with the output window displaying:

1>------ Build started: Project: TestTwo, Configuration: Debug Win32 ------
1>Object reference not set to an instance of an object.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This particular project began as an Empty C++ Project, and is a basic "Hello World" program.
Below is the entirety of the code, which is all contained in the Main.cpp file, the only file in the entire solution aside from the default external dependencies.

#include <iostream>

int main()
{
	std::cout << "Hello World!" << std::endl;
	std::cin.get();
}
It's not this project alone, either. Even if I make a new console project and make no edits whatsoever to the project, I get the same error.

The error list is completely empty as well, offering no greater insight as to what the issue is. At this point, I've been banging my head against this for hours and am completely stumped. Any help would be appreciated.




Windows explorer getting hung if SetWindowsHookEx is used with keyboard or mouse hook and if I switch between the tabs using alt +tab on win10.

$
0
0

I am using SetWindowsHookEx  to monitor the keyboard eveNts. The code is working fine on Windows7 but when I ran the same code on the windows 10 then I am seeing the windows explore hang when I switch between the windows using alt tab

If I remove the hooking(SetWindowsHookEx ) then not seeing any hang

I am loading my dll from other exe where it will show the GUI

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
)
{
hInst=(HINSTANCE)hModule;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
::DisableThreadLibraryCalls((HMODULE)hModule);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
UnInstallKBHook();
break;

    }
    return TRUE;
}

extern "C" __declspec(dllexport) void InstallKBHook()
{

hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardHook,hInst,0);

}
int UnInstallKBHook()
{
if(hkb)UnhookWindowsHookEx(hkb);
return 1;
}


LRESULT __declspec(dllexport)__stdcall  CALLBACK KeyboardHook(int nCode,WPARAM wParam, LPARAM lParam)
{

if (((DWORD)lParam & 0x40000000) &&(HC_ACTION==nCode))
{
//nothing
}

LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam ); 
    return  RetVal;
}

Do I need to enable any permission on windows 10?


fatal error C1083: Cannot open include file: 'afxwin.h': No such file or directory

$
0
0

I just got a new computer
I installed Visual Studio 2017 Community Edition
I copied my project files onto my new computer
I get this error
fatal error C1083: Cannot open include file: 'afxwin.h": No such file or directory

This file afxwin.h is found in
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include

My projects VC++ Directories has Include set to:
$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;D:\amb\wDirReport\LimeLM\TurboActivate_4_1_9_0\API\C

I updated my VS2017 installation to include ALL MFC choices

Visual C++ ATL (x86/x64) with Spectre Mitigations

Visual C++ ATL for ARM

Visual C++ ATL for ARM with Spectre Mitigations

Visual C++ ATL for ARM64

Visual C++ ATL for ARM64 with Spectre Mitigations

Visual C++ ATL for x86 and x64

Visual C++ MFC for ARM

Visual C++ MFC for ARM with Spectre Mitigations

Visual C++ MFC for ARM64

Visual C++ MFC for x86 and x64

Visual C++ MFC for x86/x64 with Spectre Mitigations

Visual C++ MFC support for ARM64 with Spectre Mitigations


Please help me


crash When Use win32 api

$
0
0

When I Use HookWindow ( Like MessageBox : System Class #32770 ) And After That SubClassing It , And Close Main Form There is No Problem But When Destroy ( Close The Window App ) The Application I See Crash ( Hang The System ) , How Can Solve it 

In memcpy_s function, Is taking destSize as sizeof(m_pDataToSend) is correct?

$
0
0

Hello all,

I replaced memcpy with memcpy_s as memcpy is a banned function and wanted to know the parameter values passed in memcpy_s are correct? 

memcpy_s function has below parameters:

dest (this is of BYTE *)
destSize (this is sizeof(Byte pointer variable)
src (this is also of type BYTE *)
count (passing the size)

Is taking destSize as sizeof(m_pDataToSend) is correct?

bool ERHttpClient::SetDataToSend(BYTE *data, unsigned int dataSize)
{
    if (data == NULL || dataSize < 0)
    {
        return false;
    }

    if (m_pDataToSend != NULL)
    {
        delete[] m_pDataToSend;
    }
    m_pDataToSend = NULL;
    m_pDataToSend = new BYTE[dataSize];
    if (m_pDataToSend != NULL)
    {
       // memcpy(m_pDataToSend, data, dataSize);
    memcpy_s(m_pDataToSend, sizeof(m_pDataToSend), data, dataSize);
        m_dataToSendSize = dataSize;
        return true;
    }

    return false;
}

m_pDataToSend is declared like as shown below:

   BYTE *m_pDataToSend;

Thank you in advance.

How would I create a while loop so that the program reads in character values from the keyboard until an asterix is entered

$
0
0

I've recently started to learn c++. One of the tasks I came across asks for me to 

Set up a while loop so that program reads in character values from the keyboard until an asterix is entered. 
You will need to count the number of characters entered. Do not include the asterix in your count.
Output the number of characters entered.

I think my issue mainly falls in the category of not knowing how to instruct the programme to differentiate between the asterisk (*) and other characters in the same string of word/letters.

	int number;
	int total;
	string input;

	bool correct = 0;
	do 
	{

	cout << "this loop will stop when an asterisk has been inputted" << endl;
	cin >> input;

	if (input == "*")
	{
	number = input.length();
	total = number - 1;
	cout << "You have " << total << " in your sentence." << endl;
	correct = 0;
	}
	else
	{
	number = input.length();
	total = number;
	cout << "You have " << total << " in your sentence." << endl;
	correct = 1;
	}

	} while (correct);

Studious Student



Fatal errors CVT1100 and LNK1123

$
0
0

I am working on a project in C on VS Community 2019 with Windows 10, which has been working, but which now gives the following errors when compiling:

1>CVTRES : fatal error CVT1100: duplicate resource.  type:ICON, name:1, language:0x0409
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

These errors occured after including an old rc file. The code of the program and the rc file have been copied from a project that was on a Windows 7 machine with VS Express 2010. 

I have tried most of the solutions I've found on the internet: I have changed Propertise > Linker > General > Enable Incremental Linking to No, and I have changed the name of all the cvtress.exe files I have found.

Thanks in advance.

Sincerely


Anyway to offer feedback to Microsoft on MFC?

$
0
0

I don't know if Microsoft still has any interest in feedback on MFC. Are they still developing it? If anyone knows a good forum to provide such feedback, could you please let me know?

I went to their website but all the feedback links are related to newer technologies.

Specifically, I noticed that the CRecordset class does not define RFX_BigInt_Bulk(), when this seems like an obvious need.

I believe it should look something like this:

void AFXAPI RFX_BigInt_Bulk(CFieldExchange* pFX, LPCTSTR szName, __int64** prgBigIntVals, LONG_PTR** prgLengths)
{
    ENSURE_ARG(AfxIsValidAddress(pFX, sizeof(CFieldExchange)));
    ENSURE_ARG(AfxIsValidString(szName));

    UINT nField;
    if (!pFX->IsFieldType(&nField))
        return;

    ENSURE_ARG(prgBigIntVals != NULL && prgLengths != NULL);
    switch (pFX->m_nOperation)
    {
        case CFieldExchange::AllocMultiRowBuffer:
        {
            // The buffer pointer better be initialized to NULL
            // or cleanup in exceptional cases may fail
            ASSERT(*prgBigIntVals == NULL);
            ASSERT(*prgLengths == NULL);

            int nRowsetSize = pFX->m_prs->GetRowsetSize();

            // Allocate buffers to hold data and length
            *prgBigIntVals = new __int64[nRowsetSize];
            *prgLengths = new LONG_PTR[nRowsetSize];
        }
        break;

        case CFieldExchange::DeleteMultiRowBuffer:
            delete[] * prgBigIntVals;
            *prgBigIntVals = NULL;

            delete[] * prgLengths;
            *prgLengths = NULL;
            break;

        default:
            AfxRFXBulkDefault(pFX, szName, *prgBigIntVals, *prgLengths,
                SQL_C_SBIGINT, sizeof(__int64));
            break;
    }
}


Jonathan Wood • Black Belt Coder


Property File's Header Directory Not Being Used

$
0
0

Hello Folks:

   Developing on Windows 10 Pro, Visual Studio 2019 Community, Win32, no MFC.

   I'm doing something wrong, but I'm not seeing it. 

   I've recently re-installed Windows 10 Pro on my development system.  For some reason Visual Studio appears to be unable to extract a critical directory name from a property file.

   Several applications and most libraries I've written depend on thecommon_cpp_headers property file to point to a directory that contains a collection of headers. 

   Building one of those libraries displays this problem:


   Building the Registry Utilities library can't find some header files.

   These header files are in a directory, D:\utilities\code\windows_files\headers, with many other commonly included header files.  The Environmental variableUTILITIES_HEADER_PATH points to this directory. 

   Here are the properties for this property file:


   Here is the build config manager for this library. 

   As you can see, this build is for the debug and Win32 configuration:

   Here is the folder being identified by the environmental variable, and the header file name. 


   There is that directory, identified by the environmental variable, followed by the filename, text_utility.h.  

   Why can't Visual Studio find it?

      Thanks
      Larry

click location within MFC Picture control

$
0
0

I have a picture control in my dialog box, showing some image.

I need to detect the click location within thisMFC picture control (IDC_STATIC_BITMAP).

How do I do that?

Thank you.

 

About MAX_PATH

$
0
0

Hello

I use below code to save a path location for a file specified by the user:

wchar_t filePath[MAX_PATH] = getFilePath();

MAX_PATH is set to be 260, but is there any possibility if the file path is over 260 characters? What happens if the file path gets over 260 characters?

Cheers


Changing MFC property sheet look

$
0
0

I have the following code which does not show my property sheet in the OutlookBar Style.

         AppPropSheet derives from CMFCPropertySheet
        CRunJobPage and CCreateJobPage Derives from CMFCPropertyPage

        AppPropSheet sht(_T("Backup"));

         CRunJobPage runjobpg;
         CCreateJobPage crjobpg;
                sht.AddPage(&crjobpg);
        sht.AddPage(&runjobpg);
      
        sht.m_shtSelImages.Create(IDB_BITMAP28, 32, 1, RGB(128, 128, 128));
        sht.SetIconsList(sht.m_shtSelImages.m_hImageList);
        sht.SetLook(CMFCPropertySheet::PropSheetLook_OutlookBar, 32);
        
        sht.m_psh.dwFlags |= PSH_NOAPPLYNOW;
       sht.DoModal();

Regards,

Ramesh D

How to prevent UWP application load a normal Windows DLL, when I call SetWindowsHookEx to do DLL injection.

$
0
0

My problem is a little bit complex.

I'm using SetWindowsHookEx  to do DLL injection. This works fine for desktop applications. But for one application installed from Microsoft AppStore, when I call SetWindowsHookEx to do DLL injection, there will be an Error dialog say something like 

"SomeApp.exe -- Bad Image
 xxxxxx\xxxxx\myDll.dll is either not designed to run on Windows or it contains an error........  Error status 0xc000012f".

After searching in Google, I know something about UWP. And this error should be caused by the incompatible between Microsoft UWP application and normal desktop application. My question is, since Microsoft designed the isolation between UWP application and normal desktop applications, why 'SetWindowsHookEx' will still cause my normal desktop version DLL being loaded by an UWP application? 

How can I prevent my normal Windows desktop DLL being loaded by application from Microsoft AppStore, when I call SetWindowsHookEx?

Thanks in advance!
seth


How to update edit box instantly??

$
0
0
Hi,

I have tried to search through the internet for this issue. Is it possible to display the test instantly after doing the command below in visual c++ 6:

m_sMessage = "Simulation starts.";
UpdateData(FALSE);

After I step through UpdateData(FALSE), the test stored in CString m_sMessage(member of my editbox) is not being updated into the editbox immediately. The text will only be added after the application has run through all the codes. Is there any command I can add after the UpdateDATA command to show the text in the edit box immediately? I know this might sound very silly to the expert but it has wasted a lot of my time to search in internet for the solution. Hopefully I can get a reply regarding this issue, sorry for asking such an easy question. :)

How to remove a category from "Choose commands from" list in customizing Quick Access Toolbar

$
0
0

I have a ribbon created from CMFCRibbonBar, which contains a Debug category which is used for development only. However this category appears in "Choose commands from" list when clicking "Customize Quick Access Toolbar"->"More commands..." in running the application. We can hide the Debug tab on the ribbon, could you please let me know how to remove the Debug category from "Choose commands from" list?

Thanks

c++ code/Library for mirroring Windows using Miracast protocol

$
0
0

I want to build windows software (not windows app) that will mirror the windows screen to a TV using Miracast protocol. I know that this is built-in on windows 10 using the start menu. But i want my application to be able to do that as well.  My question is if there is c++ code or lib that i can use to do that.

Is there any way to 'regulate' width of line width at DirectX11?

$
0
0
I draw the line width 'D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP' type.
But I can't find the way to regulate the width.
Please let me know.

Getting the list of available serial ports in C++

$
0
0
How do I get the list of available serial ports in C++? I am able to do it in Visual Basic, but I can seem to do it in C++.

Got RAM?
Viewing all 15302 articles
Browse latest View live


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