Is there a better way to Save the files in Visual Studio?
After making some changes in xyz.cpp file, when I am trying to save the whole project it asks to save files in the directory and ultimately it didn't get saved and an error message comes as
The Process cannot access the files "c:\ml/src.cpp" because it is being used by another process.
Usually to get rid of this error I use to open another .cpp file and make some chnages in that and then try to save so that other unsaved files gets save with this and sometimes it didn't work well. was wondering if there is any better way of handling it?
1 answer
-
answered 2022-05-05 10:00
Landstalker
You should:
Download ProcessExplorer
ProcessExplorer will tell you wich process are using/blocking your file.
do you know?
how many words do you know
See also questions close to this topic
-
C++ increment with macro
I have the following code and I want to use increment with macro:
#include <iostream> #define ABS(x) ((x) < 0 ? -(x) : (x)) int main(int argc, char** argv) { int x = 5; const int result = ABS(x++); std::cout << "R: " << result << std::endl; std::cout << "X: " << x << std::endl; return EXIT_SUCCESS; }
But output will be incorrect:
R: 6 X: 7
Is it possible to somehow use macros with an increment, or should this be abandoned altogether?
-
Can anyone pls tell me whats wrong with my code ? im stuck for the last 3 hours ,this question is bipartite graph in c++
idk why im getting error ,can someone help ? im trying to prove if a graph is bipartite or not in c++
bool isBipartite(vector<int> graph[],int V) { vector<int> vis(V,0); vector<int> color(V,-1); color[0]=1; queue <int> q; q.push(0); while (!q.empty()) { int temp = q.front(); q.pop(); for (int i=0;i<V;i++) { if (!vis[i] && color[i] == -1) "if there is an edge, and colour is not assigned" { color[i] = 1 - color[temp]; q.push(i); vis[i]=1; } else if (!vis[i] && color[i] == color[temp] "if there is an edge and both vertices have same colours" { vis[i]=1; return 0; // graph is not bipartite } } } return 1; }
it gives output "no" for whatever i enter
-
How to assign two or more values to a QMap Variable in Qt
I am getting confused of how to store the values assigned from 3 different functions and storing them in a single map variable
QMap<QString,QString> TrainMap = nullptr; if(......) ( TrainMap = PrevDayTrainMap(); TrainMap = NextDayTrainMap(); TrainMap = CurrentDayTrainMap(); }
The PrevDayTrainMap,NextDayTrainMap & CurrentDayTrainMap returns a set of values with Date and the TrainIdName.I need to store all the values from prevday,currentday and nextday in the TrainMap but it stores only the currentday values to the TrainMap as it is assigned at the last.I am not sure what to do so that it doesn't overwrite.If I should merge what is the way to do it?
-
Passing events to the parent panel
In a Windows Forms application, I want to create a
UserControl
that reacts to mouse events. But in some cases, I want the event to be passed to the parent that holds it (aPanel
for instance). In particular, I want aShift+MouseClick
to be passed to the parent to let a context menu appear (the context menu may not be embedded in theUserControl
). But a plainMouseClick
will be not be transmitted.Is there a simple way to achieve that (preferably using a standard
MouseClick
event handled by thePanel
) ? -
Are there any good mappings between GCC and MSVC warnings? E.g. -Wredundant-move on MSVC
This question is somewhat two fold, one being more general than the other. The specific question is; does MSVC have equivalent warnings to
-Wredundant-move
? More generally, is there anywhere online, even if it's someone's blog, that has a reasonable mapping between GCC and MSVC warnings?I'm aware that warnings don't have any requirement to be similar accross platforms, or even exist at all - that's why I'm interested to find out if there is any reasonable correlation?
For a small bit of background, I'm looking to enable specific
-Werror
s on a cross-platform project, and would prefer if each platform looked after roughly the same warnings instead of relying on the user to check on both platforms manually. -
Recursive function - Best solution
Gentlemen,
I need to create a function that performs the tasks:
- http call;
- Save the answer in a text file (if successful);
- Wait 5 seconds (Sleep);
- Runs the same task again.
In this case, I think a "recursive function" could meet my need, but I see some people saying that we should avoid recursive functions.
Could you give me ideas for a secure implementation?
Thank you! Marcelo
-
How do I slow this fill algorithm so the user can see the images being filled gradually?
I have tried to use
sleep()
in conjunction withRedraw()
but this causes the program to crash. TheFLOOD_FINISHED
message causes a call toRedraw()
void Redraw() { InvalidateRect(g_hWnd, NULL, FALSE); UpdateWindow(g_hWnd); } void FloodFillUtil(CDIB32* scr, int xPos, int yPos) { //using namespace std::chrono_literals; if (IsValid(scr, xPos, yPos)) { //Redraw(); scr->SetRGB(xPos, yPos, 255, 0, 0); FloodFillUtil(scr, xPos + 1, yPos); FloodFillUtil(scr, xPos - 1, yPos); FloodFillUtil(scr, xPos, yPos + 1); FloodFillUtil(scr, xPos, yPos - 1); } return; } void FloodFill(CDIB32* scr, CPoint& mid) { int xPos = mid.x; int yPos = mid.y; FloodFillUtil(scr, xPos, yPos); } void SetupDoItThread() { std::thread Worker(DoIt); Worker.join(); } void SetupDogThreads(CPoint mid) { //Redraw(); FloodFill(&m_screenDib, mid); } void DoIt() { if (!m_done) { CPoint mid; std::vector<std::thread> threads; for (int i = 0; i < REZ * REZ; ++i) { CPoint mid; GetBlobMidPoint(i, mid); threads.push_back(std::thread(SetupDogThreads, mid)); } for (auto& th : threads) { th.join(); } ::PostMessage(g_hWnd, FLOOD_FINISHED, NULL, NULL); m_done = true; } }
-
CListCtrl did not show text immediately like StaticText
I have a code like this to write install log to a static text and a list control, and i have a button to start the installer that be handle by function
OnClickInstallBtn()
but every time I call theWriteLogtoScreen()
, only the static text change and nothing show up in the list until theOnClickInstallBtn()
is done and everything on that list show up all at one.How can i make it show up right away like the static text?
WriteLogtoScreen(LPCTSTR sLog) { int iItems; iItems = m_ListLog.GetItemCount(); m_ListLog.InsertItem(iItems, sLog); m_ListLog.Update(iItems); m_ListLog.SetItemText(iItems, 0, sLog); m_ListLog.Update(iItems); UpdateData(FALSE); SetDlgItemText(IDC_STATIC, sLog); }
-
cannot return socket descriptor from WSASocketA
I have a .cpp file that makes a connection, works perfectly assembled with g++. I also have a 32-bit exe that makes a connection as well. The issue now is I want to use 64-bit assembly to make this connection. I was able to get as far as calling WSASocketA with all the right arguments (2,1,6,0,0,0) but I am simply not able to return a socket descriptor. I am getting -1 (0xFFFFFFFF). So then I noticed I can call WSAGetLastError which I did and it returns 10022. But my arguments are correct. I analyzed the objdump from my cpp connector which has the same exact arguments, in that order. And I am fully aware of using the correct calling convention for 64-bit in windows.
I am using nasm and tried both link and GoLinker.exe for my linkers which produce the same exact output. I am explicitly using ws2_32.lib from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64 when linking as well as kernel32.lib and ucrt.lib as well both in 64-bit. Is there some reason I am not able to get a socket descriptor. I'm pretty sure my code is correct:
BITS 64 SECTION .data fmtd: db "%d", 0x0a,0 fmts: db "%s", 0x0a,0 SECTION .bss ;pStru: resq 1 ; This is a pointer for a dynamically created structure - malloc style pStru: resb 0x190 ; Shadow space for a statically created structure SECTION .text extern printf extern malloc global main main: ;push rbp ;mov rbp, rsp ;sub rsp, 0x28 ; 40 bytes of shadow space ;and rsp, 0FFFFFFFFFFFFFFF0h ; Align the stack to a multiple of 16 bytes ; Parse PEB and find kernel32 xor rcx, rcx ; RCX = 0 mov rax, [gs:rcx + 0x60] ; RAX = PEB mov rax, [rax + 0x18] ; RAX = PEB->Ldr mov rsi, [rax + 0x20] ; RSI = PEB->Ldr.InMemOrder lodsq ; RAX = Second module xchg rax, rsi ; RAX = RSI, RSI = RAX lodsq ; RAX = Third(kernel32) mov rbx, [rax + 0x20] ; RBX = Base address ; Parse kernel32 PE xor r8, r8 ; Clear r8 mov r8d, [rbx + 0x3c] ; R8D = DOS->e_lfanew offset mov rdx, r8 ; RDX = DOS->e_lfanew add rdx, rbx ; RDX = PE Header mov r8d, [rdx + 0x88] ; R8D = Offset export table add r8, rbx ; R8 = Export table xor rsi, rsi ; Clear RSI mov esi, [r8 + 0x20] ; RSI = Offset namestable add rsi, rbx ; RSI = Names table xor rcx, rcx ; RCX = 0 mov r9, 0x41636f7250746547 ; GetProcA ; Loop through exported functions and find GetProcAddress Get_Function: inc rcx ; Increment the ordinal xor rax, rax ; RAX = 0 mov eax, [rsi + rcx * 4] ; Get name offset add rax, rbx ; Get function name cmp QWORD [rax], r9 ; GetProcA ? jnz Get_Function xor rsi, rsi ; RSI = 0 mov esi, [r8 + 0x24] ; ESI = Offset ordinals add rsi, rbx ; RSI = Ordinals table mov cx, [rsi + rcx * 2] ; Number of function xor rsi, rsi ; RSI = 0 mov esi, [r8 + 0x1c] ; Offset address table add rsi, rbx ; ESI = Address table xor rdx, rdx ; RDX = 0 mov edx, [rsi + rcx * 4] ; EDX = Pointer(offset) add rdx, rbx ; RDX = GetProcAddress mov rdi, rdx ; Save GetProcAddress in RDI ; Use GetProcAddress to find the address of LoadLibrary mov rcx, 0x41797261 ; aryA push rcx ; Push on the stack mov rcx, 0x7262694c64616f4c ; LoadLibr push rcx ; Push on stack mov rdx, rsp ; LoadLibraryA mov rcx, rbx ; kernel32.dll base address (rbx never changes so we could use it later for CreateProcessA) sub rsp, 0x20 ; Allocate stack space for function call call rdi ; Call GetProcAddress add rsp, 0x20 ; Cleanup allocated stack space mov rsi, rax ; LoadLibrary saved in RSI ;getws2_32: mov rcx, 0x6c6c ; ll push rcx ; Push on the stack mov rcx, 0x642e32335f327377 ; d.32_2sw push rcx ; Push on the stack mov rcx, rsp ; ws2_32.dll sub rsp, 0x20 ; Allocate stack space for function call call rsi ; call Loadlibrary (stored in rsi) and find ws2_32.dll add rsp, 0x20 ; Cleanup allocated stack space mov r15, rax ; base address of ws2_32.dll saved in local variable r15 (winsock handle) ;getWSAStartup: mov rcx, 0x7075 ; pu push rcx ; Push on the stack mov rcx, 0x7472617453415357 ; tratSASW push rcx ;Push on the stack mov rdx, rsp ; copy WSAStartup from stack to 2nd argument (rdx is the 2nd arg) mov rcx, r15 ; winsock handler sub rsp, 0x20 ; Allocate stack space for function call call rdi ; GetProcAddress(ws2_32.dll, WSAStartup) add rsp, 0x20 ; Cleanup allocated stack space mov r14, rax ; ws2_32.WSAStartup saved in r14 ;callWSAStartUp: ; malloc style just uncomment resq 0x190 for pStru in .bss ;mov rcx, 0x198 ; size of the structure ;call malloc ; get the memory allocated ;mov qword [ pStru ], rax ; store the address in the pointer ;xor rdx, rdx ;lea rdx, [ pStru ] ; pointer to our WSAData structure ;xor rcx, rcx ;mov cx, 0x202 ;call r14 ; stack style ;xor rcx, rcx ;mov cx, 0x190 ; 0x190 works only when 0x28 bytes are subtracted, no more, no less!!! ;sub rsp,rcx ;lea rdx,[rsp] ;xor rcx, rcx ;mov cx,0x202 ;sub rsp, 0x28 ;call r14 ; call WSAStartup(MAKEWORD(2, 2), wsadata_pointer) ;add rsp, 0x28 ;add rsp, 0x190 ; static (.bss) style just uncomment resb 0x190 for pStru in .bss xor rdx, rdx lea rdx, [ pStru ] ; pointer to our WSAData structure xor rcx, rcx mov cx, 0x202 ; version 2,2 = 514 in decimal = 0x202 in hex, must be a word (2 bytes so only register cx is used) sub rsp, 0x28 call r14 add rsp, 0x28 ; print return value from WSAStartup (0 if no errors) mov rdx, rax mov rcx, fmtd sub rsp, 0x20 call printf add rsp, 0x20 ;getWSASocketA: xor rdx, rdx xor rcx, rcx mov rcx, 0x4174 ; 'At' original push rcx ; push on stack mov rcx, 0x656b636f53415357 ; 'ekcoSASW' push rcx ; push on stack mov rdx, rsp ; copy string of WSASocketA contents from stack to rdx (2nd arg for GetProcAddress) mov rcx, r15 ; socket handler ws2_32.dll sub rsp, 0x30 call rdi ; GetProcAddress(ws2_32.dll, WSASocketA) add rsp, 0x30 ; Cleanup allocated stack space: standard is 32 bytes but 2 pushes = 16 more = 48 = 0x30 mov r13, rax ; save ws2_32.WSASocketA to r13 ;callWSASocketA: xor r9, r9 ; lpProtocolInfo=NULL (uses itself from above: NULL) push r9 ; dwFlags=NULL push r9 ; g=NULL xor r8, r8 mov r8, 0x6 ; protocol=6 xor rdx, rdx mov rdx, 0x1 ; type=1 xor rcx, rcx mov rcx, 0x2 ; af=2 sub rsp, 0x28 call r13 ; call WSASocketA add rsp, 0x28 ; Cleanup allocated stack space = 48 bytes = 0x30 mov r14, rax ; save socket descriptor of WSASocketA to r14 ; print return value from WSASocketA (should be a socket descriptor) xor rdx, rdx mov rdx, r14 mov rcx, fmtd sub rsp, 0x20 call printf add rsp, 0x20 ;getWSAGetLastError: xor rcx, rcx mov rcx, 0x726f7272457473 ; rorrEts push rcx mov rcx, 0x614c746547415357 ; aLteGSASW push rcx ;Push on the stack mov rdx, rsp ; copy WSAGetLastError from stack to 2nd argument (rdx is the 2nd arg) mov rcx, r15 ; winsock handler sub rsp, 0x30 ; Allocate stack space for function call call rdi ; GetProcAddress(ws2_32.dll, WSAStartup) add rsp, 0x30 ; Cleanup allocated stack space mov r11, rax ; ws2_32.WSAGetLastError saved in r11 ;callWSAGetLastError: call r11 ; print return value from WSAGetLastError (which should be an error number if WSASocketA failed) xor rdx, rdx mov rdx, rax mov rcx, fmtd sub rsp, 0x20 call printf add rsp, 0x20
When completed, rax has a -1 instead of a 264 or 256 as my cpp connector does. Any ideas? I did debug this for the last few days all day nonstop. My program does not crash, it simply does not get a socket descriptor. Thanks.
Using GoLink.exe:
nasm -f win64 connect64.s c:\Golink\GoLink.exe /console /entry main kernel32.dll msvcrt.dll ws2_32.dll connect64.obj /fo connect64.exe && connect64.exe
OR
nasm -f win64 connect64.s && link connect64.obj /SUBSYSTEM:CONSOLE /OUT:connect64.exe /ENTRY:main "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64\WS2_32.LIB" "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64\KERNEL32.LIB" "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64\UCRT.LIB" "legacy_stdio_definitions.lib" /LARGEADDRESSAWARE:NO && connect64.exe
-
vcxproj for x64 settings issue
I am trying to compile an old source code (VS 6, WinDDk 7600). The source is compiled for x86 debug version on Windows 10, Visual studio 2019, WinDDk 7600. When tried to compile for x64(debug, release), I got error.
This
.bat
locations is inC:\WinDDK\7600.16385.1\bin\setenv.bat
.1>------ Build started: Project: Zee_build, Configuration: Debug x64 ------ 1>Build started 07-02-2022 16:15:12. 1>Target Build: 1> The system cannot find the path specified. 1> 'build' is not recognized as an internal or external command, 1> operable program or batch file. > C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(41,5): error MSB3073: The command "call \bin\setenv.bat chk x64 win7 1> C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(41,5): error MSB3073: cd /d C:\Pro\app_build\ 1> C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(41,5): error MSB3073: build" exited with code 9009. 1>Done building target "Build" in project "app_build.vcxproj" -- FAILED.
How could I solve it?
-
fopen_s returns error code 2 with system account and win 32 but works fine on winx64 (c++)
I have a cpp program that uses fopen_s to open and read a file created under the directory C:\Windows\System32\config\systemprofile\AppData\Roaming.
My program needs to be compatible with winx64 and win32.
When I run this program with a system account (run using PSTools\PSExec -i -s C:\windows\system32\cmd.exe) and the Win32 compiled version of the program, fopen_s() on any file inside "C:\Windows\System32\config\systemprofile\AppData\Roaming" returns an error code 2, even though the file is present. However, when I run the x64 compiled version of the same program, it works fine and fopen_s() is able to find and open the same file.
I am sure there are no mistakes as far as passing a valid filename to fopen_s() and I have verified this.
I make sure that the int variable that stores the return value from fopen_s() is set to 0 every time before calling fopen_s(). I am calling fopen_s() in "r" mode.
Also, elsewhere in the same program I am able to create files under the same directory.
I am using VS2019 and cpp +11 to compile my program. My system is running windows 10 (64-bit) on an x64 processor (Intel(R) Xeon(R) Gold 6136)
Why would a win32 application fail to read a file created under "C:\Windows\System32\config\systemprofile\AppData\Roaming" with a system account while the x64 version of the same application works fine?
Code snippet:
int FileOpenFunc(FILE ** ppFile, std::string sFilename, std::string sOpenMode) { int errOpen = 0; #ifdef _WIN32 errOpen = fopen_s(ppFile, sFilename.c_str(), sOpenMode.c_str()); #else *ppFile = fopen(sFilename.c_str(), sOpenMode.c_str()); errOpen = errno; #endif return errOpen; } void func() { std::string sFileName = "C:\\Windows\\System32\\config\\systemprofile\\AppData\\Roaming\\Check\\sample.txt"; int errFopenErrNo = 0; FILE* fp = NULL; errFopenErrNo = FileOpenFunc(&fp, sFileName, "r"); if (fp!= NULL) { //do something } else { //do something else } }