Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3021 articles
Browse latest View live

Code worked in VS6 but not in VS2017

$
0
0
The following code worked before with VS6 VC++. But it does not complete the compiling with VS2017 VC++ (Link error is shown below). The complete template is in a .h file. What was changed in VS2017? What needs to be done to resolve the error? Please help. Thanks. error LNK2019: unresolved external symbol "class CArrayEx __cdecl operator-(class CArrayEx const &,class CArrayEx const &)" (??G@YA?AV?$CArrayEx@NN@@ABV0@0@Z) referenced in function "public: int __thiscall CMathEx::QNSS(class CArrayEx const &,class CArrayEx &,class CArrayEx &,double &,double &,int &,int)" (?QNSS@CMathEx@@QAEHABV?$CArrayEx@NN@@AAV2@1AAN2AAHH@Z) Code: --------- // template class CArrayEx : public CArray { public: CArrayEx(){} ...... friend CArrayEx operator + (const CArrayEx& za1,const CArrayEx& za2); ...... }; template CArrayEx operator + (const CArrayEx& za1,const CArrayEx& za2) { CArrayEx za; za.SetSize(min(za1.GetSize(),za2.GetSize())); for (int i=0;i

Is it possible to get a screen capture on windows 7 without capturing its own window?

$
0
0
If I use GetDesktopWindow(), it includes the window which starts the capturing, I don't want to include that window. Just everything except the firing program. how can I achieve this? thanks Jack

How do I teach myself C++?

$
0
0
Hi, I found that after graduating college, I've had a lot of trouble teaching myself new skills. My guess is I'm not knowledgeable enough to know what information I need to find to learn the subject, and I'm not organized enough to put it together coherently. I've heard that people successfully teach themselves new skills all of the time, but I often struggle with this. There's just too much information out there, and I, as a novice learner, can't seem to figure out what it is I need to know. I've tried things like Code Academy and Free Code Camp, but it seems like I don't remember the information I learned long enough to be able to apply it in a new way. I can easily complete the exercises and go on to the next level, but I guess this isn't true learning. I feel like I need a new strategy if I want to be successful teaching myself a programming language and staying up-to-date with technology.

Track database changes

$
0
0
Hi, ALL,
I'm trying to implement the solution explained in this.
However trying to call "SQLExecDirect();" on the very first query "IF NOT EXISTS(SELECT..." returns SQL_DATA_AT_EXEC.

I don't understand this return code at all. I'm not asking for any data - I'm changing database parameter in order to proceed.
My DSN is set to connect to the database I'm trying to modify - maybe this is the culprit and I should be connected to "master"?

Or maybe there is an easier way to track schema changes for MS SQL Server?

Can someone please advise?

Thank you.

Smart pointers

$
0
0
Hi,
I was told that my code will be greatly simplified if I start using smart pointers available in C++11. However, it is kind of hard for me to get the syntax.

In the old way I simply write:

Code:

std::vector<Foo *> m_myVector;
m_myVector.push_back( new Foo( <constructor_parameter_list> ) );

How it will convert using the new syntax?

Thank you.

SQLSetPos failure

$
0
0
Hi,
I am trying to do follwing:
Execute a query on the database and grab just some fields results.
Then call SQLSetPos( stmt, 0, SQL_POSITION, SQL_LOCK_NO_CHANGE ); and then process the complete data again.

Unfortunately the call to SQLSetPos() fails with the "Invalid cursor state". Looking at the MSDN, it says:

Quote:

The StatementHandle was in an executed state, but no result set was associated with the StatementHandle.
I am not sure I understand. I am just trying to move the cursor pointer to the first record of the recordset and so yes the statement is in the executed state and the result set should be available from the record 1 again.

Does anybody knows how do I fix it? Or there is a better way?

I was trying to not to re-create the statement handle, since I already have it and I already have a result set.

Just tried to use "1" as a second parameter. Got the same error.


Thank you.

[RESOLVED] std::vector iterators

$
0
0
I'm compiling a header file which contains the following function...

Code:

                PamPort * find_port (const std::string& port_name) const {
                        for (std::vector<PamPort*>::const_iterator it = _ports.begin (); it != _ports.end (); ++it) {
                                if ((*it)->name () == port_name) {
                                        return *it;
                                }
                        }

When I run this in the debugger, MSVC complains about incompatible iterator types. The only thing I could see was that it uses a const_iterator but then tries to return the result as non-const. So I changed the iterator to std::vector<PamPort*>::iterator it

Unfortunately, this seems to have broken the compilation :cry:

Quote:

error C2440: 'initializing' : cannot convert from 'std::_Vector_const_iterator<_Ty,_Alloc>' to 'std::_Vector_iterator<_Ty,_Alloc>'
_ports is declared as std::vector<PamPort *> _ports; so I'm not sure why it won't work with a non-const interator. What am I not seeing :confused:

Why is C++ STL implementation is written like this

$
0
0
Why they use some kind of crazy naming convension and lot of underscores?

Code:

        // constructors
        vector_impl(_Mytype_t% _Right)
                {        // construct by copying _Right
                for (size_type _Idx = _Buy(_Right.size()); 0 <= --_Idx; )
                        _Myarray[_Idx] = _Mymake_t::make_value(_Right.at(_Idx));
                _Mysize = _Right.size();
                }

        explicit vector_impl(size_type _Count)
                {        // construct from _Count * value_type()
                _Mysize = _Fill_n(0, _Buy(_Count), value_type());
                }

        vector_impl(size_type _Count, value_type _Val)
                {        // construct from _Count * _Val
                _Mysize = _Fill_n(0, _Buy(_Count), _Val);
                }

        template<typename _InIt_t>
                vector_impl(_InIt_t _First, _InIt_t _Last)
                {        // construct from [_First, _Last)
                _Construct(_First, _Last, _Iter_category(_First));
                }

        template<typename _InIt_t>
                void _Construct(_InIt_t _Count, _InIt_t _Val,
                        _Int_iterator_tag%)
                {        // initialize with _Count * _Val
                _Mysize = _Fill_n(0, _Buy((size_type)_Count), (value_type)_Val);
                }

        template<typename _InIt_t>
                void _Construct(_InIt_t _First, _InIt_t _Last,
                        input_iterator_tag%)
                {        // initialize with [_First, _Last), input iterators
                _Buy(_First != _Last ? 1 : 0);        // buy at least one if non-empty
                for (; _First != _Last; ++_First)
                        insert_n(size(), 1, (value_type)*_First);
                }

        template<typename _InIt_t>
                void _Construct(_InIt_t _First, _InIt_t _Last,
                        forward_iterator_tag%)
                {        // initialize with [_First, _Last), forward iterators
                size_type _Size = cliext::distance(_First, _Last);

                _Buy(_Size);
                for (size_type _Idx = 0; _Idx < _Size; ++_Idx, ++_First)
                        _Myarray[_Idx] = _Mymake_t::make_value(value_type(*_First));
                _Mysize = _Size;
                }


Convert console into SDI

$
0
0
Hi all of you. I came here because I get always help here, and I am stuck into relative simple issue: to convert a console program, into a real life SDI MFC app, an program that embed OpenCV library.

I have taken from here the sample program: https://www.youtube.com/watch?v=A4UDOAOTRdw

And here is the code, simplified:
Code:

int main(void)
{
cv::VideoCapture capVideo;

cv::Mat imgFrame1;
cv::Mat imgFrame2;

std::vector<Blob> blobs;

capVideo.open("768x576.avi");

capVideo.read(imgFrame1);
capVideo.read(imgFrame2);

char chCheckForEscKey = 0;

bool blnFirstFrame = true;

int frameCount = 2;

while (capVideo.isOpened() && chCheckForEscKey != 27)
{
    std::vector<Blob> currentFrameBlobs;

    cv::Mat imgFrame1Copy = imgFrame1.clone();
    cv::Mat imgFrame2Copy = imgFrame2.clone();

    // image processing (simplified code)

    imgFrame2Copy = imgFrame2.clone();          // get another copy of frame 2 since we changed the previous frame 2 copy in the processing above

    drawBlobInfoOnImage(blobs, imgFrame2Copy);

    cv::imshow("imgFrame2Copy", imgFrame2Copy);

    // now we prepare for the next iteration
    currentFrameBlobs.clear();
    imgFrame1 = imgFrame2.clone();          // move frame 1 up to where frame 2 is

    if ((capVideo.get(CV_CAP_PROP_POS_FRAMES) + 1) < capVideo.get(CV_CAP_PROP_FRAME_COUNT))
    {
        capVideo.read(imgFrame2);
    }

    blnFirstFrame = false;
    frameCount++;
    chCheckForEscKey = cv::waitKey(1);
}

return(0);
}

and here is the result:
Name:  KaixV.jpg
Views: 118
Size:  29.2 KB
Now, I have tried to made some similar in MFC:
Code:

    class CMyDoc : public CDocument
{
// Attributes
public:
    cv::Mat m_Mat;    // this will be rendered in CView !!!
....

and
Code:

    protected:
    BOOL m_bFirstFrame;
    cv::Mat m_Mat1, m_Mat2;
    cv::VideoCapture m_Video;
    std::vector<CBlob> m_blobs;

and the implementation code is simple:
Code:

    void CMyDoc::ShowNextFrame()    // called at some time interval, when FPS rate is request this
{
    if(m_Video.isOpened())
    {
        m_Video.read(m_Mat);
        DrawVideoImageSubtractionAndCount();
    }
}

And here is the buggy DrawVideoImageSubtractionAndCount:
Code:

    void CMyDoc::DrawVideoImageSubtractionAndCount()
{
    if(m_bFirstFrame)
    {
        m_Video.read(m_Mat1);
        m_Video.read(m_Mat2);
    }

    // image processing

    Mat2Copy = m_Mat2.clone();          // get another copy of frame 2 since we changed the previous frame 2 copy in the processing above
    DrawBlobInfoOnImage(m_blobs, Mat2Copy);
    m_Mat = Mat2Copy.clone();

    m_Mat1 = m_Mat2.clone();
    m_Video.read(m_Mat2);

    m_bFirstFrame = FALSE;
}

and here is the result of my MFC:
Name:  CETnE.jpg
Views: 117
Size:  30.7 KB
Can you tell me how to handle m_Mat in order to have the right result ?

Thank you for any hint/solution.
Attached Images
  

CPPUNIT_ASSERT (macro ?)

$
0
0
While debugging someone else's code yesterday I came across various statements like CPPUNIT_ASSERT() / CPPUNIT_ASSERT_EQUAL() etc - but i can't seem to find them defined anywhere. Are they just "known" to the compiler somehow? :confused:

access violation reading location 0x00000000

$
0
0
hello..
i am running a thread.but when i try to print anything edit box using the line
aa.Format("%d",i);
ts->_this->GetDlgItem(IDC_EDIT3)->SetWindowText(aa);//run time error occurs here.

my code is compilation error free.but i get an error when i run it as
access violation reading location 0x00000000

plz help.

How to use C++ concept I have learned with Visual Studio... visually?

$
0
0
I am learning C++. It is going really well. It is making other stuff I have done in programming really make sense. I was interested in getting started programming with C++ visually. I want to make a program that runs on Windows. I did not know where to get started. There is not a lot of info on the topic. I found a helpful video on YouTube that showed how to get set up. It leaves me off with code like so:
Code:

#include "MyForm.h"

using namespace System;
using namespace System::Windows::Forms;

[STAThreadAttribute]
int main(array<String^>^ args) {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        Lotto1::MyForm form;
        Application::Run(%form);
        return 0;
}

I do not know how to continue from here. How would I add some code that performs something like calculating with overloaded functions! If anybody has any examples I would greatly apreciate seeing them. I want to make a program that calculates values for a sphere or a cylinder with an overloaded function like so:
Code:

int main()
{
        double Pi = 3.14790;
        cout << "Enter a radius: ";
        double radius = 0;
        cin >> radius;
       
        cout << "The sphere = " << calcRound(Pi, radius) << endl;

        cout << "Do you want to calculate the a cylinder? (yes = y/no = n) ";
        char answer1 = 'n';
        cin >> answer1;

        if (answer1 == 'y')
        {
                cout << "Enter a height: ";
                int height = 0;
                cin >> height;
               
                calcRound(Pi, radius, height);
                cout << "The cylinder = " << calcRound(Pi, radius, height) << endl;
        }

        return 0;
}

double calcRound(double Pi, double radius)
{
        Pi = 3.1409316;
        double sphere = 4 * Pi * radius * radius * radius;
        return sphere;
}

double calcRound(double Pi, double radius, int height)
{
        Pi = 3.14317529;
        double cylinder = Pi * radius * radius * height;
        return cylinder;
}

in func.h:
Code:

in func.h:

#ifndef FUNC_H_
#define FUNC_H_

double calcRound(double Pi, double radius);
double calcRound(double Pi, double radius, int height);

#endif // FUNC_H_

The video I watched is:
https://www.youtube.com/watch?reload=9&v=0XGQIN9hfGQ

Thanks for any help

edit box problem

$
0
0
how do i read the contents of the edit box when the thread is getting executed.i am not able to use the member variable of the edit box which i have created,its popping an error. plz help

Bookmarks in VS 2015

$
0
0
In Visual Studio 2008, there is an option to move to the previous or next bookmark in the *current document.* This was replaced in Visual Studio 2015 with move to the previous or next bookmark in the *current folder!* Very disappointing. It is more useful to move around bookmarks in a document than in a folder! Specially if the document is large. Any possible way of going back to the VS 2008 option for bookmarks in a document? thanks...

No data returned

$
0
0
Hi, I've been on this couple of hours but can't figure out why am I not getting the data. I think I just need a fresh pair of eyes. Thank you. Code: --------- ret = SQLPrepare( m_hstmt, qry, SQL_NTS ); if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, m_hstmt ); result = 1; } else { ret = SQLNumResultCols( m_hstmt, &numCols ); if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, m_hstmt ); result = 1; } else { for( int i = 0; i < numCols; i++ ) { columnNameLen = new SQLSMALLINT *[numCols]; columnDataType = new SQLSMALLINT *[numCols]; columnDataSize = new SQLULEN *[numCols]; colummnDataDigits = new SQLSMALLINT *[numCols]; columnDataNullable = new SQLSMALLINT *[numCols]; columnData = new SQLWCHAR *[numCols]; columnDataLen = new SQLLEN *[numCols]; } for( int i = 0; i < numCols; i++ ) { columnNameLen[i] = new SQLSMALLINT; columnDataType[i] = new SQLSMALLINT; columnDataSize[i] = new SQLULEN; colummnDataDigits[i] = new SQLSMALLINT; columnDataNullable[i] = new SQLSMALLINT; columnName[i] = new SQLWCHAR[256]; columnDataLen[i] = new SQLLEN; ret = SQLDescribeCol( m_hstmt, i + 1, columnName[i], 256, columnNameLen[i], columnDataType[i], columnDataSize[i], colummnDataDigits[i], columnDataNullable[i] ); if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, m_hstmt ); result = 1; break; } columnData[i] = new SQLWCHAR[(unsigned int) *columnDataSize[i] + 1]; memset( columnData[i], '\0', (unsigned int) *columnDataSize[i] + 1 ); switch( *columnDataType[i] ) { case SQL_INTEGER: *columnDataType[i] = SQL_C_LONG; break; case SQL_VARCHAR: case SQL_CHAR: *columnDataType[i] = SQL_C_CHAR; break; case SQL_WVARCHAR: case SQL_WCHAR: *columnDataType[i] = SQL_C_WCHAR; break; } ret = SQLBindCol( m_hstmt, i + 1, *columnDataType[i], &columnData[i], *columnDataSize[i], columnDataLen[i] ); if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, m_hstmt ); result = 1; break; } } ret = SQLExecute( m_hstmt ); if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, m_hstmt ); result = 1; } for( ret = SQLFetch( m_hstmt ); ( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO ) && ret != SQL_NO_DATA; ret = SQLFetch( m_hstmt ) ) { str_to_uc_cpy( tableName, columnData[2] ); //if( *columnData[1] == 'C' ) str_to_uc_cpy( command, columnData[2] ); } --------- Everything works as expected but the columnData are empty strings. Below is the query I'm trying to execute: Code: --------- std::wstring sub_query1 = L"SET NOCOUNT ON; DECLARE @TargetDialogHandle UNIQUEIDENTIFIER; "; std::wstring sub_query2 = L"DECLARE @EventMessage XML; "; std::wstring sub_query3 = L"DECLARE @EventMessageTypeName sysname; "; std::wstring sub_query4 = L"WAITFOR( RECEIVE TOP(1) @TargetDialogHandle = conversation_handle, @EventMessage = CONVERT(XML, message_body), @EventMessageTypeName = message_type_name FROM dbo.EventNotificationQueue ), TIMEOUT 1000;"; std::wstring sub_query5 = L"SELECT @EventMessageTypeName AS MessageTypeName, @EventMessage.value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)') AS TSQLCommand, @EventMessage.value('(/EVENT_INSTANCE/ObjectName)[1]', 'varchar(128)' ) as TableName"; std::wstring query = sub_query1 + sub_query2 + sub_query3 + sub_query4 + sub_query5; --------- Running it Management Studio everything works. Could someone please help?

How do I report a problem to MS?

$
0
0
Hi, This past weekend my Windows 8.1 picked up updates. Unfortunately they (or one of them) broke my SQL Server 2005, that came with the machine - turns out I can't query any of the table in the "sys" schema. Is there a way to report the problem to MS? Thank you.

mathematical equation implmentation in c++

$
0
0
Hello,

I need to implement the following math conversion in the c++. I am looking for simple function. Could you help me with this., I am not much aware of the maths functionalities available in c++

1. Need to convert dBns to ns and the in the xml requirements, I see the formula as : 10^(0.8 * x)

2. Other conversion is similar(mBradians to radians) : 10 ^ (0.001 * x)
Then I need the convert the radians to degrees

Thanks a lot
pdk

How to get displayed size of mouse cursor on Windows 10 in program

$
0
0
I need to know the displayed size of mouse cursor in my C++ Windows 10 program.


On Windows 10, I make the pointer larger, say 5x than the original.
Name:  setting.jpg
Views: 26
Size:  23.5 KB


Then, in my C++/MFC program, I tried these:

int nXCursor = ::GetSystemMetrics(SM_CXCURSOR);
int nYCursor = ::GetSystemMetrics(SM_CYCURSOR);

or
int nXIcon = ::GetSystemMetrics(SM_CXICON);

or

HICON ico = (HICON)GetCursor();

SIZE res = { 0 };
if (ico)
{
ICONINFO info = { 0 };
if (::GetIconInfo(ico, &info) != 0)
{
BITMAP bmpinfo = { 0 };
if (::GetObject(info.hbmMask, sizeof(BITMAP), &bmpinfo) != 0)
{
res.cx = bmpinfo.bmWidth;
res.cy = bmpinfo.bmHeight;
}
::DeleteObject(info.hbmColor);
::DeleteObject(info.hbmMask);
}
}

They all come back with 32, which is original.

Does anybody know how to get the displayed, enlarged cursor size?
Attached Images
 

Bolding a Font of Groupbox heading/label in CDialog

$
0
0
How to bold a font of groupbox heading/label in CDialog.I tried below code but it didn't worked.
Code:

CWnd * pwnd = GetDlgItem(IDC_GROUPBOX);
CFont * pfont = pwnd->GetFont();
LOGFONT lf; pfont->GetLogFont(&lf);
lf.lfItalic = TRUE;        //To Make Text Italic
lf.lfWeight = 500;          //To Make BOLD, Use FW_SEMIBOLD,FW_BOLD,FW_EXTRABOLD,FW_BLACK
lf.lfUnderline = TRUE;      //Underline Text
pfont->CreateFontIndirect(&lf);
pwnd->SetFont(pfont);

Finding Miracast devices using WifiDirect api (c++)

$
0
0
I am trying to find all Miracast devices/wireless display (like smart TV that supports Miracast).

How i can do that from windows desktop c++ software (not app)?

I would like to do that from win7 and from win10

I read about WiFiDirectService class but i am not sure this is the right way or what is the service name

Any help would be really appreciated.
Viewing all 3021 articles
Browse latest View live