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

CMFCListctrl Sorting

$
0
0

Hi,

As per this link https://www.codeproject.com/articles/27774/clistctrl-and-sorting-rows,  in CListCtrl, if we call below lines in the oncolumnclick() event of clistctrl I am getting sort arrow image in the top center of the header. If I call similar code in the columnclick for CMFCListCtrl I am getting sort arrow at the right of the column header only not at the center.

#if (_WIN32_WINNT >= 0x501)
for(int i = 0; i < GetHeaderCtrl()->GetItemCount(); ++i)
{
HDITEM hditem = {0};
hditem.mask = HDI_FORMAT;
VERIFY( GetHeaderCtrl()->GetItem( i, &hditem ) );
hditem.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
if (i == colIndex)
{
hditem.fmt |= ascending ? HDF_SORTDOWN : HDF_SORTUP;
}
VERIFY( CListCtrl::GetHeaderCtrl()->SetItem( i, &hditem ) );
}
#endif



CMFCListCtrl

How to get sort arrow image at the top center of column header in the CMFCListCtrl?




CMFCListctrl OnCompareItems

$
0
0

Hi,

Can I use CMFCListctrl's  OnCompareItems function with owner data list control for sorting?

Thanks.

LNK1104 cannot open file ...../myproj.lib

$
0
0

I have multiple C++ projects within a solution. One of the projects is a DLL project (it is set in configs) and I want to test it.

For that I need to include it in my Tests google test project somehow. I managed to include to the VC++ directories so I can use the DLL project and intellisense works.

However I cannot build my test project because the linker fails with the error message in the title.

The myproj is a DLL project. How is it supposed to have a .lib export? How could I import that DLL project in another project then?


asd

Unable to create Bitmap image Using CreateDIBSection function

$
0
0

We are trying to create a bitmap image using CreateDIBSection function with respective to width=211808 and height=84053 with DPI(96) which returns NULL value without any log information, when I was trying with Width=33284 and height=13208 With DPI(96) I was able to generate the bitmap image. Do we have any limitation value for the width and height to generate the bitmap? If so, do we have any documented file?

simultaneous use of cameras in winrt

$
0
0

Hi everyone!

I would like to know how to simultaneously use Color and Infrared cameras in c++ winrt. Currently i using following code to get MediaCapture of one camera:

auto groups = co_await MediaFrameSourceGroup::FindAllAsync();
MediaFrameSourceGroup group = nullptr;
for (const auto& g : groups)
	if (g.DisplayName() == "CameraName") 
		group = g;

MediaCapture mediaCapture;
MediaCaptureInitializationSettings mediaCaptureInitializationSettings;
mediaCaptureInitializationSettings.SourceGroup(group);
mediaCaptureInitializationSettings.SharingMode(MediaCaptureSharingMode::SharedReadOnly);
mediaCaptureInitializationSettings.StreamingCaptureMode(StreamingCaptureMode::Video);
mediaCaptureInitializationSettings.MemoryPreference(MediaCaptureMemoryPreference::Cpu);
co_await mediaCapture.InitializeAsync(settings);

According to this:

https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/capture-from-multiple-sources-simultaneously

it is possible in C# UWP

How to change PolicySet parameter of MSFT_NetQosFlowControlSettingData instance using WMI and C++

$
0
0

Hi,

I`m trying to write analog of powershell command using C++ and WMI infrastructure

Set-NetQosFlowControl -Priority 3 -Enabled $true -InterfaceAlias "Ethernet 4"


The tricky part is the last parameter and how to set it

-InterfaceAlias "Ethernet 4"

I tried multiple approaches but none of them worked:

1) a) Enumerate on MSFT_NetQosFlowControlSettingData class instances
    b) Modify Enabled, InterfaceAlias, InterfaceIndex and PolicySet properties
    c) Apply changes

2) a) GetObject directly using \\.\ROOT\StandardCimv2:MSFT_NetQosFlowControlSettingData.InstanceID="Priority3" path
    b) Modify Enabled, InterfaceAlias, InterfaceIndex and PolicySet properties
    c) Apply changes

3) a) GetObject using MSFT_NetQosFlowControlSettingData 
      b) Spawn instance of this class      c)Modify Enabled, InterfaceAlias, InterfaceIndex and PolicySet properties      d) Apply changes

All function calls success, but as the result I get Priority 3 enalbed for Global PolicySet and not for AdapterSpecific PolicySet:

Get-NetQosFlowControl
Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      Global
1          False      Global
2          False      Global
3          True       Global
4          False      Global
5          False      Global
6          False      Global
7          False      Global
Get-NetQosFlowControl -InterfaceAlias "Ethernet 4"


Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      AdapterSpecific  16      Ethernet 4
1          False      AdapterSpecific  16      Ethernet 4
2          False      AdapterSpecific  16      Ethernet 4
3          False      AdapterSpecific  16      Ethernet 4
4          False      AdapterSpecific  16      Ethernet 4
5          False      AdapterSpecific  16      Ethernet 4
6          False      AdapterSpecific  16      Ethernet 4
7          False      AdapterSpecific  16      Ethernet 4


If I use powershell commands for configuration I get the expected result:

Set-NetQosFlowControl -Priority 3 -Enabled $true -InterfaceAlias "Ethernet 4"
Get-NetQosFlowControl

Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      Global
1          False      Global
2          False      Global
3          False      Global
4          False      Global
5          False      Global
6          False      Global
7          False      Global

Get-NetQosFlowControl -InterfaceAlias "Ethernet 4"

Priority   Enabled    PolicySet        IfIndex IfAlias
--------   -------    ---------        ------- -------
0          False      AdapterSpecific  16      Ethernet 4
1          False      AdapterSpecific  16      Ethernet 4
2          False      AdapterSpecific  16      Ethernet 4
3          True       AdapterSpecific  16      Ethernet 4
4          False      AdapterSpecific  16      Ethernet 4
5          False      AdapterSpecific  16      Ethernet 4
6          False      AdapterSpecific  16      Ethernet 4
7          False      AdapterSpecific  16      Ethernet 4

Could someone help me, or advice some different approaches?

Thanks,
Alexander


Opening Control Panel applet

$
0
0

Below is some code to open the control panel or one of its applets.  TCError() is a wrapper for FormatMessage().

When (*szArg == 0) it will open the control panel on both Windows 7 and Windows 10.  When (*szArg != 0) and szItemName is a valid name (e.g., L"Microsoft.System") it will open the applet on Windows 7.  On Windows 10, IOpenControlPanel::Open fails with ERROR_ACCESS_DENIED.  I am an administrator on both test machines.

What's up?  Thanks.  [I would have started in a Win10 or security forum, but my own code is the only way I can produce the problem.]

CoInitialize(NULL);
IOpenControlPanel *pPanel = NULL; 
HRESULT hr = CoCreateInstance(CLSID_OpenControlPanel, NULL, CLSCTX_INPROC_SERVER, IID_IOpenControlPanel, (LPVOID*) &pPanel);
if ( SUCCEEDED(hr) )
{
	hr = pPanel->Open(*szArg == 0 ? NULL : szItemName, NULL, NULL);
	if ( hr != S_OK )
	{
		TCError(hr & 0xFFFF, L"IOpenControlPanel::Open");
	}
	pPanel->Release();
}
CoUninitialize();

Fatal Error C1010 still exists when i set to Not Using Precompiled Headers

$
0
0
What else may generate this error?

Accessing managed code from native C++ application

$
0
0
I am not sure if this is the correct forum to ask this question. I have an existing C# library whose methods I need to access from my existing native C++ application. That is I need to instantiate the .Net classes from C++ and call its methods. I found some methods where the .Net methods are exposed using extern C and accessed from outside . Could someone please tell a method I can accomplish this without changing any settings of my native C++ app?

c++ add element xml file

$
0
0

Hi 

I'm writing a program to create an xml file through a ghraphic interface

I got to create my file and the elements but in the case of the modification to add a new element in a file already existing I found a problem

there is my code to creat the file  

any help please? think you 

public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
	{
		if (SavePath == "")
		{
			XmlWriter ^writer;
			OPENFILENAME ofn;
			char szFileName[100] = "";
			ZeroMemory(&ofn, sizeof(ofn));
			ofn.lStructSize = sizeof(ofn);
			ofn.lpstrFilter = "xml Files (*.xml)\0*.xml\0All Files (*.*)\0*.*\0";
			ofn.lpstrFile = szFileName;
			ofn.nMaxFile = 100;
			ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
			ofn.lpstrDefExt = "xml";
			XmlWriterSettings ^settings = gcnew XmlWriterSettings();
			String^ path = "";
			if (GetSaveFileName(&ofn))
			{
				XmlWriterSettings ^settings = gcnew XmlWriterSettings();
				settings->Indent = true;
				settings->IndentChars = ("   ");
				settings->NewLineOnAttributes = true;
				path = gcnew String(szFileName);


			}

			writer = XmlWriter::Create(path, settings);
			SavePath = path;

			try
			{
			writer->WriteStartDocument();
			writer->WriteStartElement(textBox2->Text);
			writer->WriteStartElement(balise);
			writer->WriteString(textBox1->Text);
			writer->WriteEndElement();
			writer->WriteEndDocument();
			writer->Flush();
			writer->Close();
		     }
			catch (Exception ^e)
			{
				Console::WriteLine("XML Writer Aborted -- {0}", e->Message);
			}
			finally
			{
				if (writer->WriteState != WriteState::Closed)
				{
					writer->Close();
				}
			}

		}
		else if (SavePath!="") // add new element 
		{
		int a = 0;
		XmlTextReader^ reader = gcnew XmlTextReader(SavePath);
		while (reader->Read())
		{
			// here i must to write the code to add new element 
		}

	}



Where are the phc.h library for C++ Can not find when compiling from Wolfram Mathematica

$
0
0

I am learning C++ from VIsual studio .I amfollowing tutorials available online and from text from library.  C++ in 24 hours..etc..

After a recent update, I notice that allthe C++  console applications hace a directive #include "phc.h"  .  What troubles me is where this file is located and what is its purpose.

I am using a shell from Wolfram Mathematica to execute the core. WM uses the Visual Studio 14 compiler.  BUt it fails because it does not find the location of phc.h file. Where is this file located andwhy it is not inside an /include folder ?

ProgressBar Vertical

$
0
0
Hello
I have a question how to do a vertical progress bar in visual studio 17 CLI / UI C ++ I searched the forum and hard to match anything to c ++ everything I found is on the vb The sea is some ready solution? Thank you in advance for your best regards

How to auto start a program after logon in safe mode

$
0
0

I added a value

manager "C:\Program Files\mytest\manager.exe"

under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

it works fine in normal mode.

but if I login windows with safe mode, it doesn't work.

I searched some information on internet, some people says:

Run - These are the most common startup locations for programs to install auto start from. By default these keys are not executed in Safe mode. If you prefix the value of these keys with an asterisk, *, it will run in Safe Mode.

then, I renamed my value name to "*manager", like:

*manager "C:\Program Files\mytest\manager.exe"

but, it still doesn't work.

can anybody help me?

my os is: windows 7 32bit.

How to prevent VC++ compiler from re-using local variable stack space

$
0
0

I have encountered a bug in which the VC++2017 compiled the code wrong. What I am now struggling with is how to work around it to prevent the compiler from making this mistake. It appears that the compiler "deduces" that a local early in the function is no longer used, so that it can reuse that stack space for local that is used later. The deduction is flawed, because the code stored an address to that data. So my question is whether there is any way to tell the optimizing compiler that it can't re-use the stack space used by that variable?

To illustrate the issue, I'll show the relevant lines of the code here -- all in the same function:

vector<DataSorter*> sorters(n);
...
DataSorter heightSorter(...);
...
sorters[1] = &heightSorter;
...
Pen pen(Color::Black);  
...
sorters[1]->Sort(...);


The disassembly for the 2nd line shows that the compiler positioned heightSorter at address [rbp+0E8h]:

DataSorter heightSorter(gr, absHeightKeys, 2);
000000014040D111  mov         dword ptr [rbp+0E8h],2   // size_ is first member in DataSorter
000000014040D11B  lea         rdi,[rbp+210h]  
000000014040D122  mov         qword ptr [rbp+0F0h],rdi  
000000014040D129  mov         qword ptr [rbp+0F8h],rsi  

The key info is the 1st disassembly line which shows us where the compiler located heighSorter on the stack.

Later the Pen constructor is in-lined. The inline'd code is 

    Pen(IN const Color& color, 
        IN REAL width = 1.0f)
    {
        Unit unit = UnitWorld;
        nativePen = NULL;
        lastResult = DllExports::GdipCreatePen1(color.GetValue(),
                                    width, unit, &nativePen);
    }

which the following disassembly (my annotations):

000000014040DCB3  xor         ebx,ebx                      // nativePen=NULL
000000014040DCB5  mov         qword ptr [rbp+0E8h],rbx  
000000014040DCBC  lea         r9,[rbp+0E8h]            // &nativePen
000000014040DCC3  xor         r8d,r8d                      // unit = UnitWorld
000000014040DCC6  movss       xmm1,dword ptr [__real@3f800000 (0140B7CBE8h)]  
000000014040DCCE  mov         ecx,0FF000000h       // color = Color::Black
000000014040DCD3  call        qword ptr [__imp_GdipCreatePen1 (0140A2CC30h)]  
000000014040DCD9  mov         dword ptr [rbp+0F0h],eax  


Here the 3rd line reveals that the compiler has located Pen at location [rbp+0E8h] -- the same location used for heightSorter earlier. This clobbers the contents of heightSorter, so that when the 5th line is executed, it gets and access violation.

After the 3rd line (sorters[1] = &heightSorter), the name heightSorter is not used again, so my conjecture is that the compiler concluded that the stack space used by that variable can now be reused. But because the code used its address, that assumption was flawed. This address is only used in this same function, this isn't a case of returning an address from the stack, which is obviously flawed. 

I've left out lots of logic -- the function in question is very long (yes, too long in IMHO). There is logic in there that selects which sorters get used in the specific situation, so although I extracted the relevant part, there is a higher logic to what it is doing.

I know it would be great to isolate this into a bug report. Easier said that done, but perhaps something I'll eventually be able to do. Right now, I am just looking for a work around.

So to emphasize, the question is: Is there a way to tell the compiler that it cannot reuse the space for a local variable on the stack for another variable after it thinks the first variable is no longer used?   VC++2017 compiler with /std:c++17

Thanks!

click location within MFC Picture control

$
0
0

I have a picture control in my dialog box, showing some image.

I need to detect the click location within thisMFC picture control (IDC_STATIC_BITMAP).

How do I do that?

Thank you.

 

using __mm_aeskeygenassist with MS VC++ 2017

$
0
0

Shown below is a short program that compiles and executes bout does not provide the correct answer.

Any suggestion or comment to fix it is appreciated.

Surry

//aes_key.cpp

#include<wmmintrin.h>

#include<iostream>

#include<stdio.h>

int main() {

int x;

__m128i K0,K11;

//sample key = 54 68 61 74 73 20 6D 79 20 4B 75 6E 67 20 46 75

K0.m128i_u64[1] = 0x204B756E67204675;

K0.m128i_u64[0] = 0x5468617473206D79;

K11.m128i_u64[1] = 0xB159E4E6D679A293;

K11.m128i_u64[0] = 0xE232FCF191129188;

__m128i K1 = _mm_aeskeygenassist_si128(K0, 0);

printf_s("        Key: 0x%016I64x%016I64x\n",//  original key

K0.m128i_u64[0], K0.m128i_u64[1]);

printf_s("         K0: 0x%016I64x%016I64x\n",//K0 = Original key

K0.m128i_u64[0], K0.m128i_u64[1]);

printf_s("         K1: 0x%016I64x%016I64x\n",//Computed K!

K1.m128i_u64[0], K1.m128i_u64[1]);

printf_s("Expected K1: 0x%016I64x%016I64x\n",//Expected K1

K11.m128i_u64[0], K11.m128i_u64[1]);

std::cin >> x;  //view screen output

return 0;

}//end aes_>key()

//Screen Output

//  Key: 0x5468617473206d79204b756e67204675

//K0 : 0x5468617473206d79204b756e67204675

//K1 : 0x922045ef2045ef929fb7b39db7b39d9f

//Expected K1 : 0xe232fcf191129188b159e4e6d679a293

Copy AS Html, where I can find it for MS VS 2015 ?

$
0
0

Hello,

can someone tell me where I can find CopyAsHtml gadged for MS VS 2015 up3 ?

Many thanks.

Jerry

Including Windows or MFC structures in my class

$
0
0

I get the following error when trying to define members with Windows (POINT) structures or MFC (CPoint) classes in my own class. Are they defined in a namespace or or bounded in a macro definition?

//START FILE (MyClass.h)

class MyClass
{

//my members...
private:
    CPoint m_ptOrigin;
//continue...

}

//END FILE


//START FILE (MyClass.cpp)
#include <stdafx.h>

#include "MyClass.h"

//...

//END FILE

error C3646: 'm_ptOrigin': unknown override specifier

 

The Project is an MFC project and the stdafx.h seems to have all the relevant headers etc.

Get IP address(es) of active directory user object

$
0
0
Is there any way to find active directory computer objects from which active directory user is logged, so that I can find IP of that active directory user?
I am using VC++

Active Directory | COM | VC++ | LDAP


Is it possible to generate a Type Library from a C++ header file?

$
0
0

Hi,

 

This is my first post in this forum, I hope it won't be the last Smile

 

I have recently started working in a project in which we need to re-implement a COM component with .NET . The problem is that the project involves a client of this COM component that is not .NET aware and that is maintained by an external vendor, hence we don't have control over it. This client component is implemented with COM.

 

This scenario requires implementing a .NET component that is binary compatible with the COM client.

 

As far as I have investigated, I need to get an Interop Assembly. Since the COM client vendor does not provide us with a Primary Interop Assembly, it is necessary to build my own Interop Assembly. Running the tlbimp.exe tool on the provided VENDOR.DLL returns TI0000 error code (not a valid type library). I guess there is not type information in that .DLL.


I've tried generating the Type Library from the header files provided by our vendor in two different ways (I’m using MS Visual Studio 2005):

  • Using the midl.exe tool (raises compilation errors)
  • Building a COM component that implements the interfaces defined in the header files and importing the result in a .NET project (again TI0000 not a valid type library error)

My questions are: is it possible to instruct Visual Studio 2005 to generate a Type Library from a COM project? Does anyone have knowledge about different solutions?

 

Thanks in advance,

 

Guillermo

 

Viewing all 15302 articles
Browse latest View live


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