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

VS2010 and above causing heap curruption in RPC client call

$
0
0

I got heap corruption in test program as below in VS2010 (it worked fine in VS2008). It happens in last COM call before returning. In VS2010 I can switch platform toolset from v90 to v100 to reproduce this problem in debug/release mode. The same problem exists with VS2019 as well. I can't find any place leading to this corruption. Can anyone help? Thanks!

#pragma once #include <tchar.h> #include <comdef.h> #include <comcat.h> #include <atlcomcli.h> #include "opccomn_i.c" #include "OpcEnum_i.c" #include "opchda.h" int _tmain(int argc, _TCHAR* argv[]) { CoInitializeEx(NULL, COINIT_MULTITHREADED); CLSID serverCLSID; CLSIDFromString(CComBSTR("{6A5EEDEC-1509-4627-997F-993CCB65AB7C}"), &serverCLSID); COSERVERINFO cInfo = { 0 }; cInfo.pwszName = L"localhost"; MULTI_QI cResults = { 0 }; cResults.pIID = &IID_IOPCHDA_Server; HRESULT hr = CoCreateInstanceEx(serverCLSID, NULL, CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, &cInfo, 1, &cResults); if (FAILED(hr))
   return EXIT_FAILURE;

CComPtr<IOPCHDA_Server> server; server.p = (IOPCHDA_Server*)cResults.pItf; OPCHANDLE* hServerItem = NULL; OPCHANDLE hClientItem = 1; HRESULT* pErrors = NULL; LPWSTR pszItemID = L"Static Data/Square [15 min]"; hr = server->GetItemHandles(1, &pszItemID, &hClientItem, &hServerItem, &pErrors);if (FAILED(hr))
  return EXIT_FAILURE;

OPCHDA_TIME start, end; start.bString = true; start.szTime = L"NOW-18MO"; end.bString = true; end.szTime = L"NOW"; CComPtr<IOPCHDA_SyncRead> ipOPCHDA_SyncRead; hr = server->QueryInterface(IID_IOPCHDA_SyncRead, (void**)& ipOPCHDA_SyncRead);if (FAILED(hr))
  return EXIT_FAILURE;

OPCHDA_ITEM* pItemValues = NULL; HRESULT* pErrors1 = NULL; hr = ipOPCHDA_SyncRead->ReadRaw(&start, &end, 10, true, 1, hServerItem, &pItemValues, &pErrors1); //CoUninitialize(); return(EXIT_SUCCESS); }



JH



Visual Studio 2010 redistributable superseded by VS 2014 redistributable?

$
0
0

An application I installed requires VS2010 redistributable.  I have downloaded this but cannot install it, the installer gives an error message to the effect that "a more recent version" is on my computer: "A newer version of Microsoft Visual C++ 2010 Redistributable has been detected on the machine.  Please resolve."  But what is installed is actually VS2014, according to the registry: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64, Installed REG_DWORD =0x00000001.

  Is there a way to install VS2010 redistributable in this case?  Or will the VS2014 Runtimes do the job that my software package needs?


gas turbine data storage

How to add tabs dynamically to CSplitterWnd window?

$
0
0

Hi

I have created multiple windows (views) in my MFC application using CSplitterWnd class. In one of the window (view) i need to add tabs dynamically..

Can any one help me on how to add tabs to my CSplitterWnd window.?

Thanks in advance.



main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16

$
0
0

------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------

Compiling...

main.cpp

Linking...

main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16

C:\Documents and Settings\Administrator\Desktop\dev Projects\HW\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 1 unresolved externals

Build log was saved at "file://c:\Documents and Settings\Administrator\Desktop\dev Projects\HW\HelloWorld\HelloWorld\Debug\BuildLog.htm"

HelloWorld - 2 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please bear in mind that I'm *very* much a newbie to much any form of programming.  Maybe someone can help me out a little.

The above is the output from Build as I try to compile the following code:

#include

<windows.h>

int

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lcCmdLine, int nShowCmd)

{

MessageBox(NULL,

"All your base are belong to us!", "Hello World", MB_OK | MB_ICONEXCLAMATION);

return 0;

}

 

Can anyone tell me what is wrong?

Extracting Certs from Server Cert Store?

$
0
0

Like how there's a way to extract certs from the root cert store, isn't there also a way to extract certs from the server cert store?  In my current situation I'm hard-coding the certificate into the ASIO SSL context for my app, but I want to know how to get them from the store in a loop.  I installed a new certificate just now and I want to use it, but I want to avoid having to hard-code it again if possible.

Also, if I do this, will I still have to hard-code the RSA Private Key?  There doesn't seem to be a way to install it anywhere after all.

SetThreadPriorityBoost does not work.

$
0
0

Hi Guys,

I created 8 threads, 2 of them are set to THREAD_PRIORITY_ABOVE_NORMAL priority, rest of them use the default priority.

Then I run SetThreadPriorityBoost to disable the PriorityBoost for the 6 normaldefault threads. Then I kick of these 8 threads.

However, after the 2 high priority threads start to run, I still see the 6 default priority threads got CPU time..

According to the following article, 'Threads are scheduled in a round-robin fashion at each priority level, and only when there are no executable threads at a higher level does scheduling of threads at a lower level take place.'

https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setthreadpriority 

I have use SetProcessAffinityMask to limit all threads to 2 CPUs.

Why the 6 default priority threads are still running???  

Any suggestions would be appreciated.

Here is my code.

I'm running the program in windows 10 system with 8 processors .

#include <windows.h>
#include <stdio.h>
#define THREADCOUNT 8

DWORD AccessSharedResource(LPVOID par);

int main()
{

 printf("Run SetProcessAffinityMask to bind all threads to CPU0 and CPU2\n");
	if(!SetProcessAffinityMask(GetCurrentProcess(),0x05))				
		{
			DWORD dError=GetLastError();
			printf("SetProcessAffinityMask failed with error:%d\n",dError);
		}
	HANDLE hThread[THREADCOUNT];
	DWORD lpThreadId;
	for(int i=0;i<THREADCOUNT;i++)
	{
		hThread[i]=CreateThread(
			NULL,//secuirty flag
			0,//default stack size
			(LPTHREAD_START_ROUTINE)AccessSharedResource, the function associated to this threa
			(LPVOID)i,//the parameter passed to function AccessSharedResource
			CREATE_SUSPENDED,&lpThreadId // thread Identifier
			);
		if(hThread[i]==NULL)
		{
			printf("Failed to create Thread, errorcode=%d",GetLastError());
			return 0;
		}
	}

	for(int i=0;i<THREADCOUNT;i++)
	{
		if(i>=THREADCOUNT-2)
			{
			if(SetThreadPriority(hThread[i],THREAD_PRIORITY_ABOVE_NORMAL))
				{
					printf("SetThreadPriority THREAD_PRIORITY_ABOVE_NORMAL to thread %d\n",i);
				}
				else
					{
						int dError=GetLastError();
						printf("SetThreadPriority failed with error %d\n",dError);
					}
			}
			else
				{
						if(SetThreadPriorityBoost(hThread[i],TRUE))//Disable Priority boost for thread 0~thread5
							{
								printf("SetThreadPriorityBoost disable for thread %d\n",i);
							}
				}

	}
	
	
	for(int i=0;i<THREADCOUNT;i++)
	{
	  printf("priority of thread %d is %d\n",i,GetThreadPriority(hThread[i]));
		ResumeThread(hThread[i]);
	}
	WaitForMultipleObjects(THREADCOUNT,	hThread,true,INFINITE);
		for(int i=0;i<THREADCOUNT;i++)
	{
		CloseHandle(hThread[i]);
	}

	return 1;	
}

DWORD AccessSharedResource(LPVOID par)
{
	

	for(int i=0;i<10000000;i++)
	{
		for(int j=0;j<10000000;j++)
		{
			if((int)par>=6)
  	{
  			printf("Thread id=%d is running on CPU %d\n",(int)par,GetCurrentProcessorNumber());
  	}
  	else
  		{
  			printf("..............You should not see this until Thread 6&7 complete....................\n");
  		}
		}
	}
  if((int)par>=6)
  	{
  		printf("Thread %d has compelted\n",(int)par);
  	}

	return 0;
}





How to restrict some items to be not selected in CComboBox?

$
0
0

In a MFC dialog box I am using CComboBox with CBS_DROPDOWNLIST. It is an ownerdraw CComboBox.

I am listing Group name and items of group in the listbox. using the sourcecode given in the link https://www.codeproject.com/Articles/450/CComboBox-with-disabled-items

When I select or click group name, the edit control of CComboBox should not be updated group item text. In that link they are following things to get rid of selection group item.

  • Overriding the WM_LBUTTONUP handler of the enclosed list box, we can actually disable clicking on the group items.

  • Overriding CharToItem handler, we can disable picking the group items by keyboard.

  • Andfinally, by reacting to reflected CBN_SELENDOK, we can assure that a group item was not selected.

const UINT nMessage=::RegisterWindowMessage("ComboSelEndOK");


    BEGIN_MESSAGE_MAP(CODrawCombo, CComboBox)
    ON_CONTROL_REFLECT(CBN_SELENDOK, OnSelendok)
    ON_REGISTERED_MESSAGE(nMessage, OnRealSelEndOK)
    ON_CONTROL_REFLECT(CBN_EDITUPDATE, OnComboEdited)
    ON_MESSAGE(WM_CTLCOLORLISTBOX, OnCtlColor)
    END_MESSAGE_MAP()

    void CODrawCombo::OnSelendok() 
    {
        // TODO: Add your control notification handler code here
        GetWindowText(m_strSavedText);
        PostMessage(nMessage);  
    }

    LRESULT CODrawCombo::OnRealSelEndOK(WPARAM,LPARAM)
    {
        CString currentText;
        GetWindowText(currentText);

        int index=FindStringExact(-1,currentText);
        if (index>=0 && !IsItemEnabled)
        {
            SetWindowText(m_strSavedText);
            GetParent()->SendMessage(WM_COMMAND,MAKELONG(GetWindowLong(m_hWnd,GWL_ID),CBN_SELCHANGE),(LPARAM)m_hWnd);
        }
        return 0;
    }


        void CListBoxInsideComboBox::OnLButtonUp(UINT nFlags, CPoint point) 
        {
            // TODO: Add your message handler code here and/or call default
            CRect rect; GetClientRect(rect);

            if (rect.PtInRect(point))
            {
                BOOL outside=FALSE;
                int index=((CListBox *)this)->ItemFromPoint(point,outside);
                if (!outside && !m_Parent->IsItemEnabled(index))
                    return; // don't click there
            }

            CWnd::OnLButtonUp(nFlags, point);
        }

After clicking group item and if I click outside of CListBox, the edit control of CComboBox updated with group name only? how to resolve this?


migration from VS2010 to VS2017 - issue with wincodec.h

$
0
0

Hi,

I am migrating project which is in VS2010 to VS2017. While build the issue in VS2017 I am getting error related towincodec.h

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\winerror.h(56461): note: see previous definition of 'DWRITE_E_ALREADYREGISTERED'

1>Note: including file:    C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\wincodec.h

1>Note: including file:     C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\intsafe.h

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\wincodec.h(8160): error C2061: syntax error: identifier 'DXGI_JPEG_AC_HUFFMAN_TABLE'

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\wincodec.h(8165): error C2061: syntax error: identifier 'DXGI_JPEG_DC_HUFFMAN_TABLE'

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\wincodec.h(8170): error C2061: syntax error: identifier 'DXGI_JPEG_QUANTIZATION_TABLE'

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\wincodec.h(8349): error C2061: syntax error: identifier 'DXGI_JPEG_AC_HUFFMAN_TABLE'

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\wincodec.h(8354): error C2061: syntax error: identifier 'DXGI_JPEG_DC_HUFFMAN_TABLE'

1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\wincodec.h(8359): error C2061: syntax error: identifier 'DXGI_JPEG_QUANTIZATION_TABLE'

I tried to get solution to the problem on google but didn't get any solution for the same. Looking forward for help to resolve the issue.

Thanks in advance


HeapAlloc and HeapFree failing in release version

$
0
0
I am  executing some c++ applications(Dll's) which is getting called from a c++ DCOM application. In certain schenario's when it encounters HeapAlloc and HeapRelease it crashes...And most important this happens only in the release version. We can also execute these C++ applications individually by attaching the Dll's from any C++ MFC Calling process. In those cases it works fine in both release and debug.The issues happens when these C++ applications are called from DCOM application in release version.  Any update regarding this issue will be very helpfull.

Using UpdateResource() to change a string resource

$
0
0

I am trying to change the string associated to a resouce ID using UpdateResouce(), but the string doesn't change with the code below.

void CMainFrame::UpdateMacroFileName(UINT nID, LPCTSTR szNewName)
{
	TCHAR path[_MAX_PATH];
	GetModuleFileName(NULL, path, sizeof(path));

	HANDLE hRes = BeginUpdateResource(path, FALSE);

	CString sNewString = szNewName;
	int iCharCount = sNewString.GetLength() + 1;
	LPWSTR pUnicodeString = new WCHAR[iCharCount];

	wcscpy_s(pUnicodeString, wcslen(pUnicodeString), sNewString);

	UpdateResource(hRes, RT_STRING, MAKEINTRESOURCE(nID), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), (LPVOID*)pUnicodeString, (DWORD)wcslen(pUnicodeString) * sizeof(WCHAR));

	EndUpdateResource(hRes, FALSE);

	//delete[] pUnicodeString;

	// Check if string is updated
	LPCTSTR szUpdated = MAKEINTRESOURCE(nID);
	CString strUpdated = szUpdated;
}

Could you please let me know any mistake in the code above? By the way I don't know why it crashes at delete[] pUnicodeString.

Thanks in advance.

Issues Running Sample Code Stitcher.cpp from OpenCV in VS 2017

$
0
0

Hello,

I'm new to VS, and I'm trying to run the stitcher.cpp sample code from OpenCV's GitHub.

I want to take two pictures and make them into one picture panorama style.  When I copy the code from GitHub into VS, I get many errors like the two below:

Error LNK2019 unresolved external symbol "bool __cdecl cv::imwrite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::debug_build_guard::_InputArray const &,class std::vector<int,class std::allocator<int> > const &)" (?imwrite@cv@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@debug_build_guard@1@ABV?$vector@HV?$allocator@H@std@@@3@@Z) referenced in function _main hello-realsense C:\Program Files (x86)\Intel RealSense SDK 2.0\samples\hello-realsense\rs-hello-realsense.obj 1 

 

Error LNK2019 unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread@cv@@YA?AVMat@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function "int __cdecl parseCmdArgs(int,char * *)" (?parseCmdArgs@@YAHHPAPAD@Z) hello-realsense C:\Program Files (x86)\Intel RealSense SDK 2.0\samples\hello-realsense\rs-hello-realsense.obj 1 

Can anyone provide insight into how I can correct these errors? 

Thank you for your help.


OpenVirtualDisk fails to Open VHDSET files.

$
0
0

Hi,

I am trying to open VHDSET file using Virtual Disk management API OpenVirtualDisk API call. But it fails without any proper error. OpenVirtualDisk API returns 3227320074

Below is my code,

virtStorageType.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHDSET;
	virtStorageType.VendorId = VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;

	memset(&openParameters, 0, sizeof(openParameters));

		openParameters.Version = OPEN_VIRTUAL_DISK_VERSION_2;
		openParameters.Version2.GetInfoOnly = bForInfo;
		openParameters.Version2.ReadOnly = pbIsReadOnly;
	
	

	dwOpenStatus = OpenVirtualDisk(
		&virtStorageType,
		pwstrHDPath.c_str(),
		VIRTUAL_DISK_ACCESS_NONE,
		OPEN_VIRTUAL_DISK_FLAG_NONE,&openParameters,&m_VDiskHandle);
Thanks

Memory issues while compiling the C++ project on 2019 compiler

$
0
0

Hi,

We have moved our VC++ projects to VS2019 and when tried to build the project we got the following errors after compiling some files...

3>c1xx: error C3859: Failed to create virtual memory for PCH
3>c1xx: note: PCH: Unable to get the requested block of memory

I have gone through the forums as mentioned  by the ciompiler but still getting the same error

3>c1xx: note: please visit https://aka.ms/pch-help for more details

Can you please help in resolving these issues?

Thanks,

Mohan



Appcore.cpp 196 assertion in Dialog when moving from VC++ 6.0 to VS2017

$
0
0

Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\mfc140d.dll

File:

d:\agent\_work3\s\src\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp

Line: 196

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)  

I have an app developed in VC++ 6.0 , Windows XP x32 and I want to migrate to VS 2017, Windows 10 x64

I tried registering TBarCode6.ocx using  TBarCode6.exe and regsvr32 - registration successful, but program crashes same way.

'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\mfc140d.dll'
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\combase.dll'
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\msvcp60.dll'
Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\mfc140d.dll
File: d:\agent\_work\3\s\src\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp
Line: 196

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\WinTypes.dll'
'Ares2017.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\WinTypes.dll'

How to conditionally check whether a window's scroll bar is currently visible or not?

$
0
0

I am working on an mfc application that draws two buttons on the screen relative to the dimensions of the CListBox that sits directly to the left of it. Their positions are determined by coordinates retrieved from the GetClientRect() function. However, when the CListBox contains enough data, a scroll bar will become visible, and GetClientRect() will not take the scroll bar's size into account. Therefore, my buttons end up being shifted over to the wrong place. 

I am aware there is an rgstate in the SCROLLBARINFO that has information regarding the current state of the scrollbar. I haven't been successful thus far in checking this state to determine if the scroll bar is currently visible or not. My understanding of this is pretty shallow so it's likely an error on my part. 

My conditional part of my code looks something like:

bool visible = true;
int info = scrollbarinfo.rgstate[0];
if (info == ((STATE_SYSTEM_INVISIBLE || STATE_SYSTEM_UNAVAILABLE)) 
{
visible = false;
}
My understanding on how this works must be way off. Any guidance would be much appreciated!



Application randomly getting crashed

$
0
0

My application is getting crashed .The issue is random.I have checked for all possibilities like null pointer,threads etc.

I am getting event log as below..

Faulting application name: Demo.exe, version: 1.0.0.1, time stamp: 0x5cf618be
Faulting module name: Demo.exe, version: 1.0.0.1, time stamp: 0x5cf618be
Exception code: 0xc0000005
Fault offset: 0x00070a86
Faulting process id: 0x2768
Faulting application start time: 0x01d520111b724728
Faulting application path: D:\Demo.exe
Faulting module path: D:\Demo.exe
Report Id: a7f82aa3-5c8a-4e89-9249-abc198e32edd
Faulting package full name: 
Faulting package-relative application ID: 

Get resolution in multi monitor

$
0
0

Hi everyone,  I use EnumDisplayMonitors and GetMonitorInfo to enum monitor, get Monitor info. But on Windows 10 have a set scale.

In case 1: I set the same scale percent for example 150% for three monitors, GetMonitorInfo is correct. I can use resolution(always 1920X1080) in monitor info

In case 2: I setting different scale for each monitor 1 is 100%, monitor 2 is 125 %, monitor 3 is 150%. GetMonitorInfo incorrect. I got a different resolution for 3 monitors although I set the resolution for 3 monitors is 1920x1080

Why has different resolution got from GetMonitorInfo function which scale percent each monitor?

related between scale percent and resolution?



PRJ0019 error

$
0
0

The paths in the post build step are correct and the copy is happening correctly. What is the reason for this post build error?

md  "C:\Visual_2005_Projects\REPM_TEST_APP\REPM_TEST_APP\COMMONFILES\Devices - Release\BTDT\Binaries\iCore\Release"

copy /Y  "c:\Visual_2005_Projects\REPM_TEST_APP\REPM_TEST_APP\COMMONFILES\Devices - Release\BTDT\ConnectCore 9M Wi-9M 2443 (ARMV4I)\Release\BTDT.dll" "C:\Visual_2005_Projects\REPM_TEST_APP\REPM_TEST_APP\COMMONFILES\Devices - Release\BTDT\Binaries\iCore\Release"



if errorlevel 1 goto VCReportError

goto VCEnd

:VCReportError

echo Project : error PRJ0019: A tool returned an error code from "Performing Post-Build Event..."

exit 1

:VCEnd
]

Using .net toolstrip methods in (C++)winapi

$
0
0

Good day

I'm need to access .net object methods to access information in a WinForm app from WinAPI.

Example:
Getting a toolstrips HWND via EnumChildWindows():
       int toolstripItemCount = (toolStrip1)(HWND).Items.Count.ToString();

Is this possible?

InterlockedExchange question?

$
0
0

Hi Guys,

I have two questions, please help

1.If there is only one CPU, thread A and thread B are trying to run the InterlockedExchange.

If Thread A is in the middle of running the InterlockedExchange,  and Thread A already exhaust its quantum time, does it yields and allow thread B to run the InterlockedExchange?

2. If there are two CPUs. Thread A runs on CPU0 and Thread B runs on CPU1.

If Thread A is in the middle of InterlockedExchange, and Thread B starts to run InterlockedExchange.

What's the status of thread B, is it in wait state? or just fails?

Thanks for your help.

Viewing all 15302 articles
Browse latest View live


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