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

Memory allocation and virtual memory in Win 7

$
0
0

Hi, 
I have a question about memory reservation. If I run my test application main.cpp (attached) in 32 bits (Intel Compiler and Visual c++), the output its an out of memory in the moment that I ask for more memory than 2gb.
In 64 bits (same compiler version), the SO starts to allocate memory and when it reaches the maximum of my computer (8gb), it gets hanged competely when paging (I suppose). 
How can I achieve to return an "out of memory" error instead of using unlimited virtual memory and hang my computer?
Thanks in advance!

 

(The code is well formated in http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/1db497de-e2c7-4f8e-a324-bf9598a9a390 )


Same derived names in separate CPP files of CADORecordBinding causes conflict

$
0
0

Hi

I am using VS2008 Professional C++, creating bog-standard Win32 DLLs and am using ADO RecordBinding
Running Windows 7, 32-bit.

I have 3 separate CPP files each of which does

class CSponsor2010Bind : public CADORecordBinding
{

};

and the fields read vary. Each CPP file defines a local variable of CSponsor2010Bind and reads from a recordset.
But what I am experiencing is Recordset fields with the wrong content.
This problem goes away if I name the Bind record classes differently.

But seeing the classes are local to each CPP module, and instances are local, I dont understand why the wrong content.

Anybody shed light on why this occurs?

Thanks

IdentityWrapper


IdentityWrapper

How to display tooltips for each items in CTreeCtrl?

$
0
0
Hi,

How can i display tooltips for each items (nodes) in CTreeCtrl?

I could implement this using CToolTipCtrl class.

But i am searching for other ways using CTreeCtrl only. Anybody can help me.

Thanks in advance

R6016 - Not enough space for thread data

$
0
0

My statically-linked Visual C++ 2012 program sporadically generates a CRTL error: "R6016 - Not enough space for thread data".

Microsoft documentation says this error message is generated when a new thread is spawned, but not enough memory can be allocated for it.

However, my code only explicitly spawns a new thread in a couple of well-defined cases, neither of which are occurring here (although certainly the Microsoft libraries internally spawn threads at will). One user reported this problem when the program was just existing in the background.

Not sure if it's relevant, but I haven't overridden the default 1MB reserved stack size or heap size, and the total memory in use by my program is usually quite small (3MB-10MB on a system with 12GB actual RAM, over half of which is unallocated).

This happens very rarely (so I can't track it down), and it's been reported on more than one machine. I've only heard about this on Windows 8.1, but I wouldn't read too much into that.

Is there some compiler setting somewhere that might influence this error? Or programming mistake?

[MSVC2013] Template + remove include headers from global namespace

$
0
0
Hello forum!
So as we know VS not supported export templates and extern templates can only assign to explicit decalarations!

So, we have:
//B.h

#pragma once

namespace C
{
    template <typename T>
    class B
    {
        public:
            B()
            {
            }

            ~B()
            {
            }
    };
}
//A.h

#pragma once

#include "B.h"

namespace C
{
    template <typename T>
    class A
    {
        public:
            A()
            {
                //something doing with B
            }

            ~A()
            {
            }
    };
}
//main.h

#include "A.h"

int main()
{
    C:://this place cursor for check

    return 0;
}
As we see - class A using class B only for implementation and if we check namespace C at main? we can see:

How to hide include classes for template implementation from global space (expecting: visible only class A - if include A, but visible both - if include A and B)?



Call powershell command from C++

$
0
0

Dear all,

I'm writing a demo about call powershell command and save result to .txt file.

I run it on windows server 2012 64bit.

But it ok when I run normal command like "get-date", "get-process"

But when I run "get-windowsfeature" nothing happen.

On window powershell, command "get-windowsfeature" run normally and return good result.

I don't understand why.

Below there is my code.

PowerShell^ _ps = PowerShell::Create();
   _ps->AddScript("Get-date");
    auto results = _ps->Invoke();
  ofstream myfile;
  myfile.open ("example.txt");

    for (int i = 0; i < results->Count; i++)
    {
        String^ objectStr = results[i]->ToString();
        Console::WriteLine(objectStr); 
        std::string stdString=msclr::interop::marshal_as< std::string >( objectStr);
        myfile << stdString << "\n";
    }

  myfile.close();

Exclude certain file types in CFileDialog

$
0
0

Hi,

We Can set certain types of files to be shown in the File-Open window ( CFileDialog ) using the "lpszFilter" parameter, But can we set this filter toNOT show certain types of files. E.g. Say, All file extensions except "*.exe" should be shown in the file dialog.

How can this be achieved?

Problem with Shortcut selection in CFileDialog with multiselect on!

$
0
0

Hi,

I am using the CFileDialog to select multiple files but when the shortcut is selected, the file paths that I get for the other files are wrong. e.g. say In a directory C:/Desktop I selected two files - abc.txt and a shortcut my.lnk pointing to C:/Programs/my.exe. The paths that I get are C:/Programs/my.exe and C:/Programs/abc.txt. That is, I get a wrong path for the  abc.txt also, which is wrong. Is there any way to get around this?

I am using GetStartPosition() and GetNextPathName() to get the file names.


Recommendations on converting MFC App with Ribbon to touch screens

$
0
0

For a CAD/OpenGL type of MFC application with a ribbon is it practical to move to a touch screen?

If so, is it worth the effort?

Should I buy a touch monitor so I can write and debug on my desktop machine with a touch screen?

I presume there's no issues using a mouse with a touch screen?

Or should I buy a tablet, do my development on my current system, and simply try it out on the tablet, (sounds very slow).

If so, which tablet or tablet like hardware do you recommend.

Inquiring minds want to know.


I can't find Visual C++ as language in Visual Studio 2012

$
0
0

Hi!

I instaled Visual Studio 2012 and I want to create a new project with  Visual C++ but I can't find Visual C++ in templates. I have an restrictec version of Visual Studio 2012? Thank you in advance.

error C1083: Cannot open type library file: '..\..\system32\msxml.dll': No such file or directory

$
0
0

Hii

Iam migrating my application from vc++0.6 to vc++2013, this is one of the error iam facing..

I am sending part of my code and is highlighting the error line

==================CODE=========================


#if !defined(AFX_STDAFX_H__C3E25FA3_5C78_11D3_9C0D_40003100130A__INCLUDED_)
#define AFX_STDAFX_H__C3E25FA3_5C78_11D3_9C0D_40003100130A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _ATL_APARTMENT_THREADED

#include <objsafe.h>
#include <atlbase.h>

extern CComModule _Module;
#include <atlcom.h>
#include <atldbcli.h>
#include <math.h>

#import "c:\program files\common files\system\ado\msado15.dll" rename_namespace("ADO"), rename("EOF", "adoEOF")
using ADO::_Recordset;

#import "..\..\system32\msxml.dll" rename_namespace("XML")

#include "../../COMUtils/include/tstring.h"
#include "../../COMUtils/include/enum_iterator.h"
#include "../../COMUtils/include/object_iterator.h"
#include <map>

// Get cola and job tools and make used interfaces global
#import "../COLATools/COLATools.tlb" rename_namespace("COLATools")
using COLATools::IColaMsg;
#import "../JOBTools/JOBTools.tlb" rename_namespace("JOBTools")
using JOBTools::IAudiJobExecution;
using JOBTools::IAudiDataLayoutItem;

// Get text parser
#import "../TextParser/TextParser.tlb" rename_namespace("TextParser")
using TextParser::ITextFileParser;

// Get parsed store
#import "../Parsed/Parsed.tlb" rename_namespace("Parsed")
using Parsed::IParsedRecord;
using Parsed::IParsedField;

#endif

==========================CODE====================================

This msxml.dll file is not available , so what should i do

Any suggestions

Thanks Ankush

tips from vivion

$
0
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Expenses
{
    class Expense
    {


        private string[] categories = { "Travel", "Entertainment", "Office" };
        private static Random rand1 = new Random();
        public string Category { get; set; }
        public decimal Cost { get; set; }
        public DateTime Date { get; set; }

        public Expense()
        {
            
            Category = categories[rand1.Next(0, 3)];
            decimal i = (decimal)rand1.Next(1, 10001)/100;
            Cost = i;
            Date = DateTime.Today.AddDays(-rand1.Next(0, 32));
        }

        public Expense(string category, decimal cost, DateTime date)
        {
            this.Category = category;
            this.Cost = cost;
            this.Date = date;
        }

        public override string ToString()
        {
            return Category + " " + String.Format("{0:C}", Cost) + " on " + Date.ToShortDateString(); 
        }


    }
}

Restricting the Typeface names listed in CFontDialog to a specific *_CHARSET

$
0
0

I need to be able to restrict the listed TypeFace names in a CFontDialog to only those names supported by specific Unicode Ranges. The lfCharSet attribute of the LOGFONT structure does not seem to do this. 

This application is intended to simultaneously support multiple languages, by selecting one language at a time from another menu.  Does anyone know how to do this?



100% Accurate Display Screen OCR http://www.OCR4Screen.com

certificate

$
0
0

I've created an app, got it done and got the qr code where to download and install the certificate.

The phone is now asking for the company registration... and cannot complete the installation without. I have no company, what shall I do?

error MSB6006: "CL.exe" exited with code -1073741515 with VC++ 2013 ultimate , 2010 installed and all required SDKS installed

$
0
0
I have reinstalled the whole setup the VC++ but still the same error.Anyone please help.

Beginner

$
0
0
Hello. i would like to learn C++ programming. In future i plan to learn PIC (microchips etc.) programming and computer COM USB ports controls with C++. Please need your help. Give me ur advices and from which books should i begin. thanks for ur attention

Replace xiosbase to port MS C++

$
0
0

I need to port C++ code that was originally developed by another organization using MS tools.  The new platform's compiler (gnu - no pun intended) does not find <xiosbase> and the compile fails on an attempt to #include it.  Googling suggests that this header is non-standard, MS-only (despite one MS url referring to it as a "Standard C++ Header"). 

With what do I replace this header to compile the software on non-Microsoft environments?  Is it a clean replacement, or must I implement or stub out MS extensions to the ANSI standard?  Any help would be appreciated.

Thanks

Is C++ XAML Win8 only?

$
0
0

Hi all, wanted to know if you can only use C++ / XAML together to create Windows 8 Metro style apps?  Also can you use the two together to create Windows7 apps?

I'm just getting back into C++, was wondering if the raw win32 api and mfc are the only options for windows development with c++


Rick

Problems with ShellExecute()

$
0
0

I am trying to open a PDF file when a button is pressed using the ShellExecute() command and am having problems. I first said:

#include "Windows.h"
#include <shellapi.h> 

and then added later on:

private: System::Void btn2_Click(System::Object^  sender, System::EventArgs^  e) {
ShellExecute(NULL, "Open", "C:\\Program Files\\My Prgram\\test1.pdf", NULL, NULL, SW_SHOWNORMAL);
}

And got the following errors:

1>c:\users\raj\documents\visual studio 2010\projects\helloworld\helloworld\Form1.h(109): error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Also, I would like the PDF file to be kept in a folder with the executable (.exe) file and the folder in which both these files are in may be moved, how would I define the directory for this?

Thanks.

Creating a menu.

$
0
0

resource.rc:

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"




//
// Menu resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDR_MENU1 MENU
{
    POPUP "graph"
    {
        MENUITEM "graph", IDM_GRAPH1
    }
    POPUP "newtons"
    {
        MENUITEM "newtons", IDM_NEWTONS1
    }
}

resource.h

#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDR_MENU1                               100
#define IDM_GRAPH1                              40000
#define IDM_NEWTONS1                            40001

demoapp.cpp

#include "DemoApp.h"
#include "resource.h"

int WINAPI WinMain(HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */)
{
    HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);

	if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
    {
        {
            DemoApp app;

            if (SUCCEEDED(app.Initialize()))
            {
                app.RunMessageLoop();
            }
        }
        CoUninitialize();
    }

    return 0;
}

// DemoApp constructor
DemoApp::DemoApp() :
    m_hwnd(NULL),
    m_pDirect2dFactory(NULL),
    m_pRenderTarget(NULL),
    m_pLightSlateGrayBrush(NULL),
    m_pCornflowerBlueBrush(NULL)
{
}

// DemoApp destructor
// Releases the application's resources.
DemoApp::~DemoApp()
{
    SafeRelease(&m_pDirect2dFactory);
    SafeRelease(&m_pRenderTarget);
    SafeRelease(&m_pLightSlateGrayBrush);
    SafeRelease(&m_pCornflowerBlueBrush);

}

// Creates the application window and device-independent
// resources.
HRESULT DemoApp::Initialize()
{
    HRESULT hr;

    // Initialize device-indpendent resources, such
    // as the Direct2D factory.
    hr = CreateDeviceIndependentResources();

    if (SUCCEEDED(hr))
    {
        // Register the window class.
        WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
        wcex.style         = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc   = DemoApp::WndProc;
        wcex.cbClsExtra    = 0;
        wcex.cbWndExtra    = sizeof(LONG_PTR);
        wcex.hInstance     = HINST_THISCOMPONENT;
        wcex.hbrBackground = NULL;
        wcex.lpszMenuName  = NULL;
        wcex.hCursor       = LoadCursor(NULL, IDI_APPLICATION);
        wcex.lpszClassName = L"D2DDemoApp";

        RegisterClassEx(&wcex);


        // Because the CreateWindow function takes its size in pixels,
        // obtain the system DPI and use it to scale the window size.
        FLOAT dpiX, dpiY;

        // The factory returns the current system DPI. This is also the value it will use
        // to create its own windows.
        m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);

		HMENU hMenu = LoadMenu(HINST_THISCOMPONENT, TEXT("IDR_MENU1"));

        // Create the window.
        m_hwnd = CreateWindow(
            L"D2DDemoApp",
            L"Direct2D Demo App",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            static_cast<UINT>(ceil(640.f * dpiX / 96.f)),
            static_cast<UINT>(ceil(480.f * dpiY / 96.f)),
            NULL,
			hMenu,
            HINST_THISCOMPONENT,
            this
            );

        hr = m_hwnd ? S_OK : E_FAIL;
        if (SUCCEEDED(hr))
        {
            ShowWindow(m_hwnd, SW_SHOWNORMAL);
            UpdateWindow(m_hwnd);
        }
    }

    return hr;
}

// Creates resources that are not bound to a particular device.
// Their lifetime effectively extends for the duration of the
// application.
HRESULT DemoApp::CreateDeviceIndependentResources()
{
    HRESULT hr = S_OK;

    // Create a Direct2D factory.
    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pDirect2dFactory);

    return hr;
}


// Creates resources that are bound to a particular
// Direct3D device. These resources need to be recreated
// if the Direct3D device dissapears, such as when the display
// changes, the window is remoted, etc.
HRESULT DemoApp::CreateDeviceResources()
{
    HRESULT hr = S_OK;

    if (!m_pRenderTarget)
    {
        RECT rc;
        GetClientRect(m_hwnd, &rc);

        D2D1_SIZE_U size = D2D1::SizeU(
            rc.right - rc.left,
            rc.bottom - rc.top
            );

        // Create a Direct2D render target.
        hr = m_pDirect2dFactory->CreateHwndRenderTarget(
            D2D1::RenderTargetProperties(),
            D2D1::HwndRenderTargetProperties(m_hwnd, size),&m_pRenderTarget
            );


        if (SUCCEEDED(hr))
        {
            // Create a gray brush.
            hr = m_pRenderTarget->CreateSolidColorBrush(
                D2D1::ColorF(D2D1::ColorF::LightSlateGray),&m_pLightSlateGrayBrush
                );
        }
        if (SUCCEEDED(hr))
        {
            // Create a blue brush.
            hr = m_pRenderTarget->CreateSolidColorBrush(
                D2D1::ColorF(D2D1::ColorF::CornflowerBlue),&m_pCornflowerBlueBrush
                );
        }
    }

    return hr;
}

// Discards device-dependent resources. These resources must be
// recreated when the Direct3D device is lost.
void DemoApp::DiscardDeviceResources()
{
    SafeRelease(&m_pRenderTarget);
    SafeRelease(&m_pLightSlateGrayBrush);
    SafeRelease(&m_pCornflowerBlueBrush);
}

// Runs the main window message loop.
void DemoApp::RunMessageLoop()
{
    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

// This method discards device-specific
// resources if the Direct3D device dissapears during execution and
// recreates the resources the next time it's invoked.
HRESULT DemoApp::OnRender()
{
    HRESULT hr = S_OK;

    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
    {
        m_pRenderTarget->BeginDraw();

        m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

        m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

        D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

        // Draw a grid background.
        int width = static_cast<int>(rtSize.width);
        int height = static_cast<int>(rtSize.height);

        for (int x = 0; x < width; x += 10)
        {
            m_pRenderTarget->DrawLine(
                D2D1::Point2F(static_cast<FLOAT>(x), 0.0f),
                D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height),
                m_pLightSlateGrayBrush,
                0.5f
                );
        }

        for (int y = 0; y < height; y += 10)
        {
            m_pRenderTarget->DrawLine(
                D2D1::Point2F(0.0f, static_cast<FLOAT>(y)),
                D2D1::Point2F(rtSize.width, static_cast<FLOAT>(y)),
                m_pLightSlateGrayBrush,
                0.5f
                );
        }

        // Draw two rectangles.
        D2D1_RECT_F rectangle1 = D2D1::RectF(
            rtSize.width/2 - 50.0f,
            rtSize.height/2 - 50.0f,
            rtSize.width/2 + 50.0f,
            rtSize.height/2 + 50.0f
            );

        D2D1_RECT_F rectangle2 = D2D1::RectF(
            rtSize.width/2 - 100.0f,
            rtSize.height/2 - 100.0f,
            rtSize.width/2 + 100.0f,
            rtSize.height/2 + 100.0f
            );


        // Draw a filled rectangle.
        m_pRenderTarget->FillRectangle(&rectangle1, m_pLightSlateGrayBrush);

        // Draw the outline of a rectangle.
        m_pRenderTarget->DrawRectangle(&rectangle2, m_pCornflowerBlueBrush);

        hr = m_pRenderTarget->EndDraw();
    }

    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardDeviceResources();
    }

    return hr;
}


//  If the application receives a WM_SIZE message, this method
//  resizes the render target appropriately.
void DemoApp::OnResize(UINT width, UINT height)
{
    if (m_pRenderTarget)
    {
        // Note: This method can fail, but it's okay to ignore the
        // error here, because the error will be returned again
        // the next time EndDraw is called.
		m_pRenderTarget->Resize(D2D1::SizeU(width, height));
    }
}

// Handles window messages.
LRESULT CALLBACK DemoApp::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    LRESULT result = 0;

    if (message == WM_CREATE)
    {
        LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
        DemoApp *pDemoApp = (DemoApp *)pcs->lpCreateParams;
        ::SetWindowLongPtrW(hwnd,GWLP_USERDATA,PtrToUlong(pDemoApp));
        result = 1;
    }
    else
    {
        DemoApp *pDemoApp = reinterpret_cast<DemoApp *>(static_cast<LONG_PTR>(
        ::GetWindowLongPtrW(hwnd,GWLP_USERDATA))
		);
        bool wasHandled = false;

        if (pDemoApp)
        {
            switch (message)
            {
            case WM_SIZE:
                {
                    UINT width = LOWORD(lParam);
                    UINT height = HIWORD(lParam);
                    pDemoApp->OnResize(width, height);
                }
                result = 0;
                wasHandled = true;
                break;

            case WM_DISPLAYCHANGE:
                {
                    InvalidateRect(hwnd, NULL, FALSE);
                }
                result = 0;
                wasHandled = true;
                break;

            case WM_PAINT:
                {
                    pDemoApp->OnRender();
                    ValidateRect(hwnd, NULL);
                }
                result = 0;
                wasHandled = true;
                break;

            case WM_DESTROY:
                {
                    PostQuitMessage(0);
                }
                result = 1;
                wasHandled = true;
                break;
            }
        }

        if (!wasHandled)
        {
            result = DefWindowProc(hwnd, message, wParam, lParam);
        }
    }

    return result;
}

I have an example from Charles Petzold's book but it does not build because it is dependent on MFC. One of my questions is about MFC. Is MFC considered to be legacy at this point?

I'm reading through the documentation here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms647553(v=vs.85).aspx

as well I am trying to follow the example from Petzold. The code I have right now is:

		HMENU hMenu = LoadMenu(HINST_THISCOMPONENT, TEXT("IDR_MENU1"));

        // Create the window.
        m_hwnd = CreateWindow(
            L"D2DDemoApp",
            L"Direct2D Demo App",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            static_cast<UINT>(ceil(640.f * dpiX / 96.f)),
            static_cast<UINT>(ceil(480.f * dpiY / 96.f)),
            NULL,
			hMenu,
            HINST_THISCOMPONENT,
            this
            );

Although my code compiles and links with no errors I don't see a menu at this point. I'm still looking for example source code for Win32 that doesn't depend on MFC. Is any available? Perhaps someone can tell me why my code is in error? Is there any newer code or should I refer to Petzold?

Thanks...




Viewing all 15302 articles
Browse latest View live


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