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

getline() with ifstream errors

$
0
0

Hello, I am on Visual Studio 2013. The following code compiles and runs just fine in XCode:

    constchar* infile ="/Users/user1/Documents/master.txt";

    std::ifstream pfile(infile);

    for (std::string line;std::getline(pfile, line);)

    {

            std::cout<< line << std::endl;

    }

With the MSVC compiler, std::getline does not seem to work. Reported error:

"No instance of overloaded function std::getline" matches the argument list. Argument types are const std::ifstream, std::string"

My includes are:

<iostream>

<fstream> - for ifstream

<string> - for getline

Why is this the case and what is the right way to have std::getline working? Thanks for your answers.


Window color on Windows 10 in C++ app

$
0
0

Hello, I have been working on my app for Windows 10 and got a question.

There is an app called "Groove Music" and it uses dark design, so my question is how to set dark design in my app? Right now it uses default color scheme (which is white).

Using DrawThemeBackground

$
0
0

I am struggling for some while to coloring a control scrollbar, with DrawThemeBackground. (any control, no matter what) ... here is the trial:

void CMyControl::OnDraw(CDC* pDC)
{
// draw control
	HTHEME hTheme = OpenThemeData(m_hWnd, L"WINDOW");
//	HTHEME hTheme = OpenThemeData(m_hWnd, L"MFCGridCtrl");
	if(NULL != hTheme)
	{
		if(WS_VSCROLL & GetStyle())
		{
			SCROLLBARINFO si;
			si.cbSize = sizeof(SCROLLBARINFO);
			GetScrollBarInfo(OBJID_VSCROLL, &si);
			CRect rect(si.rcScrollBar);
			pDC->FillSolidRect(&rect, RGB(255, 0, 0));
			HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
			if(S_OK == hResult)
				TRACE("ok\n");
			else
				TRACE("not ok !\n");
		}
		CloseThemeData(hTheme);
	}
}

And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.

input value as a function parameter ?

$
0
0
is there a way to make the user input a value directly as a function argument ?

Unresolved Externals While Linking

$
0
0

I moved my application into  Visual Studio 2015 Community and got the following message when rebuilding.  Can you help me resolve the unresolved externals issues. 

Thank you in advance for your help

Craig

1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

1>msvcmrt.lib(mstartup.obj) : error LNK2020: unresolved token (0A00009B)__scrt_current_native_startup_state

1>msvcmrt.lib(mstartup.obj) : error LNK2020: unresolved token (0A00009C) __scrt_native_startup_lock

1>msvcmrt.lib(mstartup.obj) : error LNK2020: unresolved token (0A0000F5) __scrt_native_dllmain_reason

1>wrtobject.obj : error LNK2019: unresolved external symbol "public: static class CraigsSystem::Object * __cdecl CraigsSystem::Object::Import(void *,unsigned int,char *)" (?Import@Object@CraigsSystem@@SAPAV12@PAXIPAD@Z) referenced in function"public: unsigned int __thiscall <lambda_2ec5f7f75f5aa97109075639f9ee4dde>::operator()(struct Windows::Storage::Streams::IBuffer ^)const " (??R<lambda_2ec5f7f75f5aa97109075639f9ee4dde>@@QBEIP$AAUIBuffer@Streams@Storage@Windows@@@Z)

1>msvcmrt.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___scrt_native_dllmain_reason

1>msvcmrt.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___scrt_current_native_startup_state

1>msvcmrt.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___scrt_native_startup_lock

1>C:\Users\Craigs\Documents\Visual Studio 2015\Projects\OptionChain\Debug\OptionChain\OptionChain.exe : fatal error LNK1120: 7 unresolved externals

Can we build *.sln project using MSBuild without installing the Visual Studio 2012?

$
0
0

Hi All.

Can somebody tell me that can we build *.sln project using MSBuild and without installing the VS2012 product?

I have seen a similar question , but i have many link errors following the answers given in that question.

Here are some of my errors:

msvcprtd.lib(newaop_s.obj) : error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1700”(attribute-construction-list.obj 中) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
MSVCRTD.lib(ti_inst.obj) : error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1700”(attribute-construction-list.obj 中) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
MSVCRTD.lib(tncleanup.obj) : error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1700”(attribute-construction-list.obj 中) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
file-config.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
raw-text-config.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
sixth.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
virtual-net-device.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
attribute-default-iterator.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
attribute-iterator.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
config-store.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ),该符号在函数 "public: virtual class std::error_condition __thiscall std::_System_error_category::default_error_condition(int)const" (?default_error_condition@_System_error_category@std@@UBE?AVerror_condition@2@H@Z) 中被引用 [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
wimax-mac-to-mac-header.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]
wimax-net-device.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) [D:\software\ns-3-win2\windows\ns-3-dev\main\main.vcxproj]

Constant strings in VS2013

$
0
0

Greetings everyone.

I need help.

My company does most of its work in c# these days, but I am responsible for looking after one large legacy project in c++. Last week the Poohbahs decided to migrate everything from VS2010 to VS2013 (they're a conservative bunch who don't rush into things, obviously). We could have kept the c++ code compiling in 2010 compatibility mode, but it was decided to convert completely to 2013.

When I first compiled with the new VS, it forced me to switch on the unicode character set in the project options, and to upgrade the WINVER switch from 500 to 501.

When I compiled, I got more than 2000 errors. The errors of of several kinds, but the common denominator seems to be the treatment of constant strings, presumably due to the change to unicode. Here is a pic of some of the error messages and the lines of code that produced each one.

Obviously, I can fix each individual error by doing a cast (by putting "_T" in front of each string, or whatever), but there are two thousand of the swines. I don't want to fiddle around changing thousands of lines, possibly introducing instability into what has thus far been very stable code. I also don't like the idea of wasting time only to have to go through it all again the next time Microsoft decides to change its string handling.

So...

Is there a better way? Is there some switch or compiler directive somewhere that I can use to get the string handling to work as it is without the need to change 2000 individual lines?

CryptAcquireContext intermittently hangs in a Custom v1 Credential Provider for Contacted Smart Card

$
0
0
In my custom Windows v1 Credential Provider, during the call to ICredentialProvider::SetUsageScenario, I collect Smart card information - discover cards inserted, connect to the card, get the ATR and CSP provider. Then when I call CryptAcquireContext, using the reader as the default container (in preparation to enumerate the card for the containers and certificates), the machine hangs. If I remove the smart card that corresponds to the CryptAcquireContext call, the call aborts. This does not happen all of the time - it is intermittent. I do not understand what could cause CryptAcquireContext to hang. My CP Filter is removing all other credential providers, so I do not know what other process can be holding the smart card to prevent me from accessing it.

Joseph J Eremita


rs232 serial communication .

$
0
0
hi.. i need to develop piece of code in vc++ to demonstrate how to read from rs232 serial communication port and how to write on to it..please help me....

Event trigger for new connection in WebBrowser Control

$
0
0

Hello All

I have developed an Embedded WebBrowser in C++. I would like to know if it is possible to capture event trigger for new connection made by HTTP request? Whenever we request a webpage then there are multiple parallel HTTP request.  I would like to know if there is any way I could know whenever there is a new connection.  

I am trying to implement IBindHost and IInternetProtocolSink in my WebBrowser but unable to succeed. Is this the right approach or can this be achieved by any other way?

Thanks

CreateProcess errors with Japanese Characters

$
0
0

Hi,

I use a Unicode enabled VC++ project that will do that will parse a text file containing some inputs and then create a command using those inputs and invoke the CreateProcess to create the process.

In my particular case, I have some japanese characters in the text file. These are being perfectly read and passed on to the commandline parameter of the CreateProcess. Also note that I am working on an English windows XP machine.

However, when the CreateProcess creates the process, the japanese characters are being converted to question marks and as a result of which the process is not created properly.

Please let us know how this problem can be solved.

Intended Installation Commandline (parsed correctly):

"D:\WorkSpace_Iberia\tools\windows\jdk\jdk1.7.0\bin\java.exe" -Xms16777216 -Xmx50331648 -classpath "C:\Program Files\A바탕\_mm_installation\;C:\Program Files\A바탕\_mm_installation\uninstallerResources.zip;" com.zerog.lax.LAX

The command line actually taken by the create process

"D:\WorkSpace_Iberia\tools\windows\jdk\jdk1.7.0\bin\java.exe" -Xms16777216 -Xmx50331648 -classpath "C:\Program Files\A??\_mm_installation\;C:\Program Files\A??\_mm_installation\uninstallerResources.zip;" com.zerog.lax.LAX

Note: Here the Folder with name as A바탕 is getting converted to A?? resulting in the CreateProcess failure.

Thanks in advance.

Thanks

Jiju

Template and function: instantiations or specialization?

$
0
0

Hello!

I am getting started with templates for a software I am writing. I have an Header.h:

#ifndef Templates_Header_h
#define Templates_Header_h
#include <iostream>

using namespace std;

template<typename T>
struct S
{
private:
    T val;
public:
    S() : val{} {};
    T* get();
    T* get() const;
    T set();
    T operator=(const T&);
    T read_val(T& v);
    void print_val() const;
};

template<typename T>
void S<T>::print_val() const
{
    cout << "Value is: " << val << endl;
}

template<typename T>
T* S<T>::get()
{
    T* p = &val;
    return p;
}

template<typename T>
T S<T>::set()
{
    T newvalue;
    cout << "Type new value: ";
    cin >> newvalue;
    S<T>::val = newvalue;
    return S<T>::val;
}

template<typename T>
T S<T>::operator=(const T&)
{
    T val1;
    val1 = val;
    return *this;
}

template<typename T>
T* S<T>::get() const
{
    T* p = &val;
    return p;
}

template<typename T>
T S<T>::read_val(T& v)
{
    cout << "Type Value: ";
    cin >> v;
    return S<T>::val = v;
}

#endif

This is my Header.cpp:

#include <stdio.h>
#include "Header.h"
#include "std_lib_facilities.h"

template <>
struct S <int>
{
private:
    int val;
public:
    S() : val{0} {};
};

template<>
struct S<char>
{
private:
    char val;
public:
    S() : val{'0'} {};
    char read_val(char& v);
};

template <>
struct S<double>
{
private:
    double val;
public:
    S() : val{0.0} {};
    double read_val(double& v);
};

template <>
struct S<string>
{
private:
    string val;
public:
    S() : val{""} {};
    string read_val(string& v);
};

template<>
struct S<vector<int>>
{
private:
    vector<int> val;
public:
    S() : val{0} {};
};

Now I should define function read_val(T& v) for int, double, string and char but not for vector<int>. What is the correct form to instantiate a function for the types I need? Should I do an instantiation or a specialization?

Thanks!




Windows Radio Manager API Client - CLSIDs are not registered

$
0
0

Visual Studio 2015, Windows 8.1 SDK/WDK. Unmanaged C++ service app, running on Windows 8.1 Enterprise x64, target Windows 8, 8.1, & 10, 32 & 64 bit.

I need to access this API as a client, but it appears that the IDs for IMediaRadioManager and other interfaces are not in the registry, so I get either "no interface" or "class not registered" errors.

I have tried the CLSIDs for RMapi.dll and WlanRadioManager.dll with no luck.

      IMediaRadioManager* manager = nullptr;
      IClassFactory* factory = nullptr;
      CLSID clsid = {};
      // from CLSID registry for RMapi.dll:
      HRESULT hr = CLSIDFromString(L"{581333F6-28DB-41BE-BC7A-FF201F12F3F6}", &clsid);        // ok
      hr = CoGetClassObject(clsid, CLSCTX_ALL, nullptr, IID_IClassFactory, (void**) &factory);    // ok
      hr = factory->CreateInstance(nullptr, IID_IMediaRadioManager, (void**) &manager);  // E_NOINTERFACE 
      hr = factory->QueryInterface(IID_IMediaRadioManager, (void**) &manager);// E_NOINTERFACE

How do I get the CLSIDs to work in order to enumerate the interface instances?

Once I get that I think I am OK. I need to enumerate all the devices, get their status, and register for status change events.

Thanks,

Robert Tonsing

Latest additions to MFC library of UI controls

$
0
0

I am currently using Visual Studio 2010. I design my user interfaces that are mainly dialog based using standard controls as used in my old projects (VS2005). 

Are they any advanced additions to MFC GUI or recommended new controls?

Where can I get this information?


Sharing is profitable only if it happens with knowledge.

MFC - MDI Tabbed windows - listing them all

$
0
0

Here's a code snippet for anyone wanting to iterate through the tabbed windows in a MFC App

void CMainFrame::ActivateDocTab(CChildFrame::ViewType viewType)
{
	CString viewTab(CChildFrame::ConvertViewTypeToStr(viewType));

	CString name;
	const CObList& TabGrps = m_wndClientArea.GetMDITabGroups();
	for (POSITION pos = TabGrps.GetHeadPosition(); pos != 0;)
	{
		CString name;
		CMFCTabCtrl* pNextWnd = nullptr;
		if ((pNextWnd = DYNAMIC_DOWNCAST(CMFCTabCtrl, TabGrps.GetNext(pos))) != nullptr)
		{
			int cnt = pNextWnd->GetVisibleTabsNum();
			for (int x = 0; pNextWnd->GetTabLabel(x, name) == TRUE; x++)
			{
				if (viewTab == name)
				{
					pNextWnd->ActivateMDITab(x);
					break;
				}
			}
		}
	}
}



will stott





Read Excel data from C++ project - Quick and best methodology

$
0
0

Hi,

   I my c++ project I want to open an excel file and query data and identify the rows that matches the specific column values(more than one column). What is the best methodology to connect to excel and query the worksheets?

The excel might contain several thousands of records and hence it is very important to complete the search and show the results in quick time and optimum performance.

Request you to let me know more than one option and suggest the best out of it.

    

  


Sharing is profitable only if it happens with knowledge.

[UWP] Ask user for an input?

$
0
0

I'm absolutely new to the whole UWP, WinRT, XAML etc and I need a way to ask the user for an input, e.g.;

user right clicks on the ToggleSwitch and the app will ask him for a number

I know how to create ToggleSwitch

I know how to do something when user right clicks on ToggleSwitch

I have no idea how to create a dialog that pops out, includes a question, TextBox (accepting only numbers) and "OK" & "Cancel" buttons

where should I look for what I need? any tutorials? examples? anything?

Thanks!

Where is IID_IDXGIFactory4 defined?

$
0
0

I get LNK2001 unresolved external symbol IID_IDXGIFactory4 for the following code chunk:

IDXGIFactory4* dxgiFactory;
auto hr = CreateDXGIFactory1(IID_IDXGIFactory4, (void**)&dxgiFactory);

I am linking against dxgi.lib.  Where is this symbol defined?  I can't figure it out from the documentation.  It is declared in dxgi1_4.h.

GetGlyphOutline for UCS-4 characters?

$
0
0

It seems GetGlyphOutline is only working for UCS-2 Unicode characters.

When I call GetGlyphOutline for a UCS-4 character uChar=0x0002000B (which is not a UCS-2 character), then it seems the hi-word is ignored and the outline for the glyph uChar=0x000B is returned.

How can I get the glyph outline for true UCS-4 characters (UTF-16 surrogate pairs)?

Windows crypto API : Creation of self signed certificate using CertCreateSelfSignCertificate() fails when SHA-256 signature algorithm and subject name containing umlaut characters is specified

$
0
0

Hi All,

I have developed a program in C++ which creates self signed certificate using crypto API interfaceCertCreateSelfSignCertificate().

The program so far worked just fine with

Signature Algorithm - SHA1 with RSA Encryption

I have tested creation of self signed certificates with subject names containing only ASCII as well as containing UTF-8 characters like ä (umlaut a) and its successful.

Recently we have decided to migrate signature algorithm to SHA-256 with RSA Encryption.

I am running the unit tests again and now I find that certificate creation works fine for ASCII subject names with algorithm as SHA256RSA, but subject names containing characters like ä (umlaut a) fails with  error code 2148073512 (The buffer supplied to a function was too small.) from CertCreateSelfSignCertificate().

If I make the signature algorithm back to SHA1RSA, same unit test passes. Also the test passes with SHA256RSA if umlaut a is removed.

I do not get a clue from the error code returned by the CertCreateSelfSignCertificate() interfaceas well, there are no output buffers from this function.

I can post my code here if required. Did anybody face this problem. Any help is much appreciated.

Thanks in Advance,

Sreekanth


Great Day, Sreekanth


Viewing all 15302 articles
Browse latest View live


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