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

How to receive a serial signal through a usb port

$
0
0

The company I work for has an older model flight simulator which outputs the aircrafts position to a Roland DXY-1100 plotter through a built-in serial port.  The plotter does not always work correctly, but we cannot find a replacement it do to the age of the technology (unless someone knows where we can get an old Roland DXY-1100, -1150, -1300 style pen plotter).  Instead what I have been tasked to do is to write a computer interface that can receive the plotter signals and translate them into a position on the screen.  As far as I can tell the simulator is outputting ASCII signals to the plotter.  IE.  M2040, 3045 where M is the command for move and the numbers are coordinates in millimeters.  If someone can help me open and monitor the connection I can write the rest.  Thanks.

So here is the question...how do I use a usb port to receive a serial signal from the simulator.  I have already purchased a Keyspan 19HS Hi-Speed USB to Serial Adapter, but I am unsure how to even start. 


Where should a breakpoint be placed to stop at the earliest possible instruction of an MFC application?

$
0
0

Sigh... This was a lot easier when all C/C++ applications began at main()...

In a WPF application, the first code is in App.xaml.cs, but MFC is too darn confusing.

TIA

installing gcc 4.8.2 for eclipse juno on windows 7

$
0
0
ive written the infamouse hello world tutorial to simply go through the paces of knowing what happens when a program is compiled.

however i have a problem. program g++ can not be found in PATH. SO to make sure i have the latest compiler/ collection of compilers i Google searched for the gcc. doing so i found a tar.bz2 and .gz files, from the GNU website.

long story short, any step by step guidance would be appreciated on how to install gcc and get eclipse working so I can write and compile software.

im a novice although I've been studying the c++ syntax for sometime, but using IDE's I'm at a loss. Ive gotten basic functionality down: perspectives, workspace, but setting up preferences for tool chains, choosing compilers, and console commands and mixing it all up along with setting variables (PATH OR ${AVAR}, I get what a var is and if i'm not mistaken the latter of the two is a var inside of another var?) and commands is scrambling my brain.

looking for a some clarity from a more experienced mind.

in short. i just wanna set eclipse up to compile code i write.

thanks for your help if you have the time.

fyi: im using windows 7 on a home built pc. im using IDE eclipse Juno (i like to think ive got the stuff to write any program i want, however using the ide and compiler and knowing the ins and outs is bottle knecking me and is a bit discouraging as im excited to start on a personal project. so that being said any additional information or tutorials that aid in better understanding of using an IDE such as eclipse and installing cool things like compiler collections would be so sweet.

thanks all.

How to set CFileDialog default file path at dlg.DoModal?

$
0
0
I use MFC Visual C++ 4.2.

I want to set CFileDialog default path so when user click a button that will do the dialog, the default path will be the one I set.

I have read the MSDN Library and there was only GetPathName. No SetPathName.

    CFileDialog dlg( TRUE, NULL, NULL, OFN_FILEMUSTEXIST, "All Files (*.*)|*.*||" );
    if( dlg.DoModal() == IDOK ){

    }

How to set the path?

Thank you very much.

This question is about N3797 §12.1/4 or N3337 12.1/5

$
0
0

The quoted paragraphs in the two versions of the Draft (N3797 and N3337) are the same:

A default constructor for a class X is a constructor of class X that can be called without an argument. If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted (8.4). An implicitly-declared default constructor is an inline public member of its class. A defaulted default constructor for class X is defined as deleted if:

  • X is a union-like class that has a variant member with a non-trivial default constructor,
  • any non-static data member with no brace-or-equal-initializer is of reference type,
  • any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-
    initializer does not have a user-provided default constructor,
  • X is a union and all of its variant members are of const-qualified type (or array thereof),
  • X is a non-union class and all members of any anonymous union member are of const-qualified type (or array thereof),
  • any direct or virtual base class, or non-static data member with no brace-or-equal-initializer, has class type M (or array thereof) and either M has no default constructor or overload resolution (13.3) as applied to M’s default constructor results in an ambiguity or in a function that is deleted or inaccessible from the defaulted default constructor, or
  • any direct or virtual base class or non-static data member has a type with a destructor that is deleted or inaccessible from the defaulted default constructor.

I'll start with the 4th bullet point. As you can see here (http://rextester.com/HCPP94321) and here (http://rextester.com/HHQUB4028), the results vary for the compilers VS2013, clang and g++, and it appears to me that the only one respecting this bullet point in the Standard is clang, as I'll try to explain below:

The first snippet

#include <iostream>

union U
{
    const int i;
    const double x;
    char c;
};

int main()
{
    U u;
}

shows one non-constant variant-member in the union U. This should compile without a problem. But that's not what happens. I summarize below the results for the three compilers:

VS2013    -  error C2512: 'U' no appropriate default constructor available

clang        -  Ok (no error message)

g++          -  error: uninitialized const member in 'Union U'
                    note: 'U::i' should be initialized
                    error: uninitialized const member in 'Union U'
                    note: 'U::x' should be initialized

The second snippet

#include <iostream>

union U
{
    const int i;
    const double x;
    const char c;
};

int main()
{
    U u;
}

shows all variant members in the Union constant, which is the subject of the 4th bullet point above. See below the results for each compiler:

VS2013   -  the same error C2512

clang       -  error: call to implicitly-deleted default constructor of 'U'
                   note: default constructor of 'U' is implicitly deleted because all data members are const-qualified

g++        -   the same errors listed above

Assuming clang is correct, I can understand the reason for the implicit deletion of the default constructor in this case, i.e., to avoid an uninitialized object of a union, where all variant-members are constant.

Now lets consider the third bullet point above:

  • any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-
    initializer does not have a user-provided default constructor,

Here I don't see the need for this implicit deletion of the default constructor, for the compiler will always show an error for a class constant member which is not initialized, as you can see here (http://rextester.com/AOI2981). That is, what's the reason for this bullet point?

Why the row height of CListCtrl are different when case1 create it on CDockablePane and Case2 create it on CDialog?

$
0
0

That is a problem that, the row height and font of CListCtrl are different in following 2 cases:

         Case 1: Create a CListCtrl in CDockablePane

         Case 2: Create a CListCtrl on CDialog

For case 1, when use CListCtrl::GetFont function, the font height is -12, while for case 2, the font height is -11, and from the UI, we will see the row height are diffenent, the row height of CListCtrl in CDockablePane is large than in CDialog, why will they be different?

Visual styles and CTLCOLOR messages

$
0
0

I have enabled Visual Styles for my application. I like the better look but also like to control the color by myself. Unfortunately the behaviour of the CRLCOLOR messages is different. When I return a hollow brush, the back color is black. Setting the text color does not work. This is true especially für check boxes. Turning off the visual styles for specific controls is not an option.

How can I solve?

Thanks, Richard

Pointer-to function issue

$
0
0

In moving from VS2008 to VS2013 I'm experiencing an issue with pointers.  This type of declaration and function calls worked on the older version of VS:

double sigma;

double lysq;

int nl;

(this is a class for Dynamically allocated arrays, Cline, M., C++ FAQ Lite document,http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.19, 10/22/2008)

template<class T2D> class Matrix2D {
 public:
   Matrix2D(unsigned nrows, unsigned ncols);	// Throws a BadSize object if either size is zero
   class BadSize { };
   // Access methods to get the (i,j) element:
   T2D&       operator() (unsigned i, unsigned j);
   const T2D& operator() (unsigned i, unsigned j) const;
   // These throw a BoundsViolation object if i or j is too big
   class BoundsViolation { };
   unsigned nrows() const;						// #rows in this matrix
   unsigned ncols() const;						// #columns in this matrix
 private:
   std::vector<std::vector<T2D> > data_;
 };
 template<class T2D>
 inline unsigned Matrix2D<T2D>::nrows() const
 { return data_.size(); }
 template<class T2D>
 inline unsigned Matrix2D<T2D>::ncols() const
 { return data_[0].size(); }
 template<class T2D>
 inline T2D& Matrix2D<T2D>::operator() (unsigned row, unsigned col)
 {
   if (row >= nrows() || col >= ncols()) throw BoundsViolation();
   return data_[row][col];
 }
 template<class T2D>
 inline const T2D& Matrix2D<T2D>::operator() (unsigned row, unsigned col) const
 {
   if (row >= nrows() || col >= ncols()) throw BoundsViolation();
   return data_[row][col];
 }
 template<class T2D>
 Matrix2D<T2D>::Matrix2D(unsigned nrows, unsigned ncols)
   : data_ (nrows)
 {
   if (nrows == 0 || ncols == 0)
     throw BadSize();
   for (unsigned i = 0; i < nrows; ++i)
     data_[i].resize(ncols);
 }

Matrix2D<double> FUNCTION(const Matrix2D<double>& sigma, const int nl) (function declaration)

int main()

nl = 7;

Matrix2D<double>sigma(nl,72);

Matrix2D<double>lysq(nl,72);

sigma(i, j) = expression;

lysq = FUNCTION(sigma, nl);

out << sigma(i, j); -->this is where I get two errors (in the code:  "Error:  expression preceding parentheses of apparent call must have (pointer-to-) function type" and upon building:  "Error C2064:  term does not evaluate to a function taking 2 arguments")

FUNCTION(const Matrix2D<double>& sigma, const int nl)

Thanks, Rob


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.

Looking for a Mentor

$
0
0
Hi there. I'm currently a student in a CS degree and I'm looking for someone to mentor/tutor me. I'm looking for someone that can help me with challenging assignments/topics, have in-depth conversations regarding the topics I'm learning about and just all around help me out.

We are coding in C++ and using Visual Studio 2013.

Thanks!

Jenn

tips from jk

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

namespace BookList
{
    class Book
    {
        public string Author { get; set; }
        public string Title { get; set; }
        public decimal Price { get; set; }

        public Book(string author, string title, string price)
        {
            this.Author = author;
            this.Title = title;
            this.Price = Convert.ToDecimal(price);
        }

        public override string ToString()
        {
            return Author + " " + Title + " €" + Price;

        }

        public string FileWriteFormat()
        {
            //charles dickens,hard times,10
            return Author + "," + Title + "," + Price;

        }
    }
}

File Upload(Web Based Internet Explorer) need Code

$
0
0

Hi

I want to select a file using  fileupload through code (with out human invervention).

when i run the code fileupload control should automatically pick the file from specific path.

advance thanks.


hi

error C2664: '_com_ptr_t::_com_ptr_t(LPCSTR,IUnknown *,DWORD)' : cannot convert argument 1 from 'ATL::CComPtr' to 'int'_

$
0
0

Hii

I am migrating my application from vc++ 0.6 to vc++2013, one of the error i am facing is given above,

I am sending th epart of my code with the error line highlighted

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

// Get first child of m_spXMLNode which represents a record. This should be all elements without text child
// @returns true if a child is found, otherwise false.
bool CXMLHelper::GetFirstSubRecord()
{
 bool bFound = false;
 
 if ( m_spXMLNode == NULL ) return false;
 if ( VARIANT_TRUE == m_spXMLNode->hasChildNodes() )
 {
  typedef object_iterator<XML::IXMLDOMNode> iterator;
  for ( iterator oIte(m_spXMLNode->childNodes); oIte != iterator(); ++oIte )
  {
   XML::IXMLDOMNodePtr spNode(*oIte);      // error line
   if ( spNode->hasChildNodes() && !CXMLHelper::HasTextChild(spNode) )
   {
    // We have found a node whithout text ==> this is a subrecord
    m_spXMLNode = spNode;
    bFound = true;
    break; // leave loop
   }
  }
 }

 return bFound;
}

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

Please can anyone help me get through this??

Thanks Ankush

WinHttp x64 crash

$
0
0

Hi everyone,

I run into issue when application is crashing if inaccessible host/IP is specified.

steps:

1) open asynchronous session/connection to inaccessible host/IP

2) send GET request

3) before request timeouts, close (valid) request handle with  WinHttpCloseHandle

at this point, request should be aborted and callback should be called with WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, but instead, I get windows exception. Details in this exception says that array is being used with index out of range. If I wait when request gets timeouted, no exception will occur. 32 bit app doesn't seem to have this issue.

Am I doing something wrong?Does anybody else run into this issue? Is there some workaround?

Thanks in advance for your help/advice/pointers,

PetrB

Converting code from visual c++ 6.0 to visual c++ 2010

$
0
0

I have been tasked by my employer to convert an old code written in Visual C++6.0 to Visual C++ 2010.

How can I convert the function below to Visual C++ 2010? All my previous Attempts lead to memory errors on Visual C++2010.

The function CI_CompileProgram is actually in a DLL and the declaration is 

STDCALL CI_CompileProgram(wchar_t* wsXMLFile, wchar_t* wsSavePath);

Function to be updated starts below ..........

void Compiler_now::OnFileCompile()
{

// TODO: Add your command handler code here

CFileDialog dlg(TRUE, _T("xml"), NULL, OFN_FILEMUSTEXIST, _T("xml file(*.xml) | *.xml"));
if(dlg.DoModal() == IDOK)
{
CString strPath = dlg.GetPathName();
int len  = strPath.ReverseFind(L'\\');
CString strSave = strPath.Left(len);
if(CI_CompileProgram(strPath.GetBuffer(strPath.GetLength()), strSave.GetBuffer(strSave.GetLength())))
MessageBox(_T("Compilation is complete!"));
else
MessageBox(_T("Compilation is failed!"));
}
}


Microsoft visual studio 2013 express keeps telling me to...

$
0
0

Microsoft visual studio 2013 express keeps telling me to repair or uninstall it how do I stop this?

I've repaired and uninstalled visual studio multiple times.

Copy data from file.txt to an array

$
0
0
Hello everyone !
I have to make a program where I have to take data from a .txt file and put that information into an INT.array.When I open the file , it looks like this :

125 George
59 Samantha
88 Name
75 Other Name
... ...
Number Name
etc, etc...

So I have to copy only the numbers from the text file and put them into an array. How do I do that ?
Thanks in advance !

split into word from a text line

$
0
0

i want coding for split the word by word from a text document or line.it store in different string in vc++2012

ex:this is the text

output:

string1=this

string2=is

string3=the

string4=text


Karthikn.s


Hello World Error

$
0
0

Hello, I need help with the following error.
Thank you!

midl : error MIDL2019: error accessing type info : Error Returned -2147312566

$
0
0

Hii

I am migrating my application from vc++0.6 to vc++ 2013

I am facing these error MIDL2019

Can anyone help me through this

Thanks Ankush

Viewing all 15302 articles
Browse latest View live


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