visual-c++

A simple way to convert to/from VARIANT types in C++

匆匆过客 提交于 2020-01-13 08:50:31
问题 Are there any easy-to-use , high-level classes or libraries that let you interact with VARIANT s in Visual C++? More specifically, I'd like to convert between POD types (e.g. double , long ), strings (e.g. CString ), and containers (e.g. std::vector ) and VARIANT s. For example: long val = 42; VARIANT var; if (ToVariant(val, var)) ... // tries to convert long -> VARIANT comObjPtr->someFunc(var); std::vector<double> vec; VARIANT var = comObjPtr->otherFunc(); if (FromVariant(var, vec)) ... //

How to make child control handle accelerator command of parent CView

妖精的绣舞 提交于 2020-01-13 06:42:11
问题 I have a CFormView, and a child CListCtrl control. I can handle accelerator events, like Ctrl+C, Ctrl+V ... in CFormView without problem, by defining below message handler: ON_COMMAND(ID_EDIT_COPY, &CMyFormView::OnEditCopy) Now I want my CListCtrl handle these commands differently. I want to implement OnEditCopy in CListCtrl class, rather than implement logic in the view class. How can I pass the accelerator events from CView to child control, when CListCtrl is on focus? I tried like: ON

LNK2028 Managed C++ DLL calling function in another Managed C++ DLL

二次信任 提交于 2020-01-13 06:36:09
问题 I'm using VS2010 with a managed C++ DLL calling a function in another managed C++ DLL and I'm getting many LNK2028 link errors that look like this. 1>udpPkt.obj : error LNK2028: unresolved token (0A0000AA) "unsigned short __cdecl ComputeCrc16(void const *,unsigned int)" (?ComputeCrc16@@$$FYAGPBXI@Z) referenced in function "public: short __thiscall CPrivateUdpPkt::ComputeCrc(void)const " (?ComputeCrc@CPrivateUdpPkt@@$$FQBEFXZ) When I use dumpbin /export on the called DLL I see the unresolved

How do I compile a single source file within an MSVC project from the command line?

為{幸葍}努か 提交于 2020-01-13 05:13:17
问题 I'm about to start doing some benchmarking/testing of our builds, and I'd like to drive the whole thing from a command line. I am aware of DevEnv but am not convinced it can do what I want. If I could have a single file built within a single project, I'd be happy. Can this be done? 回答1: The magical incantation is as follows. Note that this has only been tested with VS 2010 - I have heard this is the first version of Visual Studio with this capability: The Incantation <msbuild> <project>

Is dividing by zero accompanied with a runtime error ever useful in C++?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 04:26:10
问题 According to C++ Standard (5/5) dividing by zero is undefined behavior. Now consider this code (lots of useless statements are there to prevent the compiler from optimizing code out): int main() { char buffer[1] = {}; int len = strlen( buffer ); if( len / 0 ) { rand(); } } Visual C++ compiles the if -statement like this: sub eax,edx cdq xor ecx,ecx idiv eax,ecx test eax,eax je wmain+2Ah (40102Ah) call rand Clearly the compiler sees that the code is to divide by zero - it uses xor x,x pattern

Compile Assembly Output generated by VC++?

流过昼夜 提交于 2020-01-12 20:38:12
问题 I have a simple hello world C program and compile it with /FA. As a consequence, the compiler also generates the corresponding assembly listing. Now I want to use masm/link to assemble an executable from the generated .asm listing. The following command line yields 3 linker errors: \masm32\bin\ml /I"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" /c /coff asm_test.asm \masm32\bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib" asm

Is it possible to impersonate a user without logging him on?

只愿长相守 提交于 2020-01-12 15:19:43
问题 Is it possible to impersonate a user without supplying user name/password? Basically, I'd like to get the CSIDL_LOCAL_APPDATA for a user (not the current one) using the ShGetFolderPath() function. All I currently have is a SID for that user. 回答1: No, you have to call Win32 API LogonUser function to get windows account token back so you can then impersonate. 回答2: You can impersonate a user without supplying password by calling ZwCreateToken. See the CreatePureUserToken function in this article

Is it possible to impersonate a user without logging him on?

北慕城南 提交于 2020-01-12 15:19:19
问题 Is it possible to impersonate a user without supplying user name/password? Basically, I'd like to get the CSIDL_LOCAL_APPDATA for a user (not the current one) using the ShGetFolderPath() function. All I currently have is a SID for that user. 回答1: No, you have to call Win32 API LogonUser function to get windows account token back so you can then impersonate. 回答2: You can impersonate a user without supplying password by calling ZwCreateToken. See the CreatePureUserToken function in this article

Why does the compiler complain about this not being a constexpr?

旧街凉风 提交于 2020-01-12 14:40:55
问题 I am trying to learn a bit more on how to use C++ constant expressions in practice and created the following Matrix class template for illustration purposes: #include <array> template <typename T, int numrows, int numcols> class Matrix{ public: using value_type = T; constexpr Matrix() : {} ~Matrix(){} constexpr Matrix(const std::array<T, numrows*numcols>& a) : values_(a){} constexpr Matrix(const Matrix& other) : values_(other.values_){ } constexpr const T& operator()(int row, int col) const {

Compiling libffi with VS2012 fails with fatal error LNK1281: Unable to generate SAFESEH image

做~自己de王妃 提交于 2020-01-12 14:11:52
问题 Compiling libffi with VS11 gives the following linker error libffi\libffi-3.0.9\ms\Win32\Debug\ffi.dll : fatal error LNK1281: Unable to generate SAFESEH image. The same project was compiling fine with VS10, but after an auto upgrade with VS2012, it started giving linker error The Explanation in MSDN is too cryptic and least helpful I might rebuild with /SAFESEH:NO , but I am unsure of the implication. Please advise what might go wrong. 回答1: The main implication of not having SAFESEH is that