Windows threading: _beginthread vs _beginthreadex vs CreateThread C++

CreateThread() is a raw Win32 API call for creating another thread of control at the kernel level. _beginthread() & _beginthreadex() are C runtime library calls that call CreateThread() behind the scenes. Once CreateThread() has returned, _beginthread/ex() takes care of additional bookkeeping to make the C runtime library usable & consistent in the new thread. In … Read more

How to find if a native DLL file is compiled as x64 or x86?

You can use DUMPBIN too. Use the /headers or /all flag and its the first file header listed. dumpbin /headers cv210.dll 64-bit Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file cv210.dll PE signature found File Type: DLL FILE HEADER VALUES 8664 machine (x64) 6 number of sections … Read more

When do we need to set ProcessStartInfo.UseShellExecute to True?

The UseShellExecute boolean property is related to the use of the windows ShellExecute function vs the CreateProcess function – the short answer is that if UseShellExecute is true then the Process class will use the ShellExecute function, otherwise it will use CreateProcess. The longer answer is that the ShellExecute function is used to open a … Read more

What is __stdcall?

__stdcall is the calling convention used for the function. This tells the compiler the rules that apply for setting up the stack, pushing arguments and getting a return value. There are a number of other calling conventions, __cdecl, __thiscall, __fastcall and the wonderfully named __declspec(naked). __stdcall is the standard calling convention for Win32 system calls. … Read more

How to get the error message from the error code returned by GetLastError()?

//Returns the last Win32 error, in string format. Returns an empty string if there is no error. std::string GetLastErrorAsString() { //Get the error message ID, if any. DWORD errorMessageID = ::GetLastError(); if(errorMessageID == 0) { return std::string(); //No error message has been recorded } LPSTR messageBuffer = nullptr; //Ask Win32 to give us the string … Read more

How to provide user name and password when connecting to a network share

I liked Mark Brackett’s answer so much that I did my own quick implementation. Here it is if anyone else needs it in a hurry: public class NetworkConnection : IDisposable { string _networkName; public NetworkConnection(string networkName, NetworkCredential credentials) { _networkName = networkName; var netResource = new NetResource() { Scope = ResourceScope.GlobalNetwork, ResourceType = ResourceType.Disk, DisplayType … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)