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

How to create a global object of a ref class type?

$
0
0

Hi,

In Visual C++ 2013, I am trying to create a global object of a ref class because I need to share the values between various .cpp files.

But I am having an error: "a variable with static storage duration cannot have a ref class type".

Please help me to solve this.

Thanks.


C++ Resource

$
0
0

Hello,

I want Add File To my project 'Resource '

And when My DLL Load,

Copy The File From Resource  To DLL Folder, or to PC.

Where can I download the header files "Everything.h" and "Environment.h"?

$
0
0
I try googling it but there was no result. Is there a special package I have to download?

Copy elision during copy initialization not always occuring when using STL types such as std::string.

$
0
0

Is their any reason why the below code does not perform copy elision during copy initialization when the std::string is passed by value, but performs it if passed by const reference.

The below code was tested on Visual Studio Express 2012 Update 4 and Visual Studio 2013 Professional Update 2.

I stumbled upon this after thinking about the pass by value and move into place idiom suggested at last years going native conference and by various blogs (such as herb sutter's and cpp-next want speed pass by value).

Example code that does NOT perform copy elision.

#include <string>
#include <iostream>

using std::cout;
using std::endl;
using std::string;

class Object {
public:
    Object(string name)
        : _name{move(name)} {
        cout << "Object(string)" << endl;
    }

    Object(Object&& other)
        : _name{move(other._name)} {
        cout << "Object(Object&&)" << endl;
    }

    Object(const Object& other)
        : _name{other._name} {
        cout << "Object(const Object&)" << endl;
    }

private:
    string _name;
};

int main(int argc, char* argv[]) {
    auto name = string{"Object"};
    auto obj = Object{name};

    return 0;
}


Output:

Object(string)

Object(Object&&)

Example code that DOES perform copy elision.

#include <string>
#include <iostream>

using std::cout;
using std::endl;
using std::string;

class Object {
public:
    Object(const string& name)
        : _name{name} {
        cout << "Object(const string&)" << endl;
    }

    Object(Object&& other)
        : _name{move(other._name)} {
        cout << "Object(Object&&)" << endl;
    }

    Object(const Object& other)
        : _name{other._name} {
        cout << "Object(const Object&)" << endl;
    }

private:
    string _name;
};

int main(int argc, char* argv[]) {
    auto name = string{"Object"};
    auto obj = Object{name};

    return 0;
}

Output:

Object(const string&)

Any feedback is appreciated :)




Changing the text in a CONTROL control

$
0
0

Hi,

I am using VS 2013, an MFC app.

CONTROL         "Point ID",IDC_EPTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,131,292,63,10

I want to change the text when the dialog is created. I want to replace "Point ID" with a Wide character. If I wanted "Point ID" to be a wide character I can prefix the string with 'L'. SetDlgItemText does not work for wide characters, nor does SetDlgItemTextW.

Any help gratefully appreciated

 

Convert CPP Code in .exe in MS Visual Studio 2010 by VC++ Project

$
0
0

Hi,

I have one source code of .CPP program and i want to generate .exe file of this project, for that i create one new EMPTY PROJECT(VC++) in Microsoft Visual Studio 2010 and add all the .cpp and .h files in to Source file Folder.

Now When i m going to built the solution it gives error Like : 

Error: Failed to locate: "CL.exe". The system cannot find the file specified.

In my sytem the CL.exe file on this path : C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\CL.exe

Some of your solution tell that it should be at this location : C:/Program Files\Microsoft Visual Studio 10.0\VC\ce\bin

So can you please suggest what should i do for solve this error?

Or also can you give any other solution which can Complete the Purpose to Generate .exe file of CPP Program ?

Thnx

Vimal Bhavsar

CfileDialog arguments in VC 10

$
0
0

CfileDialog arguments in VC++ 10.

Please explain and give some concrete examples.

Thanks.

GDI+ Flat API and Windows XP SP3

$
0
0

Hello,

I use GDI+ Flat API but I encounter a very strange problem.

If I draw image with attributes through:

  GdipCreateImageAttributes + GdipSetImageAttributesColorMatrix + GdipDrawImageRectRectI

too often, I got a GPF crash on Windows XP.

Surprisingly, this occurs only on Windows XP, not on later OS.

When not using Image Attributes, no problem occurs.

When not using ColorMatrix, problem also occurs.

Do you have any clue on this problem?

I tried to update GDI+ but it did not solved the problem...

Best regards,

Denis


MFC text drawing APIs: kerning and ligatures

$
0
0

Programming with VS2010, and drawing text  with the UTF-16 versions  DrawTextW,  TextOutW,  ExtTextOutW of the  old  APIs (and their MFC wrappers in the CDC class):

If one selects an Open Type font then it appears that ligatures (eg f+i -> fi) are respected (which is nice), but kerning pairs are ignored (which isn't). 

Is this correct?

If so what other options are available which respect both ligatures and kerning, and can provide easy substitutes for the above functions in an MFC program?

Dave

[Apologies that I asked this earlier but it ended up on the wrong forum.]


David Webber Author of Mozart music notation software http://www.mozart.co.uk

A bug in MSVC 2013

$
0
0

Hi there.

I was trying out 2013 because of these new nice C++ features from new standart and that's what I found..

I experienced a nasty deadlock and I wasn't able to find a reason for quite some time..

It realy looks like in this case compiler does not call a destructor for a temporary variable, so it doesn't delete itself from debug iterator list in vector container. I made as small test as possible to make this problem to reproduce.

Problem exists only in Debug.

In example code you can comment "#define I_WANT_A_DEAD_LOCK" line to make code work. You can see that only this it make is writes

autotmpIt = (it + 5);

v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *tmpIt});

instead of just

v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *(it + 5)});

it makes compiler to call destructor for tmpIt...

whole code is

#include <vector>
#include <iostream>

#include <conio.h>

struct SomeNumbers
{
 std::vector<double> doubles_;
};

struct SumeNumbersWithOneMoreDoulbe
{
 SomeNumbers numbers_;
 double d;
};

#define I_WANT_A_DEAD_LOCK

int main ()
{
 std::vector<double> v1;
 std::vector<SomeNumbers> numbers;
 std::vector<SumeNumbersWithOneMoreDoulbe> v2;

 v1.resize (100);
 numbers.resize (10);

 auto numIt = numbers.begin ();

#ifdef I_WANT_A_DEAD_LOCK
 for (auto it = v1.begin (), itEnd = v1.end (); it != itEnd; it += 10, ++numIt)
 {
  v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *(it + 5)});
 }
#else
 for (auto it = v1.begin (), itEnd = v1.end (); it != itEnd; it += 10, ++numIt)
 {
  auto tmpIt = (it + 5);
  v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *tmpIt});
 }
#endif

 std::cout << "done";
 _getch ();
}

Restricting movement of modal dialog within its parent boundaries

$
0
0

Hello All,

I have created a new MFC application. The AboutDlg is modal dialog. I want to restrict the movement of AboutDlg to its parent region/boundary only. If the user drags/moves the window outside the parent rectangle boundaries then the AboutDlg should clip. Could you please assist with the approach to be followed to get this feature.

Thanks and Regards,

Hari

unwanted busy cursor when multi-threading

$
0
0

we would like to do time-consuming computing behind-scene with multi-threading(in my case, 4 threads are kicked off simultaneously, each thread is assigned to read one sheet in a large excel file), as soon as the application env is up. During this computing time we do not want the busy cursor to show up, as there is no need for this(this is the behind scene work user does not need to know). In the code, I have not explicitly set any busy cursor. however, the busy cursor displays automatically, until all 4 threads are complete. This is viwwed as a bug in our application as user sees this when he moves cusror over application toolbars area, and they don't understand what's going on.

 How to prevent this from happening?

Can IWbemServices ExecMethodAsync SetStatus return __ExtendedStatus instance when called in synchronous mode?

$
0
0

Hi,

I want to return an instance of the __ExtendedStatus call to the client code when they invoke a wmi provider implementing the IWbemServices interface (method ExecMethodAsync).  I have tried many different approaches but cannot seem to get the right way going.  So, I am now wondering if it is even possible to get an extended error object returned (see the last parameter of the SetStatus call) when called in synchronous mode.

In one of my attempts, on the client side, I can get the IWbemCallResult but when I get its __CLASS property, it is coming back as __PARAMETERS and I would have expected the object instance to be __ExtendedStatus (the object I passed into SetStatus). 

The provider is working as expected but I would now like to add the __ExtendedStatus to not only return error information if something goes wrong in the provider but to also send back to the client some simple performance data so they can understand the backend logic better.

Any advice or code samples would be greatly appreciated.  Thanks in advance! 


Anthony LaMark

how to write a text or images on icon?

$
0
0

Hi Guys,

I am using Visual studio 2008 VC++.

how to write a text or image on icon?

     example

         tortoise svn is showing some image on folder and files

         and

         skype is writing some text on tray icon where some notifications are there

like those how i make to my program icon on system tray and desktop icon as well

Thanks in Advance

Compiling code with VC++ 2013 on Windows Server

$
0
0
To my great dismay, MSFT no longer includes the compiler toolchain with the Windows SDK. My source code is currently held (along with all my other documents) on a SMB share hosted on Windows Server. I would like to be able to compile my source over a Powershell session from a Surface 2, but the share is on one computer, and the compiler (via Visual Studio 2013) is on another. These computers are not in a domain, so accessing the share from the computer with the compiler creates a double hop problem that I have yet to be able to resolve. Is there ANY way to get the Visual C++ 2013 compiler installed on a Windows Server 2008 r2 computer?

KeepMyIdentities, Your Key to Password Security. Available now on the Windows Store: http://apps.microsoft.com/webpdp/en-US/app/keepmyidentities/61a9f340-97ac-4666-beab-39f9246cb6fa


C++ console application running as a service application

$
0
0

Hi,

I have a C++ console application that creates an OPC Client which connect to an OPC server, read and write data. I'm using a Toolkits that contains library and ressources that I can call from my application. this application is working well.

Now I want to run it as a service application (on windows 7). I found some help in Internet and I added some code to convert it to a service application and installed the service. The sevice runs correctly when the application is modified to do some simple tasks like writing in a CSV file, but doesn't work when I try to create the OPC clinent and connect to the server.

I call my functions from the "ServiceWorkerThread" as follows:

DWORD WINAPI ServiceWorkerThread (LPVOID lpParam)

{

createOpcClient();

OpcClient* pClient = getOpcClient();

//  Periodically check if the service has been requested to stop

while(WaitForSingleObject(g_ServiceStopEvent, 0) != WAIT_OBJECT_0)

    {

       if(!SUCCEEDED(pClient->initialize()))

        {

            pClient->terminate();

            destroyOpcClient();

         }

            pClient->initializeDaObjects();

          pClient->readItem();

          Sleep(1000);

          pClient->writeSyncSubscription();

    }

return ERROR_SUCCESS;

}

All functions called exists in my cpp file "OpcCVlient.cpp" or in the Toolkit Library. the link to the Toolkit is done.

Thank you for any help

   

how to get Tabpage color using c#

Unable to retrieve system info using WMI in Windows 7

$
0
0

Using the example code provided here:

http://msdn.microsoft.com/en-us/library/aa390423.aspx

I have been able to retrieve hardware information using WMI on many versions of Windows (including Windows 7). 

The code is NOT working at all for one customer with Windows 7.

There do not seem to be any errors but the code does not yield any information.

Any suggestions or ideas ??

Thanks.

run time error 7

$
0
0

Hi,

I am working on MFC application that uses Datagrid.  I can build and launch the application without any problems.

while I am trying to edit the dialog box for datagrid, I am getting the out of memory error as a message box.

I am getting the error only in Visual studio 2012 but not in VC++6.0 

regards,

anju

How to shutdown selected program in MFC project with ? (Visual C++)

$
0
0

Hi,

I have been able to shutdown program which I selected in a textfield but I haven't found anything valuable about it on forums yet,

I'm asking if someone knows a much easier way.

Any methods are appreciated.

Thank you.


Viewing all 15302 articles
Browse latest View live


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