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

Online compiler collection using various Visual C++ toolkit versions?

$
0
0

Dear Visual Studio experts,

are you aware of an online compiling tool where I could test some #ifdef magic aimed at supporting various MSVC toolkits? (ideally from v90 to v14x included...) ? I'd like to avoid the hassle of setting up a VM, installing tools... I just need to test a simple TU with some static tests. Compiling is enough, I do not need to link or execute (barring code generation bugs).

I know about _MSC_VER_MSC_FULL_VER__cplusplus , _MSVC_LANG and /Zc, but I'd like to test my feature flag detection before pushing my changes into the wild (it's indeed quite scary looking, when taking into account GCC and clang support, and I might want to add support for other compilers in the near future)

I already know about Compiler Explorer but it only goes as far as v140, and I am precisely concerned by the v90/v100 era.

Thanks in advance!


How to compare two files line by line after storing them in vector

$
0
0

i have two text files named totalfiles.txt and uploaded.txt i am storing both of them in a vector now offcourse when this program will run for a very first time uploaded.txt will be made and it will be empty and first file will be written in it after its successfully uploaded to the server what i want is some kind of method to compare both .txt files so if files that are already uploaded to server don't get uploaded again so is there any method to do that in c++? again at the beginning i am going to store the files in vector and i need to do above operation via vector and not using .txt files directly with fstream

ifstream read2("ScannedFiles.txt");
ofstream read3("Problem.txt", ios::app);
fstream uploaded("Uploaded.txt", ios::app);
vector<string>filen2;
vector<string>upl;
string st3;
string st2;
while (getline(read2, st2))
{
if (st2.size() > 0)
filen2.push_back(st2);
else
break;

}
while (getline(uploaded,st3))
{
if (st3.size() > 0)
upl.push_back(st3);
else
break;
}
<pre>for (vector<string>::iterator t = filen2.begin(); t != filen2.end(); t++)

Image file not showing when trying to open from resources c++

$
0
0

i have a code in c++ on visual studio 2015 an empty project in which i added a bitmap resource(a jpeg pic) now i am trying to open it from main using i have also include #include"resource.h" but its not opening the file what might be the reason?

can't i simply open it and show it in windows builtin photo viewer?

fstream file;

file.open("55f49fda-4db6-4c41-93d2-0311695e3cf8_5.jpg");

How to create Console Applications by using pure C-Language

$
0
0
I like to use Visual Studio 2019 Community for pure C-Programming on my Windows 10 PC. That ist allegedly possible by naming a source file xxx.c instead of xxx.cpp. But at the end the Microsoft Windows Security recognizes the produced xxx.exe as a Trojaner (Win32/Ludicrouz.Z).
Do I made something wrong - please inform me how I can program pure C-Progams (C99 or later) with Visual Studio 2019.
Thank you in advance.

c++/cli and create WPF UserControl without STA thread apartment (help)

$
0
0

I have c++ dll project where WPF UserControl (as DLL) is used for GUI.

I simply working with UserControl created in C# project inside C++/CLI

controls = gcnew uc_control();

The problem is, when project is compiled, it throw this error:

Unhandled Exception: System.InvalidOperationException: The calling thread must be STA, because many UI components require this.

this error cause code above.

The interesting part is, when project is run under validator (validator is not created by me) then error is occurred. But when project is run under host application, everything is working, without any error.

question is, Where should be problem? Should I use another thread with STA enabled? Is it ok create UserControl or any other C# object from WPF without STA thread?

Btw. I dont use application framework (App.xaml) in dll.


UMDF Detect Display State (On/Dim/Off) from System Reboot/Restart Events

$
0
0

Using PowerSettingRegisterNotification, I was able to listen to Display States on the following System Power Events (using GUID_CONSOLE_DISPLAY_STATE as SettingGUID):

  • System Shutdown
  • Sleep
  • Hibernate
  • User Idle (Turn screen off after n-minutes)

What I was not able to receive a Display State from is when a system restart is performed. My Power Setting Notify Callback was not called, neither from Display State Off before restart, nor Display State On after restarting.

Is this a normal behavior? Or should I be listening to another event, specifically to handle this kind of scenario?

I also tried GUID_MONITOR_POWER_ON as my SettingGUID, the same behavior was produced.

I also tried usingEvtWdfDeviceD0Exit for that, with WdfPowerDeviceD3Final as WDF_POWER_DEVICE_STATE. The driver was not notified of such exit from D0 during system restart or system shutdown. I also tried the other states, the only D0 Exit event the driver received was from WdfPowerDevicePrepareForHibernation for pre-hibernation.

Visual Studio Debugger: Cannot find or open the PDB file

$
0
0

Tools-> Options-> Debugging-> Symbols. Select checkbox "Microsoft Symbol Servers". Visual Studio will download PDBs automatically.

When starting a program under the Microsoft Visual Studio 2017 *debugger, you will generally see in the Output pane a series of messages similar to the following:

'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'dpiTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.

Before, the symbol fille can be successfully loaded;

but recentlly the symbols can not be found ?

open Debug-> windows-> moduels  dialog,  download pdb file, the "no symbols found: browse for ***.pdb" dialog popup;

so how to fix it?


DLL Missing MSVCP140D With registry Key

$
0
0

Hy

I have build a application  with visual studio 2019 and MFC . I write a key to lunch automaticly my application at users start

"Software\\Microsoft\\Windows\\CurrentVersion\\Run". It's ok. When users start the application try to start and i have the message "File missing MSVCP140D.dll". So i have modified my program to see where i lunch my application. I found "c:\windows\system32". So MSVCP140D it's not in "c:\windows\system32". I don't know how solved this problem. Do have an idea?

Thanks

Jean Bezet


How to delete a file from my Desktop using c++

$
0
0
 

I'm trying to delete a file from my desktop. Any help would be appreciated.

  const int result = remove("C:\\Users\\user1\OneDrive\Desktop\file1.exe");
    if (result == 0)
    {
        cout << "\nsuccess" << endl;
    }
    else
    {
        cout << "\nNo success" << endl;
    }



StudiousStudent


How to delete a running exe file from the Windows Registry?

$
0
0

I'm writing a small programme to list all the strings in the run key and delete one of the keys and the file. I can delete the string value (Can be seen from the Registry Editor) however I can't delete the file if it's running. Any help would be appreciated.

HKEY hk; DWORD ValuesNumber; // Number of values in the run key DWORD MaxValueNameLen; DWORD MaxValueDataLen; DWORD valueNameLen; DWORD dataLen; TCHAR valueName[28], valuePath[MAX_PATH]; TCHAR NameToFind[] = TEXT("FileR"); // file string value in the Run key //------------------------ Opening the Run Key -----------------------// RegOpenKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),&hk); //--------------------------- Get The Key----------------------------// RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &ValuesNumber,&MaxValueNameLen,&MaxValueDataLen, NULL, NULL); cout << "Number of entries is Run is " << ValuesNumber << "\n" << endl; //------------------------ Listing Key Values ------------------------// if (ValuesNumber) { cout << "Now, listing each value and its path\n" << endl; for (int j = 1; j < (int)ValueNumber; j++) { valueNameLen = MaxValueNameLen; dataLen = MaxValueDataLen; // Enumerate the key values RegEnumValue(hk, j, valueName, &valueNameLen, NULL, NULL, (LPBYTE)valuePath,&dataLen); // Print out TCHAR arrays             wcout << "Name: " << valueName << ", Path: ";
            wcout << valuePath << "\n";

// _tcscmpis used to compare two TCHAR values if (_tcscmp(valueName, NameToFind) == 0) { cout << "File found... and will be deleted \n"; RegDeleteValue(hk, valueName); DeleteFile(valuePath); // DOESN'T DELETE THE FILE IF IT IS RUNNING } } } RegCloseKey(hk);


StudiousStudent




One block of memory with two pointers for two different processes in unmanaged situation?

$
0
0

I have a problem of transferring some integer values that are generated at a fast clip in MFCaptureD3D. The latter is a GitHub project that captures pixel values of standard WebCam. It is a C++ application. A few variants have been considered, including named pipes and named shared memory. They still might be used but analyzing the code I noticed that there is considerable overhead in each method and that I am afraid will make them impractically slow and chocked with the data. So I want to define one block of memory with the stipulation that I could also define two pointers attached to it. I think I can use one of them to write the data and the other one to read. My question is are there any pitfalls in the idea? If there are I will abandon it and try to do named pipes.

int* ptr1[76800];

So, how do I define the second pointer if it is at all possible?    process A, writer ==> [memory] ==> process B, reader.

Thanks, -MyCatAlex


How to get Process ID of running application?

$
0
0

I'm trying toi get the process ID of a running application. But I think I may be doing it wrong. Any help would be appreciated.

        HANDLE hProcessSnap;
	HANDLE hProcess;
	PROCESSENTRY32 pe32;
	bool processFound = 0;
	TCHAR fileName[] = TEXT("FileAshAndBen.exe");

	// ------------ Getting List of Running Processes ------------//

	hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

	if (hProcessSnap == INVALID_HANDLE_VALUE)
	{
		cout << "CreateToolhelp32Snapshot (of process) is failed\n";
		return 0;
	}

	// ---------------- Getting FIle Process ID ----------------//

	// Set the size of the pe32 structure before using it
	pe32.dwSize = sizeof(PROCESSENTRY32);

	if (!Process32First(hProcessSnap, &pe32));
	{
		cout << "Process32First failed \n";
		// clean the snapshot object
		CloseHandle(hProcessSnap);
	}

	// Go through all the processes looking for FileAshAndBen.exe
	do
	{
		// print out the process name
		wcout << "\nProcess name is " << pe32.szExeFile << endl;

		// if the process name is FileAshAndBen.exe
		if (_tcscmp(pe32.szExeFile, fileName) == 0)
		{
			cout << "File process is found \n";
			processFound = 1;
			break;
		}
	} while (Process32Next(hProcessSnap, &pe32));



StudiousStudent

One block of memory with two pointers for two different processes in unmanaged situation?

$
0
0

I have a problem of transferring some integer values that are generated at a fast clip in MFCaptureD3D. The latter is a GitHub project that captures pixel values of standard WebCam. It is a C++ application. A few variants have been considered, including named pipes and named shared memory. They still might be used but analyzing the code I noticed that there is considerable overhead in each method and that I am afraid will make them impractically slow and chocked with the data. So I want to define one block of memory with the stipulation that I could also define two pointers attached to it. I think I can use one of them to write the data and the other one to read. My question is are there any pitfalls in the idea? If there are I will abandon it and try to do named pipes.

int* ptr1[76800];

So, how do I define the second pointer if it is at all possible?    process A, writer ==> [memory] ==> process B, reader.

Thanks, -MyCatAlex


key shortcut for closing a dockable window by win32 api

$
0
0

How to make key shortcut for closing a dockable window in C++ win32 api such as in Notepad++ Search Result window (pane)?

I don't know how in Visual Studio to put breakpoint at right just user clicking on small X button in the corner right.

Thanks before.

Detailed view in explorer allows edit of property after search

$
0
0

Hi,

I have created property handler DLL and in the same I have disabled the edit of some properties when viewed in detail page in windows explorer. It works fine.

But when I search the file in explorer and on searched result file these properties are editable.

How to fix this problem. Any suggestions.

Thanks,

Viyang C.


what does warning C4251 class needs to have dll interface to be used by clients of class mean?

$
0
0

what does C4251 class needs to have a dll interface warning mean?

Warning 1 warning C4251: 'reg::RegPartBase::mPartText' : class 'std::basic_string<_Elem,_Traits,_Alloc>' needs to have dll-interface to be used by clients of class 'reg::RegPartBase' c:\srcpp\libfilepreview\x64\debug\RegPart.h 32 1 LibFilePreview

I have a class in a DLL. In the project that uses the DLL there is a header file that declares the class with __declspec(dllimport).

class __declspec(dllimport) RegPartBase
{

public:
	wstring mPartText ;
	PartType mPartType ;
...
} ;

lvalue vs rvalue

$
0
0
I was going through the terms lvalue and rvalue. I read some articles but still fail to grasp the concepts. Could someone please explain in simple terms(if possible) what rvalue and lvalue mean?

what are the alternatives of curl in c++?

$
0
0

i am working on a project in which i have to send data from client pc to my server for now i am using curl for sending data to my server which is then processing data in php aand stores it in database.

But curl is not light weight its increasing size of my exe significantly besides that i want to know what are the alternatives i can use to send some string format data and files from c++ client side to my server php side.

please give a small example of uploading too

How to split a string to separate variables with a space - C++

$
0
0

I'm trying to make a Command-Line-Interface in C++ for fun. I need to have multiple arguments, so I need my string to be separated to different variables. Not to change the string to change what line a word is showed on.

EXAMPLE

>echo hello
hello>echo I am cool
I am cool

What I have so far is a simple program that asks for input. stores it into a variable and does nothing with it.

(This is stored in a function because there is stuff that launches it.)

void Foo() {
	string com = "";
	cout << "C++ Computer Operation" << endl;
	for ( ; ; )
	{
		cout << endl;
		cout << "> ";
		getline(cin, com, " ")
		if ( com = "echo" ):
			{
				cout << arg;
			}
	}
}

And I am sorry for using the name 'Foo'

MS Docs: Scroll Bitmap Issue & Double Buffering

$
0
0

Hi there,

Regarding the classic example which was pasted into a new VS 2019 Windows Desktop Application C++ project in Windows 1909, the form showed without any bitmap or scrollbars. Is extra code required for that?

Is it possible to apply double buffering in that example to operate in conjunction with ScrollWindowEx? The original idea was to move the co-ordinates of hdcWin in the WM_PAINT section:

(Pseudo code)

hDC = BeginPaint hwnd
hdcMem = CreateCompatibleDC: hDC
hBMMem = CreateCompatibleBitmap

In this example there is
HBITMAP oldBmp = (HBITMAP)SelectObject( memDC, bmp );

Instead of moving the bitmap of the hwnd to the edge of the virtual screen, for example, it is instead, saved tooldBmp

Not sure if all the drawing code in that example is going to help here, as we are only painting.

In another scenario, scrolling a bitmap with additional controls on the form, a drawing procedure should not be required for those controls inWM_PAINT either. Correct?

There's a some other SO examples here here and here that touch on the issue, but they only render a somewhat incomplete picture in my rather infertile gallery of conceptualizations.

Thanks for any help!


A natural, B flat, C sharp, D compile

Viewing all 15302 articles
Browse latest View live


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