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

ReportEvent: Problem with Insertion Strings

$
0
0

//SNIPPET FROM "Messages.mc"
; // The following are message definitions.
MessageIdTypedef=DWORD

MessageId=0x03
Severity=Success
Facility=Runtime
SymbolicName=EVENT_START
Language=English
Document extraction Document ID

When I call ReportEvent without any parameters, "Document extraction Document ID" shows up without error in the Application Log.

-------------------------------------------------------------------
; // The following are message definitions.
MessageIdTypedef=DWORD

MessageId=0x03
Severity=Success
Facility=Runtime
SymbolicName=EVENT_START
Language=English
Document extraction Document ID %1

When I use a Parameter I have problems.

	PCTSTR strings[] = { _T("a parameter") };

	if (ReportEvent(_hEventLog,
		0,
		0, //wCategory
		3, //dwEventID
		NULL, //lpUserID
		1,
		0,
		strings,
		NULL)

This is what shows up in the Application Log:

"The description for Event ID 3 from source EventLogger cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

a parameter"


I don't think I'm using the parameter in the mc correctly, or maybe it's the way I'm compiling things.  I'm not sure.


Here's my command line:
mc -U -z "EventLogger" -r .\res Messages.mc


MFC custom ontrol on CFrameWnd don't appear until the mouse move over it

$
0
0

I have a simple custom tab control:

#include "stdafx.h"
#include "MyCustomTabCtrl.h"
IMPLEMENT_DYNAMIC(CMyCustomTabCtrl, CTabCtrl)
CMyCustomTabCtrl::CMyCustomTabCtrl()
{
}
CMyCustomTabCtrl::~CMyCustomTabCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyCustomTabCtrl, CTabCtrl)
END_MESSAGE_MAP()

My main application is a CFrameWnd:  

From MyFrameWnd.h:

CMyCustomTabCtrl m_myTabCtrl;

From MyFrameWnd.cpp:

int CMyFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

    //[...]

    m_myTabCtrl.Create(TCS_TABS | WS_CHILD | WS_VISIBLE, CRect(0, 0, 100,20), this, IDC_MY_CUSTOM_ID);

    m_myTabCtrl.SetParent(this);

    //[...]

    m_myTabCtrl.InsertItem( 0, &item );

}

void CMyFrameWnd::OnSize(UINT nType, int cx, int cy)
{

    //[...]

    m_myTabCtrl.MoveWindow(2, y, w, h, TRUE);

}


My Problem:  when the tool is first brought up, my custom tab control is NOT visible at all.  When I move the mouse over the custom tab control, the tabs start to show up one by one.  When I resize the window, the tab control disappears again. The only way to see the tab control and its tabs is to move the mouse pointer over the area where the tab control is added.   Could you please let me know what I did wrong here?  

Thank you so much in advance for your help.  I greatly appreciate it.

Best regards,

Michelle 


How to stop Communication of Serial ComPort while receiving data continously

$
0
0

While receiving data continuously from serial COM Port, if stopped receive thread.

Then tried to close the port file handle to stop communication but code get stuck at closeHandle(fileHandle) method.

Method does not terminated by returning any value. due to this application is not getting close completely it is not responding.

please help me to solve this error. please any one tell me how to close all ComPort Connection safely and close handle of  read file.

How to implement voice activity detection library in C++ Visual Studio (Digital Sound Processing)

$
0
0

May I know how to implement VAD in Visual Studio? The outcome would be like this: The user press the button on mainwindow.ui and the recorder will be turned on, receiving audio from the user. When the user stops talking (when it detects silence), it will automatically stop the whole thing.


Sharing data with a DLL

$
0
0

My C++ program loads a dll.  The client has some data structures such as

    extern "C" struct lens1s {
        double CVD[JC][NS+1];
        double CCD[JC][NS+1];
        double THD[JC][NS+1];
        double RINDEX[JC][NS+1][NBCOL];
        double ANUM[JC][NS+1][30];
        double WAVL[JC][NBCOL];
        double WGTD[JC][NBCOL];
        double CATND[JC][NS+1];
        double CATVD[JC][NS+1];
        int ICORD[JC][NBCOL];
        int JUCODE[JC];
        int NSPACE[JC][NS+1];
    } LENS1;

I want the dll program to be able to use these data when it runs.  How do I get the data across?

CControlBar - derived Control not shown after - Migration from VS2008 to VS2010

$
0
0

Hello everybody,

I have detected a breaking change in a running C++ MFC program (compiled by VS2008)after migration to VS2010 (SP1).

I use some CControlBar-derived "floatable ToolWindow" to fill it with our own controls.
In an version, compiled by Visual Studio 2008 all runs fine. The floatable CControlBar will be shown.
After compiling the same source with current Visual C++ 2010, the floatable CControlBar is not shown.

I have searched in the net for some solutions or workarounds and found a similar sample on Codeguru.

http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451
SourceCode:  Download demo project - 25KB

 

And on StackOverflow, there was an unanswered article, that describes, that this error occurs only by compiling against VS2010:

http://stackoverflow.com/questions/4149748/dockable-dialog-bar-derived-from-ccontrolbar-not-working-in-visual-studio-2010 

I'm using a CControlBar derived class to implement dockable windows. The code is derived from an old codeguru example which can be found here:http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451 This code worked fine but since switching from VS2008 to VS2010 the dockable window does not show up anymore. The standalone example that comes with the article mentioned above also does not work in VS2010 but behaves correctly in earlier versions of Visual Studio.

Does anybody know of any changes in MFC which could break existing code derived from CControlBar? Anyone else who used the codeguru example above as a basis for their own dockable windows.


Base Code will be ...

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 ...

 CString title("CoolBar Demo");if (!m_wndDialogBar.Create(this, &m_cDialog,title, IDD_DIALOG1))
 {
 TRACE0("Failed to create dialogbar\n");return -1; // fail to create
 }> m_wndDialogBar.SetBarStyle(m_wndDialogBar.GetBarStyle() |> CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
 ...
}


ControlCreation is done in this sample by code:

BOOL CCoolDialogBar::Create(CWnd* pParentWnd, CDialog *pDialog, CString &pTitle, UINT nID, DWORD dwStyle)
{
 ASSERT_VALID(pParentWnd); // must have a parent
 ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));// save the style -- AMENDED by Holger Thiele - Thankyou
 m_dwStyle = dwStyle & CBRS_ALL;// create the base window
 CString wndclass = AfxRegisterWndClass(CS_DBLCLKS, LoadCursor(NULL, IDC_ARROW),
 m_brushBkgd, 0);if (!CWnd::Create(wndclass, pTitle, dwStyle, CRect(0,0,0,0),
 pParentWnd, 0))return FALSE;// create the child dialog
	m_cDialog = pDialog;
	m_cDialog->Create(nID, this);// use the dialog dimensions as default base dimensions
	CRect rc;
 m_cDialog->GetWindowRect(rc);
 m_sizeHorz = m_sizeVert = m_sizeFloat = rc.Size();
	m_sizeHorz.cy += m_cxEdge + m_cxBorder;
	m_sizeVert.cx += m_cxEdge + m_cxBorder;return TRUE;
}

The following code is the original code from my own large project:
(both code works well with VS2008 and earlier, but will not work after compiling with Visual Studio C++ 2010 SP1)

BOOL mfc_grafik_menu::Create( CMainFrame *pParent, const CRect &window_rect, BOOL dock_it )
{
UINT dockbar_id;
UINT floating_style;

ASSERT( pParent != NULL );

if( !CControlBar::Create( NULL, "",
 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CBRS_SIZE_DYNAMIC, window_rect, pParent, 0/*nID*/) )return FALSE;

SetBarStyle( CBRS_ALIGN_TOP | CBRS_BORDER_3D | CBRS_SIZE_DYNAMIC );

WndOrgRect = window_rect;
pParent->ClientToScreen( WndOrgRect );if( window_rect.Width() > window_rect.Height())
 {
 EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
 dockbar_id = AFX_IDW_DOCKBAR_TOP;
 floating_style = CBRS_ALIGN_TOP;
 }else
 {
 EnableDocking( CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT );
 dockbar_id = AFX_IDW_DOCKBAR_LEFT;
 floating_style = CBRS_ALIGN_LEFT;
 }if( dock_it )
 pParent->DockControlBar( this, dockbar_id, &WndOrgRect );else
 {
 EnableDocking( 0 ); // disable docking for grafik menus if they are not created docked
 pParent->FloatControlBar( this, WndOrgRect.TopLeft(), floating_style );
 }return TRUE;
}

 


Just take the sample from Codeguru (SourceCode: Download demo project - 25KB), load this old project from .dsw to  VS2008  or VS2010 and compare the results.
Attn:  In these old codeguru sample sources the only change, that is needed, is to change the signature of OnNcHitTest fromUINT to LRESULT

  change:
  UINT CCoolDialogBar::OnNcHitTest(CPoint point)
  to:
  LRESULT CCoolDialogBar::OnNcHitTest(CPoint point)
After click on right most toolbar button, in the VS2008-Version you will see the floatable Toolwindow, in VS2010-Error you see nothing.

In Spy++ (by looking for all controls that match the process) you can see, that the Controls were created, but they are not shown on the sceen.
I have tried to compare the MFC-Sources from C++2008 to C++2010-Versions, but I found no point, that could have an impact on this issue.

Which CBRS_*-Flags or other Flags or Overloads  or other workarounds should I use to solve this issue.

Thanks in advance.

Dietmar Mayer  - dm01

 




warning C6386: Buffer overrun while writing to 'this->m_csSounds[byIndex].szSound':  the writable size is '520' bytes, but '1040' bytes might be written

$
0
0

I have this code:

DWORD CButtonST::SetSound(LPCTSTR lpszSound, HMODULE hMod, BOOL bPlayOnClick, BOOL bPlayAsync)
{
	BYTE	byIndex = bPlayOnClick ? 1 : 0;

	// Store new sound
	if (lpszSound)
	{
		if (hMod)	// From resource identifier ?
		{
			m_csSounds[byIndex].lpszSound = lpszSound;
		} // if
		else
		{
			_tcscpy_s(m_csSounds[byIndex].szSound,
				sizeof(m_csSounds[byIndex].szSound), lpszSound);
			m_csSounds[byIndex].lpszSound = m_csSounds[byIndex].szSound;
		} // else

		m_csSounds[byIndex].hMod = hMod;
		m_csSounds[byIndex].dwFlags = SND_NODEFAULT | SND_NOWAIT;
		m_csSounds[byIndex].dwFlags |= hMod ? SND_RESOURCE : SND_FILENAME;
		m_csSounds[byIndex].dwFlags |= bPlayAsync ? SND_ASYNC : SND_SYNC;
	} // if
	else
	{
		// Or remove any existing
		::ZeroMemory(&m_csSounds[byIndex], sizeof(STRUCT_SOUND));
	} // else

	return BTNST_OK;
} // End of SetSound

When I run the code analysis I get this warning:

warning C6386: Buffer overrun while writing to 'this->m_csSounds[byIndex].szSound':  the writable size is '520' bytes, but '1040' bytes might be written.

So it is complaining about this bit:

_tcscpy_s(m_csSounds[byIndex].szSound,
	sizeof(m_csSounds[byIndex].szSound), lpszSound);

m_csSounds is a structure:

	typedef struct _STRUCT_SOUND
	{
		TCHAR		szSound[_MAX_PATH];
		LPCTSTR		lpszSound;
		HMODULE		hMod;
		DWORD		dwFlags;
	} STRUCT_SOUND;

How can I resolve this warning, or is it a false positive?

The default MFC app calls OnFileNew as the first action - how can I change that?

$
0
0

Hi,

The default MFC app calls OnFileNew as the first action - how can I change that?

Regards,

Juan


Juan Dent


create 3 tabbed group document of equal size

$
0
0

Hi,

I would like to create some MDI tabbed group documents and I would like equal size for each one.

unfortunately creating a tabbed group divide actve gorup in 2 equal gorups, so if I create 3 groups by code I've got one of them occupying 50% of size and 2 others ones 25% each

is there a solution to equilibrate size for all groups.

thanks

Yan

reboot pc, miss dll

$
0
0
Recently, I have encountered the following problem:
Some program files lost after rebooting my PC. I had lost the libintl-8.dll of postgresql, and also some of my own application programs' DLL file.
This problems happened in many OSs, such as Windows 2008, Windows 2012, Windows 10.
I wonder if someone has also encountered this problem and can give me some advice to solve it. Thanks a lot.

UpdateData in VC++ Visual Studio 2015 community

$
0
0

I am learning the Visual Studio 2015 VC++ using the book ( "Sam's Teach Yourself Visual C++ 6 In 21 Days (e-Book)"

There are minor differences I have been able to work around.

However, UpdateData does not seem to work to set the data to the control.

If I type in the control for example "Display this message", then click the button that calls the function below. A pop up displaying "Display this message" is displayed. After clicking OK, I would expect the control on the display to be updated with the message "After Show". However, nothing happens. Seems this should be simple enough... I can get data out using UpdateData(TRUE), but I can't set the data using UpdateData(FALSE).

void CDay2Dlg::OnBnClickedShwmsg()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
MessageBox(m_strMessage);
m_strMessage = "After Show";
UpdateData(FALSE);
}

Hook user open file

$
0
0

Hi,

I have a project at college where I need to let or deny access to user when he opens a file by hex signature.

I read about hooking and detours but I couldn't find how to perform the Hook and to which function.

My main concern is, How to hook when user open file with double click or enter?

What do I hook?

Can this be done with File System Filter Drivers? There is no much code examples of it.

This needs to be done on Windows 10.

I would ready appreciate any kind of help.

Thanks,

Jonathan

Getting a lot of hangs in VS2015 debugger

$
0
0

Getting regular Visual Studio is busy messages which take ~ 5 minutes to complete in VS2015. Specifically, debugging a 64 bit version of my app with Edit and Continue enable after choosing to ignore an exception, it stalls, arrives at the point in the code the exception took place, and then stalls again and continues to do so until I terminate the debugging session.  If I delete everything out of my project folder other than source, project and solution file, the problem is corrected but tends to reappear a few weeks later.

Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Professional

LightSwitch for Visual Studio 2015   00325-60000-80195-AA437
Microsoft LightSwitch for Visual Studio 2015

Visual Basic 2015   00325-60000-80195-AA437
Microsoft Visual Basic 2015

Visual C# 2015   00325-60000-80195-AA437
Microsoft Visual C# 2015

Visual C++ 2015   00325-60000-80195-AA437
Microsoft Visual C++ 2015

Application Insights Tools for Visual Studio Package   7.15.01215.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8)   14.1.11106.0
ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.8
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

InstallShield Limited Edition   
InstallShield. For more information visit the Flexera Software website at <http://www.FlexeraSoftware.com>. Copyright © 2015 Flexera Software LLC. All Rights Reserved.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.60519.0
Microsoft SQL Server Data Tools

TypeScript   1.8.36.0
TypeScript tools for Visual Studio

Visual Assist   
For more information about Visual Assist, see the Whole Tomato Software website at http://www.WholeTomato.com. Copyright (c) 1997-2016 Whole Tomato Software, Inc.

Visual Commander   2.6.1
For more information about Visual Commander, see the website at https://vlasovstudio.com/visual-commander/.
Copyright (c) 2013-2016 Vlasov Studio.

Visual Studio Tools for Universal Windows Apps   14.0.25420.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Why Can't My App Find Its Include Files?

$
0
0

Hello Again Folks:

   Developing on Windows 10 Pro, Visual Studio 2015 Community. 

   Visual Studio learned a new trick today.  A project I've been working on can no longer find its header files. 

   This screen shot shows VS main page, the first header statement that fails, and the list of additional directories where header files can be found:

   It seems unable to find many header files. 

   Is that particular header file in that directory?

   There is the header file Visual Studio can't find, in the third of the additional include directories. 

   What happens if we try to look at that first header file?

   That seems odd.  It isn't looking in any of the directories specified in the properties additional include directories.

   In case you're wondering, here is the properties page for the debug_nr_from_program_files configuration, which, as you can see, matches the All Configuration properties:

   Another task that should take a couple of minutes will turn out to take, I don't know how long. 

   What am I doing wrong?

      Thanks
      Larry






WRITE A TEXT FILE IN A SFECIFIC FOLDER UWP C++

$
0
0

Hi, can you modify or add to this code to write in a specific folder ? thank you for your help 

StorageFile^ file = "C:\\file.txt";
if (file != nullptr)
{
String^ userContent = "hello";
if (userContent != nullptr&& !userContent->IsEmpty())
{
create_task(FileIO::WriteTextAsync(file, userContent));
task.get();

}


Calling a win32 API at runtime

$
0
0

The requirement of my application is such that I need to call the win32 API which is mentioned in the xml file.

The XMl file contains the name of the Win32 API, the input parameters values. And parameters in XML are in sequence as per MSDN.

like for example CreateFile APII have the API name = CreateFile, Filename = C:\sample\notepad.txt, etc.

Now I need to call this CreateFile API with the argument values present in the XML file.

I need to write the generic code such that the application should be able to execute any Win32 API present in the XML file.

Please suggest any tutorial or guide me.

i refered http://stackoverflow.com/questions/8696653/dynamically-load-a-function-from-a-dll

but there also you need to declare the function pointer as per the perameters, but then this approach wont be generic, and also I cannot add the details for all the Win32 APIs.

Please help.

Thanks in Advance.


Thanks & Regards, Mayank Agarwal

warning C28183: 'pszBuf' could be '0', and is a copy of the value found in 'wcschr()`327':  this does not adhere to the specification for the function 'wcschr'.

$
0
0

Here is another buffer overrun analysis error.

My method:

CString CPTSDatabase::GetJETDriver(bool bAccDbMode)
{
	CString			strDriver;
	CString			strName, strNameLower, strValue;
	CString			strDefaultDriver = _T("Microsoft Access Driver (*.mdb)");
	CString			strDBType = _T("(*.mdb)");
	CStringArray	aryStrDrivers;
	TCHAR			szBuf[2001];
	WORD			cbBufMax = 2000;
	WORD			cbBufOut;
	TCHAR			*pszBuf = szBuf;

	if (SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
	{
#ifdef _WIN64
		strDefaultDriver = _T("Microsoft Access Driver (*.mdb, *.accdb)");
		strDBType = _T("(*.mdb, *.accdb)");
#else
		if (bAccDbMode)
		{
			strDefaultDriver = _T("Microsoft Access Driver (*.mdb, *.accdb)");
			strDBType = _T("(*.mdb, *.accdb)");
		}
#endif
		do
		{
			strName = CString(pszBuf);
			strNameLower = strName;
			strNameLower.MakeLower();

			if (strNameLower.Find(strDBType) != -1)
			{
				aryStrDrivers.Add(strName);
				if (strName.CollateNoCase(strDefaultDriver) == 0)
				{
					strDriver = strName;
					break;
				}
			}

			pszBuf = _tcschr(pszBuf, _T('\0')) + 1;
		} while (pszBuf[1] != _T('\0'));

		if (strDriver.IsEmpty() && aryStrDrivers.GetSize() > 0)
		{
			// Try and use the first MDB driver we found
			strDriver = aryStrDrivers.GetAt(0);
		}
	}
	// Make a note of the driver
	AfxGetApp()->WriteProfileString(_T("Options"), _T("JET Connection Driver"), strDriver);

	return strDriver;
}

The offending lines:

	pszBuf = _tcschr(pszBuf, _T('\0')) + 1;
} while (pszBuf[1] != _T('\0'));

The warning from code analysis:

warning C28183: 'pszBuf' could be '0', and is a copy of the value found in 'wcschr()`327':  this does not adhere to the specification for the function 'wcschr'. See line 328 for an earlier location where this can occur

Is this another false positive or can I supress it with improved code?

Thanks!

How to run a function in C++ from a DLL

$
0
0

I see lots of pages explaining how to run a function in a DLL from a client program -- but I want to do the opposite.  My client program has the function

extern "C" __declspec( dllexport ) void wndout( char* textstring );
...

extern "C" __declspec( dllexport ) void wndout( char *textline )    // write string to current text window
{
    writeTo->AddTextString( (LPCTSTR) textline );
}

and the DLL has the line

extern "C" __declspec( dllimport ) void wndout( char *textline );    // write string to current text window

...

    wndout("textline");

But the DLL won't compile, saying wndout is unresolved external symbol __imp__wndout.  How can I make the DLL run the function in the main program?

Question on size of data types ?

$
0
0

So, a byte is 8 bits which is '0000 0000' How it represent an Char which is 1 byte long ? lets say A is number from Hex. 

And int is 4 byte which means it's storage is 32 bits or how does it works ? 

How to compare ? 

Debug Assertion failed - Data out of range (UpdateData)

$
0
0

I have a control with variable int attached to it.

int, m_iInterval, public

I set the min value to 1, and the max value to 100000

In the control, if I set the value outside of the min - max, UpdateData() should prompt the user that the data is out of range... Which it does... But quickly is followed up with another fatal error. It seems the user should be allowed to correct the data in the control after being prompted the data is out of range. Incidentally, the initial value is 0, which does not trigger the out of range pop  up, but if 1 is entered, then set back to 0, a pop up is display that the data is out of range, followed quickly with the Debug Assertion Failed message below...

Debug Assertion Failed!

Program: C:\Windows\system32\mfc140ud.dll

File f:\dd\vctools\vc7libs\ship\atlmfc\src\wincore.cpp

Line 4362

For information on how your program can cause an assertion

failiure, see the Visual C++ documentation on assserts.

(Press Retry to debug the application)


Viewing all 15302 articles
Browse latest View live


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