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

Exiting MFC program after destroying shared_ptr UI thread causes crash

$
0
0

Please reference this thread: 'Exiting MFC program after destroying UI thread causes crash'.

This establishes the proper way to create and destroy a MFC UI thread.

My program needs the UI thread to return as a std::shared_ptr< UIThread > uiThread;

This causes my test program to crash with the characteristics as described in the other posting. Apparently, going out of scope causes the smart pointer to my new UIThread to delete itself and somehow conflict with the normal MFC UI destruction.

I need shared ptrs in my app because I make extensive use of containers with weak ptrs.

If I can get them to work and destroy properly, it will ultimately make the code less complex. 


RT


_findnext API crashes for x64bit application in windows 8.1 and windows server 2012.

$
0
0

Hi,

I tried to debug the below simple code snippet in 64bit configuration in (VS 2013)windows 8.1 operating system(64 bit) and windows server 2012(64 bit). but in windows 7(64 bit) is working.

Code snippet:

#include<iostream>
#include<conio.h>
#include<io.h>

using namespace std;

void main()
{

struct _finddata_t dcm_file;
long hFile;


int id = 0;
std::string myfile = "c:\\temp\\ravi\\*.txt";
//std::string  dcm_file;
//double hFile;

if ((hFile = _findfirst(myfile.c_str(), &(dcm_file))) == -1)
{
cout << "txt files are Not present";
}
else
{
do
{
cout << id << " txt file : " << dcm_file.name<<endl;
id++;

} while ( _findnext(hFile, &dcm_file) == 0);
_findclose(hFile);
}
}

crashes with error message:

Unhandled exception at 0x00007FFA46097E69 (ntdll.dll) in fileNext.exe: 0xC0000005: Access violation writing location 0xFFFFFFFFF502AF40.

Could you please suggest me how to fix the problem?

I am waiting for your reply.

Thanks,

Ravi

Animation program in Visual C++ using Animated and Still Images

$
0
0

Hi,

I have got a project in Visual C++ which shows an animation of an animal. I checked the project directory & i found various files in addition to some HTML files containing animation of the animal & some still images. When i run the project, it shows the still images in the back ground & the animation of the animal in foreground.

The Readme of the project is given  below:

APPLICATION : data Project Overview
========================================================================

AppWizard has created this data Application for you.

This file contains a summary of what you will find in each of the files that
make up your data application.

data.vcproj
    This is the main project file for VC++ projects generated using an Application Wizard.
    It contains information about the version of Visual C++ that generated the file, and
    information about the platforms, configurations, and project features selected with the
    Application Wizard.

data.cpp
    This is the main application source file.
    Contains the code to display the form.

Form1.h
    Contains the implementation of your form class and InitializeComponent() function.

AssemblyInfo.cpp
    Contains custom attributes for modifying assembly metadata.

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
    These files are used to build a precompiled header (PCH) file
    named data.pch and a precompiled types file named StdAfx.obj.

/////////////////////////////////////////////////////////////////////////////

Can some body please guide me how to make this program from scratch?

Zulfi.

WebBrowser default path

$
0
0

 

 Is there a way to define a default path for the WebBrowser control in a windows form application?

 I’m writing a form application that reads data from the “Working Directory” and displays data in a WebBrowser control.

 

The application reads the data files from the defined Working Directory with no problem.

 

I have tried 3 methods for loading a CSS file to control the display:

 

<link media='screen' href='Styles.css' type='text/css' rel='stylesheet' /><link media='screen' href='Files/Styles.css' type='text/css' rel='stylesheet' /><link media='screen' href='C:/W7Share/aa Test/Files/Styles.css' type='text/css' rel='stylesheet' />

 

Placing the CSS file in the Working Directory and placing it in a subdirectory off the Working Directory both fail to assign the styles to the web page display.

 

The third line does work when I give the full path to the CSS file from the root.

 

My pages will contain a fair number of graphics and I don’t want to have to provide the full path for every one. Is there a way to define a default working directory for the WebBrowser control?

I hate my alternative of creating a short path for all files:  "C:/WP/"file.ext

Can I use the same socket in blocking mode and in overlapped mode?

$
0
0
I am using IOCP. I have a socket that is associated to a completion port, I want to call WSARecv() in overlapped mode, but I want to call WSASend() in blocking mode. Is there a problem in doing this?

[SOLVED] Issue with background image in borderless dialog

$
0
0

Hello!

I have little issue with background image in a dialog. When the dialog is build and updated 1st time everything is OK but the 2nd update deletes the image below meter area (meter is build from 3 rectangles). When the dialog is in its max size this issue does not happen (at some point it was OK even when 4 or 6 meter bars were active but I can't remember what changes I did before those started to be troublesome as well. I've tried by changing the dialog size through .rc and resizing routine ... there are some routines for to set the dialog stay on top and layered but not much more valls to routines related to meter rectangles or background image than what seen in coding below.

Debugging leads to system code (user32, etc) before issue happens so I quess there's some updates done for the dialog or rectangles (I don't have the .pdb files for those). I'm in learning process of C++ programming (outside Forms applications) so any help would be appreciated.

EDIT: I got this issue solved by preparing separate .rc files for each channel config.


Why using afxDump now in VS2013 generates extra TRACE output

$
0
0

Hi,

since using VS2013 instead of VS2010 old code using the afxDump object creates "extra" output.

Something like:

d:\...\bcgcbpro\bcgcbpro.cpp(39) : atlTraceGeneral - BCGCBPRO.DLL Initializing!

The reason for the TRACE related output is to be found in "dumpcont.cpp":

void CDumpContext::OutputString(LPCTSTR lpsz)
{
	// use C-runtime/OutputDebugString when m_pFile is NULL
	if (m_pFile == NULL)
	{
		TRACE(atlTraceGeneral, 0, _T("%s"), lpsz);
		return;
	}

	ASSERT( lpsz != NULL );
	if( lpsz == NULL )
		AfxThrowUserException();
	// otherwise, write the string to the file
	m_pFile->Write(lpsz, static_cast<UINT>(_tcslen(lpsz))*sizeof(TCHAR));
}

One of the most unreadable outputs via afxDump is:

f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -         f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - CRibbonButtonf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  @ f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - $0BB99940f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - disabledf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open Objectf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - " (description "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open the object referenced in the current cell.f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ", tooltip "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open Objectf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ", image sizef:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - s f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 16f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  x f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 16f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - )f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - /f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - (f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 32f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  x f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 32f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - )f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - , image indexes f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 27f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - /f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 27f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - , keys "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - OOf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ) -> f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 34329f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  / f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - CRibbonItemResources { ID f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - 34329f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - , resource "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open the object referenced in the current cell.\nOpen Object\nOpen Objectf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ", name "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open Objectf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ", tooltip "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open Objectf:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ", description "f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - Open the object referenced in the current cell.f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - ", from f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  module f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral - $43000000f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -  }f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dumpcont.cpp(23) : atlTraceGeneral -

Is there any chance to switch the TRACE output off?

Since the big changes in the ATL library and since the AtlTraceTool got unnecessary removed from the distribution ... how to configure TRACE output?

Best regards,

Martin


Martin Lemburg Berlin / Germany
Martin0815@twitter
martinlemburg@facebook
http://about.me/Martin0815


Problem with OpenProcess() and UAC (ERROR_ACCESS_DENIED )

$
0
0

Hello,

On Windows 7, Administrator User, when I call OpenProcess(), even with minimal parameters like PROCESS_QUERY_INFORMATION, I get ERROR_ACCESS_DENIED when the process has UAC Icon.

In the following sample, where I test 2 VS tools (Spy++ and ErrLook) : ErrLook works fine and I can use OpenProcess () (No UAC icon), but Spyxx doesn't work : ERROR_ACCESS_DENIED (UAC icon)

// Here useless code to enable SE_DEBUG_NAME : "WhoAmI /priv" in cmd.exe command doesn't list SeDebugPrivilege (is this normal ? (for Admin User))
// ...

DWORD dwProcessID;
WCHAR wsMessage[255] = L"";

SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.lpParameters = L"";
sei.nShow = SW_SHOWNORMAL;
//sei.lpFile = L"D:\\Programmes\\Microsoft Visual Studio 12.0\\Common7\\Tools\\spyxx.exe";
sei.lpFile = L"D:\\Programmes\\Microsoft Visual Studio 12.0\\Common7\\Tools\\errlook.exe";
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
ShellExecuteEx(&sei);
if (sei.hProcess)
{
	WaitForSingleObject(sei.hProcess, 2000);
	dwProcessID = GetProcessId(sei.hProcess);
	if (dwProcessID)
	{
		HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessID);
		if (!hProcess)
		{
			swprintf(wsMessage, L"Error OpenProcess = %d", GetLastError());
			MessageBox(NULL, wsMessage, L"Error", MB_OK | MB_ICONSTOP);
		}
		else
		{
			swprintf(wsMessage, L"PID = %d", dwProcessID);
			MessageBox(NULL, wsMessage, L"Info", MB_OK | MB_ICONINFORMATION);
			CloseHandle(hProcess);
		}
	}
}


Why does Spyxx have UAC icon ? ( I disabled UAC (slider moved down in UserAccountControlSettings.exe))

Why can't I use OpenProcess()  on these executables with UAC icons?

(I could set "requireAdministrator" in the Manifest, but it worked yesterday without doing that)

Additional question : why, in command prompt, "whoami /priv"  doesn't list SeDebugPrivilege ? (as Administrator User)

Thanks.











reduce exe size in visual studio

FrameRgn is not working for the dialog without Title and caption

$
0
0

Hi,

I created a dialog based applicationFrom dialog properties, i removed Title bar and Set border is none.Then ProgmaticallyI modified the dialog size using MOveWindow() and i change the dialog shape to a polygon region and applied frame region. its working fine.

But when I created a dialog based application Progmatically, i removed Title bar and Dialog frame as below:

ModifyStyle(WS_CAPTION,0);

ModifyStyle(WS_DLGFRAME,0)

Then ProgmaticallyI modified the dialog size using MOveWindow() and i change the dialog shape to apolygonregion and applied frame region. The frame is not appearing around the dialog. its there only in left and top.

Complete Code:

BOOL CDialogShapeDlg::OnInitDialog(){CDialogEx::OnInitDialog();ModifyStyle(WS_CAPTION,0);ModifyStyle(WS_DLGFRAME,0);CRect rect;GetClientRect(&rect); //Tried with GetWindowRect also but same issueMoveWindow(rect.left,rect.top,400,500);GetClientRect(&rect); //Tried with GetWindowRect also, but same issueCPoint vertex[4];
	vertex[0]=CPoint(rect.left,rect.top);
	vertex[1]=CPoint(rect.right,rect.top);
	vertex[2]=CPoint(rect.right,rect.bottom);
	vertex[3]=CPoint(rect.left,rect.bottom);


	rgn.CreatePolygonRgn(vertex,4,ALTERNATE);
	HGDIOBJ hRgn = rgn.Detach();::SetWindowRgn(GetSafeHwnd(),(HRGN)hRgn, TRUE);
	rgn.CreatePolygonRgn(vertex,4,ALTERNATE);return TRUE;}voidCDialogShapeDlg::OnPaint(){CPaintDC dc(this);CBrush*pBrush =newCBrush(RGB(255,0,0));
	dc.FrameRgn(&rgn,pBrush,1,1);}
Can anyone please help on this

Can QT and MFC coexist in a VC++ 2010 project?

$
0
0

         I need to use an opensource library (it compiles only with QT and not with VC++) in my VC++ project. I'm planning to use Visual Studio Add-ins for QT (like Qt 5.4.0 for Windows 32-bit) in VS IDE. Some of the codes need to be compiled by QT and the rest using VC++ compiler. Need advice if such arrangement will work . I want to use MFC for the GUI part.

        Alternatively could I use the lib/dll pre-compiled  and ported from QT for use inside VC++?





c++ delete undefined behavior

$
0
0

Hi

I'm getting a struct array from dll.

here is my code

dll code

struct Building  {

	bool is_empty;
	int size;

	char *id;
	char *name;

};

void getBuilding(Building *building)
{
	building[0].id = "1";
	building[0].name = "aaaaa";

	building[1].id = "2";
	building[1].name = "bbbb";

	building[2].id = "3";
	building[2].name = "ccccc";

}

the exe code

Building *building_data = new Building();
getBuilding(building_data);

std::cout << building_data[0].id << std::endl;
std::cout << building_data[1].id << std::endl;
std::cout << building_data[2].id << std::endl;

delete[] building_data;

In above code I can get information but delete operator doesn't work because of undefined behavior

If I change it to 

Building *building_data = new Building[3];

it will work and will delete the memory

But I don't the size of array. It must be a dynamic.

Now which is the best solution ?

Thanks in advance.

MFC: FrameRgn is not framing the entire region

$
0
0

Hi,

I want to draw a border for a dialog region. I created a rectangular region as below:

m_rgnShape.CreatePolygonRgn(vertex,4,ALTERNATE);

Then in Onpaint, i am drawing the border using FrameRgn. But the border appears only in twoside i.e. left and top.

Also i used m_rgnShape.OffsetRgn(10,10); still its in two side. 

Can anyone please help on this.

Thanks

Remote Detouring functions in a process

$
0
0

http://pastebin.com/j1Uq7gpS

would anyone happen to know why this would crash after the first WPM call, its not for malicous use but for learning other ways to detour other than using MS Detours with injected dll's

Thanks if you can help


Anddos

Connecting to 64 bit Access Database

$
0
0

32 bit DB seems to work well with SQLDriverConnect(...) and for

64 bit DB  SQLConnect(...) seems to work better to me. 

1) I can't connect a 64 bit DB using  SQLDriverConnect(...) command. Whats wrong?

2) I can't connect unless I change User DNS  settings under windows in both cases. Why? Can I also skip this step normally ?




Enabling 80-bit type long double?

$
0
0

Hello,

Is there any way to enable an 80-bit or greater long double in any version of Visual Studio for C and C++?

Thanks,
Ray

Incremental linking file (ILK) size limit

$
0
0

Hi,

Regarding link error.

 fatal error LNK1210: exceeded internal ILK size limit; link with /INCREMENTAL:NO

What is the actual limit of .ILK file size .. Using VS2013, Windows7, 4GB RAM. 

Also i cann't disable the Incremental linking. Is there any solution for this link error.

Accessing the system-wide clipboard in a C++ service

$
0
0

I have a service written in C++ that needs to access the clipboard for the following tasks:

  • Put data (CF_TEXT) on the clipboard, which should be visible to other applications so that it can be pasted there.

  • Access any CF_TEXT type data posted to the clipboard by another application

I tried doing the above operations using the standard clipboard functions in C++, but I'm able to view data that I posted on the clipboard only within my service and not in other applications. The same goes for accessing data put by other applications on the clipboard.

How can I achieve what I described above? Is there any "global" clipboard so that this can be done?

Note: My service is running as Local System


Draw scrollbar with theme

$
0
0

I saw here a guide of how to draw a button with theme ... but I tried to draw the scrollbar of an control (CListBox for instance), and I didn't succeded ... here is the trial:

void CMyListBox::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	// TODO: Add your message handler code here

	HTHEME hTheme = OpenThemeData(m_hWnd, L"LISTBOX");
	if(NULL != hTheme)
	{
		if(WS_VSCROLL & GetStyle())
		{
			CRect rect;
			GetClientRect(&rect);
			dc.FillSolidRect(&rect, RGB(255, 255, 0));
//			GetThemeBackgroundContentRect(hTheme, dc.GetSafeHdc(), LBCP_BORDER_HVSCROLL, LBPSHV_NORMAL, &rect, NULL);
			DrawThemeBackground(hTheme, dc.GetSafeHdc(), LBCP_BORDER_HVSCROLL, LBPSHV_NORMAL, &rect, NULL);
		}
		CloseThemeData(hTheme);
	}
	// Do not call CListBox::OnPaint() for painting messages
}

Can you

give me a little hint of what I should do to color the scrollbar of an control ? I dig for this for weeks, with no results ... :(

Can CDHtmlDialog play swf file with audio component?

$
0
0

Hello, I'm using CDHtmlDialog in our application to play swf that shows user how to do a workflow. It works fine if swf does NOT have audio; if the swf has audio component, then it does not play.

Can CDHtmlDialog play swf with audio?

If not, any suggestion on how to implement playing swf file with audio?

Many thanks in davance.

Viewing all 15302 articles
Browse latest View live


Latest Images

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