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

How to manually manage Task View features of Windows 10 in an MFC application?

$
0
0

Hello,

I'm working with a very old code base. For some weird reason I have to manually handle the Taskbar Thumbnail and Peek Preview/Live preview.  What I do is, create a bitmap of my application and use DWM ( DwmSetIconicLivePreviewBitmapDwmSetIconicThumbnail ) to use that bitmap.

For Windows 10, I've noticed that, there is a feature called task view (Win+Tab). I couldn't find any way to use my bitmap for that view using DWM.

Can anyone please guide me how to handle taskview scenario in windows 10? Is it actually possible to do with DWM? Or do I need something else here? Or is it really impossible to do manually?

Eagerly waiting for your kind replies.

Thanks in advance. 


Unable to compile project - inconsistent dll linkage

$
0
0

I decided (after many years) to re-compile my project using MFC as a shared DLL rather than statically.

I did a full rebuild and encountered several errors with inconsistent dll linkage. The class in question is defined in the header like this:

class AFX_EXT_CLASS CFileVersionInfo
{
}

How to compile?

How to determine whether MSVC++ 2015 redistributable (32- or 64-bit) is already installed?

$
0
0

Hello, all.

I am preparing an installer for an application which is build with C++ and requires that theMicrosoft Visual C++ 2015 redistributable is installed. Found several forum threads (thread #1, thread #2) that point to potential solutions but investigating further figured out that they are not persistent solutions across different subversions of the redistributable and moreover one cannot determine the bitness of the installed runtime. By saying different subversions of the redistributable I mean whether it is the initial version, update 1, 2 or 3 of the version 2015 redistributable. Is there any persistent way to check whether a given version and bitness of the C++ runtime is installed? The installer that I am preparing downloads the needed third-party components on demand and thus skipping the process of downloading the runtime and running it would save time. It is perfectly known that if the runtime is already installed and one tries to install it again in quiet mode it would just do nothing since it would detect if it is already installed or not. So, the installation won't be aborted if we try to install the runtime again but it is its integrated detection that I am aksing for.


"The pursuit of perfection ..."


How to update the string for the resouce ID on the fly?

$
0
0

The string for a resouce ID is obtained from string table. I want to update the string of the resource ID dynamically, e.g. the string can contain a recent filename, so that the filename can be included in the string of the resource ID.

Could you please let me know how to do it?

Thanks in advance.

TimeZoneInfo -> Summer time - Formatting into a string.

$
0
0

Hello,

I have a console application and want to format the time with daylight
saving time.

- Problem: +1 instead +2
- Why does string formatting not work?
I have no MFC application, then the string does not work?
How I can solve it?

/ ------------------ 
// My code


#include "pch.h"
#include <iostream>

#include "DateHelper.h"

#include "atlstr.h"

CString GetTimeZoneDifference()
{
TIME_ZONE_INFORMATION TimeZoneInfo;
GetTimeZoneInformation(&TimeZoneInfo);

CString strTimeZoneDifference2;
int testValue = 2;
strTimeZoneDifference2.Format(_T("%d", testValue));
printf("%d", testValue);

CString strTimeZoneDifference;
strTimeZoneDifference.Format(_T("%+03d:00", -1 * TimeZoneInfo.Bias
/ 60)); // -1* da Bias add to local time 

printf("%+03d:00", -1 * TimeZoneInfo.Bias / 60);


return strTimeZoneDifference;
}

int main()
{
std::cout << "Hello World!\n"; 


//COleDateTime time = COleDateTime::GetCurrentTime();
CDateHelper time = CDateHelper::GetCurrentTime();
CString strTimeBoard = time.Format("%Y-%m-%dT%H:%M:%S.00") +
GetTimeZoneDifference();

}

//h
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ATLComTime.h"
class CDateHelper : public COleDateTime
{
public:
CDateHelper();
CDateHelper(DATE);
CDateHelper(const COleDateTime&);
CDateHelper(int iYear, int iMonth, int iDay,
int iHour = 0, int iMinute = 0, int iSecond = 0);
CDateHelper(const CString&);

virtual ~CDateHelper() {}

const CDateHelper& operator=(COleDateTime dtSrc)
{
m_dt = dtSrc.m_dt;
return *this;
}
}




// CPP
CDateHelper::CDateHelper()
{
SetStatus(COleDateTime::null);
}

CDateHelper::CDateHelper(const COleDateTime& date)
: COleDateTime(date)
{}

CDateHelper::CDateHelper(DATE date)
: COleDateTime(date)
{}

CDateHelper::CDateHelper(int iYear, int iMonth, int iDay, int iHour, int
iMinute, int iSecond)
: COleDateTime(iYear, iMonth, iDay, iHour, iMinute, iSecond)
{}

CDateHelper::CDateHelper(const CString& str)
{
}
Regards Markus

VS2019 c++ simple console app throws Error MSB6006 "CL.exe" exited with code 2.

$
0
0

Hello I recently updated my VS from 2017 to 2019 and from now on I cant compile any c++ projects created by VS2019 it throws error: Error MSB6006 "CL.exe" exited with code 2. 

Code to reproduce error: 

int main()
{
  return 0;
}
First thing I done is repair VS because I though there is corruped file, but that didnt helped so I started messing with settings,

Changing Properties > C/C++ > Advanced > Compile As > to C code /TC app compiles and work, setting default or /Tp it throws again Error MSB6006 "CL.exe" exited with code 2., changing platform from x64 to x84 works too, but currently as I write it does not work anymore, already deleted bin and obj folders but it didnt help, also noticed that VS19 does not create any precompiled headers, if I copy paste settings and pre-header files it throws error that it unable to find myproject.pch files, I believe because of not set pre-headers its related that compiler throws error Error MSB6006 "CL.exe" exited with code 2. 

sort and low_bound callbacks parameters

$
0
0

I want sort list of strings, and next using low_bound to get range beginning at first letter, next I want search this range for letter at position=1, next 2,3 ...

My callback must have parameter (int pos).

Is posssible callback parameter or callback will be method or this number must be global variable (ugly!)

Application fails to run as Windows XP/7 compatibility mode on Windows10 machine

$
0
0

Hi,

What "Microsoft Visual C++ redistributables" do i need for running an application as Windows XP/7 compatibility mode on Windows 10 machine.

Thanks.


What is the proper hierarchy of parent and child window?

$
0
0

Hello,

Hope you guys are doing well. I'm working with a MFC project where I have to manage two window frame. Let one be the parent window, and another be the child window. The child window won't have any caption area or taskbar icon. What I want to achieve is that the child window should always be underneath the main window. I'd be grateful if someone can please guide me how to accomplish this. 

What is the proper way to create them? Does the child window positioned underneath the parent window initially? I guess it doesn't. If not, then how to change the Z order in the proper way with SetWindowPos()?

Waiting for your kind replies.

Thanks and regards.


Visual studio 2005 C++ project MIDL2039 warnings

$
0
0

Hi, 

I need help correcting the warnings below. I have pasted the code sections.

Thank you,

Priya

.\BladeAPI.idl(51) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'pData' of Procedure 'SetSensorGainRequestDx' ( Interface 'IBladeDiagnostics' ) ]
.\BladeAPI.idl(105) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'pKey' of Procedure 'InitializeBlade' ( Interface 'IBlade' ) ]
BladeAPI.idl file:
interface IBladeDiagnostics : IDispatch
{
    [id(14), helpstring("method SetSensorGainRequestDx")] HRESULT SetSensorGainRequestDx([in] SensorGainLevelData *pData);
....
}
interface IBlade : IDispatch
{
 [id(1), helpstring("method InitializeBlade")] HRESULT InitializeBlade([in] SAFEARRAY(BYTE) pKey,BladeAPIMode eMode);
....
}
BladeAPI.h file:
IBladeDiagnostics : public IDispatch
{
    public:
        virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetSensorGainRequestDx(
            /* [in] */ SensorGainLevelData __RPC_FAR *pData) = 0;
.....
}
IBlade : public IDispatch
    {
    public:
        virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE InitializeBlade(
            /* [in] */ SAFEARRAY __RPC_FAR * pKey,
            BladeAPIMode eMode) = 0;
 

Weird math problem with VS2015

$
0
0

Hello , So i will just get to it .

I was trying to do this 

DWORD Value1 =7cb1d74f ;

Value1 = Value1  *-1 ;

the answer should be 834e28b0 , But in debugger its showing result as 834e28b1 .

Is there something im not getting ?  

I tried using singed int , no change .

Syntax Error in the provided windns.h when attempting to migrate from an older VC++

$
0
0

Hello,

As I mentioned in the title, I am working on migrating an old project, that was last built using Visual C++ 6. I am trying to build using the Windows XP compatibility, and have largely been finding success with updating the code where necessary. However, I'm at a point now where I am getting the following errors:

c:\program files (x86)\microsoft sdks\windows\v7.1a\include\windns.h(1451): error C2059: syntax error: ','

c:\program files (x86)\microsoft sdks\windows\v7.1a\include\windns.h(1544): error C2059: syntax error: ','


This occurs during the compilation of multiple files, but not all. The windns.h I am using has not been modified at all from when it was installed.

Any suggestions? 
Thanks!




WM_MOUSEMOVE continually fired without moving mouse (1903 windows update)

$
0
0

After 1903 update i get spurious WM_MOUSEMOVE msg.

Problem that i cant recive WM_TIMER from my setTimer callback when mouse not moving.

TickHandle=SetTimer(FindWindowA(NULL,"Test"),1,100,(TIMERPROC)TimerProc)

Only when mouse is not move!!! any action or disale vsync (fps > 100) and WM_TIMER msg start to go.

Spy++ (mouse idle):

https://i.imgur.com/Ru5cMkZ.png - 1903 version

https://i.imgur.com/oVPb9hg.png - 1806 version


From the VC++ client how to call and consume a WCF service?

$
0
0

Hello All,

My existing application is in VC++. And from this VC++ client, I need to call service.

I know that we can use XML Web Services using SOAP Toolkit.

I never involved in any services related development. So wanted to know is there any other service (apart from webservice) that we can implement to call from the VC++ client.

Can we use WCF or Java service from the VC++ client?

If it is possible, can anyone please provide information to use WCF or Java service? 

And also which service is more popularly using now a days?

Regards,

Prakash


Y A S Prakash

Why I cannot reuse CMemFile?

$
0
0

Hi,

In the following codes, I try to reuse CMemFile by detaching the buffer and re-attache the buffer:

    CMemFile MemFile;
    CArchive Archive(&MemFile, CArchive::store);
    CString strLine, strOutput;
    UINT uSize;
    BYTE* lpBuf;

    for (UINT nIndex = 0; nIndex < 500; nIndex ++)
    {
        //  Reset the file to empty
        MemFile.SetLength(0);

        strLine.Format(_T("This is line %u."), nIndex);

        Archive.WriteString(strLine);

        Archive.Flush();

        //  Get the data out of the memory file
        uSize = MemFile.GetLength();
        lpBuf = MemFile.Detach();

        strOutput = CString((LPCTSTR)lpBuf, uSize / sizeof(TCHAR));

        TRACE(_T("%s\r\n"), strOutput);

        //  Re-attach the buffer so that we can reuse the memory file
        MemFile.Attach(lpBuf, uSize, 1024);
    }

However, the output is multiple "This is line 0", as below:

This is line 0.
This is line 0.
This is line 0.
...

Why?


Opening keys in HKEY_CLASSES_ROOT

$
0
0
I am trying to open a registry node under HKEY_CLASSES_ROOT from my V++ app. I am getting error but error code is zero. Is there any restrictions for accessing keys under HKEY_CLASSES_ROOT?

Cannot open file 'mfc100.lib'. I'm getting this error when I try to build project in Visual Studio 2017.

$
0
0

I'm migrating my project from VS2010 to VS2017. When I trying to build my project I'm getting error, LNK1104 Cannot open file 'mfc100.lib'. 

My project's Platform ToolSet is set toVisual Studio 2017(v141)

I set Use of MFC to Use MFC in a Shared DLL

Please help me find out a proper solution to fix this. 

Thanks in advance.  

DLL fails to load if unused ref class is removed

$
0
0

I'm running into a very strange problem trying to compile and use a windows runtime component within an UWP application (VS2017 community 15.9.13 with NetCore.UniversalWindowsPlatform 6.2.8, compiled without /clr but with /ZW).

It is basically something like the GrayscaleTransform found in the UWP samples. The runtime component is actually working as expected, now I wanted to remove some unused code. However, as soon as I remove it from a particular file and recompile, it indeed compiles, links, but the DLL does not load any more.

Here's some example code that I have to put in:

ref class DummyU sealed {
  public:	DummyU() {}
};
DummyU^ CreateDummyU() {	
  return ref new DummyU();
}

The code just makes it work, although it is a) not referenced at all and b) does not do anything useful. 

The result of removing it:

Exception thrown at 0x0EFF322F (vccorlib140d_app.dll) in TestAppUWP.exe: 0xC0000005: Access violation reading location 0x00000000.


in

STDAPI DllGetActivationFactory(_In_ HSTRING activatibleClassId, _Deref_out_ IActivationFactory** ppFactory) {
	return Platform::Details::GetActivationFactory(Microsoft::WRL::Details::ModuleBase::module_, activatibleClassId, ppFactory);
}


function in dllexports.cpp which is part of VS. The module_ becomesNULL.

Does anyone have an idea if there are any known bugs with respect to the windows runtime not being initialized/used properly if there is no explicit instantiation of a ref class in a file?

VC++ 2019 (64Bit) Loading DLL built from Labview 2017 64Bit.

$
0
0

Hi,

I am struggling to figure out how to use a DLL that I have created in Labview 2017 (64 bit). I have created a minimal DLL and VC++ code base to share here to hopefully find a solution to the error with the DLL not loading (the error is described below). The DLL (and others I have made) work fine when I use them with MatLab 2015b. But VC++ is just not working for me!

I am using Visual Studio 2019 C++ and took the following steps to create the simple project:

  • I started with an Empty c++ project.
  • Changed the Linker>System>SubSystem from blank to: Windows (/SUBSYSTEM:WINDOWS)
  • Changed the Linker>Advanced>Entry Point from blank to: main
  • Right-Clicked on the project to choose Add>New Item. 
  • Then chose "Visual C++">UI>Windows Form (Creating MyForm).
  • Added the main(..) function to the MyForm.cpp
  • A text field is added to the form (InputField)
  • A second text field is added to the form (OutputField)
  • A Button is added to the form (Button1)
  • Double click on the new Button to automatically create the event: Button1_click(...)" at the bottom of MyForm.h
  • The code for the Button1_click() is show below.
  • I have tried adding the path of the DLL/LIB/h files to the Properties>VC++ directories (Include and Library Directories) but it made no difference. All those files are located next to the project and other source files anyhow.

The Error I receive when I Build is LNK2028, LNK2019, and LNK1120 (see the image below)

Error	LNK2028	unresolved token (0A000008) "extern "C" double __cdecl MyIncrement(double)" (?MyIncrement@@$$J0YANN@Z) referenced in function "private: void __clrcall MyTestApp::MyForm::Button1_Click(class System::Object ^,class System::EventArgs ^)" (?Button1_Click@MyForm@MyTestApp@@$$FAE$AAMXPE$AAVObject@System@@PE$AAVEventArgs@4@@Z)	MyTestApp	C:\Users\kane\source\repos\MyTestApp\MyForm.obj	1	
Error	LNK2019	unresolved external symbol "extern "C" double __cdecl MyIncrement(double)" (?MyIncrement@@$$J0YANN@Z) referenced in function "private: void __clrcall MyTestApp::MyForm::Button1_Click(class System::Object ^,class System::EventArgs ^)" (?Button1_Click@MyForm@MyTestApp@@$$FAE$AAMXPE$AAVObject@System@@PE$AAVEventArgs@4@@Z)	MyTestApp	C:\Users\kane\source\repos\MyTestApp\MyForm.obj	1	
Error	LNK1120	2 unresolved externals	MyTestApp	C:\Users\kane\source\repos\MyTestApp\x64\Debug\MyTestApp.exe	1	

The MyForm.h header consists of:

#pragma once
#include "MySimpleTest.h"" //DLL Header

namespace MyTestApp {
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

/*...
and so on and so on... standard form items etc. Below, 
Button1_Click(...) is the peice of code that calls the 
DLL function "double MyIncrement(double)" when the
Button1 is pressed. The function Reads value from the
InputField, Increments the value, and writes it to the 
OutputField. That is all! To activate the DLL call, 
set the #define UseDLLCall to true (but will cause an error).
...*/

private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
   double a,b;
   /*CHANGING THE LINE BELOW TO true CAUSES COMPILE ERRORS*/
   #define UseDLLCall false
   a = System::Convert::ToInt32((InputField->Text));
#if UseDLLCall
   // Use the DLL to do the Increment: NOTE, this results in
   // the error I can not resolve!!!!!!
   b = MyIncrement(a); //This is the DLL Call
#else
   // Do the increment maths without the DLL.
   b = a + 1;
#endif
   OutputField->Text = System::Convert::ToString(b);
}
};
}

The MyForm.cpp is:

#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;

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

The DLL files ... 
  MySimpleTest.dll
  MySimpleTest.lib
  MySimpleTest.h
... are all together inside the VC++ project folder, along with the files ...
  MyForm.h
  MyForm.cpp
  MyTestApp.h
  MyTestApp.sln
  MyTestApp.vcxproj

The DLL Header MySimpleTest.h is:

#ifdef __cplusplus
extern "C" {
#endif

// The DLL call "MyIncrement() simply returns "Input + 1".
double __stdcall MyIncrement(double Input);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
void __cdecl SetExcursionFreeExecutionSetting(long value);

#ifdef __cplusplus
} // extern "C"
#endif

Does anyone know what the problem is? Many thanks in advance!

The project and source can be downloaded from here:

(It won't let me post a link)

Kind regards,

Kane.


undefined GetForegroundWindow() or VS unable to find user32.lib

$
0
0

Hello I trying to include user32.lib in my project(c++ application) but seems it does not work, I have included 

#include <windows.h>
//other includes


#pragma comment(lib, "user32.lib")

But it still shows GetForegroundWindow as undefined.

Tried to set property > linker > Input > Additional Dependencies:

user32.lib;
WindowsApp.lib;
$(OutDir)GameAssembly.lib;
d3d9.lib;
kernel32.lib;
gdi32.lib;
winspool.lib;
comdlg32.lib;
advapi32.lib;
shell32.lib;
ole32.lib;
oleaut32.lib;
uuid.lib;
odbc32.lib;
odbccp32.lib;
%(AdditionalDependencies)

But still shows as GetForegroundWindow undefined, current VS using is VS2019 with all C++ and Win SDK installed,

In path: C:\Program Files (x86)\Windows Kits\10\Lib user32.lib exist in diffrent windows versions folders, what I'm missing here? Thanks.


Viewing all 15302 articles
Browse latest View live


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