c++-cli

List<T> Find method in C++/CLI

百般思念 提交于 2020-01-15 08:44:07
问题 Why it doesn't work in C++/CLI ? _list->Remove(_list->Find(x => x.Inode == 2)); I received an error error C2065: 'x' : undeclared identifier 回答1: @Hans Passant's comment is the answer, so I'm just pasting it here: C++/CLI doesn't support lambda expressions. The language was frozen in 2005, no new bells and whistles were added to it since then. You'll need to use a delegate explicitly. C++11 got lambdas but they are not compatible with C++/CLI. – Hans Passant 回答2: As Hans Passant commented, C+

libcurl compile errors

╄→尐↘猪︶ㄣ 提交于 2020-01-15 05:20:09
问题 I use libcurl and I get these errors without writting any code just compiling and I don't know why Fehler 49 error C2628: '$UnnamedClass$0x05e5b255$395$' gefolgt von 'bool' unzulässig (Semikolon ';' vergessen?) c:\users\ttg\desktop\curl-7.21.7\lib\setup_once.h 273 Fehler 50 error C2065: '_SH_DENYNO': nichtdeklarierter Bezeichner C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xiosbase 111 first is a libcurl file and it says it's followed by bool(forgot semicolon?) second

Linking unmanaged C++ DLL with managed C++ class library DLL

天大地大妈咪最大 提交于 2020-01-14 07:57:09
问题 As in the question Creating simple c++.net wrapper. Step-by-step I am tring to use C++ classes in .NET but I am having problems building in Visual Studio (2008). I have an unmanaged class A (C++ compiled with /clr). I created a C++/clr class 'Class1' which wraps A and with matching method delegates to A's methods. If I include class A's unit source file in the class library project for Class1 (managed) I have no problems everything links and works fine, But I have many unmanaged C++ classes

Declare native types inside a cli class?

旧时模样 提交于 2020-01-14 05:39:41
问题 I have a public ref class Test inside this class, I have: int frameWidth; int frameHeight; int frameStride; When I try to compile this, I get the error: error C2664: 'GetImageSize' : cannot convert parameter 1 from 'cli::interior_ptr<Type>' to 'int *' GetImageSize is a native function and it works only if I move the declaration of the 3 ints above to outside the class or inside the block that calls GetImageSize. How can I solve this? Those 3 ints needs to be accessible by more than one

void* to Object^ in C++/CLI

时光怂恿深爱的人放手 提交于 2020-01-13 13:49:52
问题 I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#. Some of the native C++ functions have a return type of void*. I am not sure how to handle this when I pass back the value to my calling code. For instance: if a C# app calls my dll wrapper, what do I return from the native call: void* start(ThreadFunc,void *, unsigned *); I am currently attempting to box the return in a generic System::Object^ with no luck.

Passing C++/CLI Class Method as C function pointer

旧巷老猫 提交于 2020-01-13 07:55:09
问题 I have a third-party C library that provides this header: //CLibrary.h #include <Windows.h> #include <process.h> typedef void (WINAPI *CLibEventCallback)(int event, void *data); __declspec(dllexport) bool CLibStart (CLibEventCallback callback, void *data); // CLibrary.c -- sample implementation static CLibEventCallback cb; void _cdecl DoWork (void *ptr) { for (int i = 0; i < 10; ++i) { cb (i*i, ptr); Sleep (500); } } __declspec(dllexport) bool CLibStart (CLibEventCallback callback, void *data

Passing C++/CLI Class Method as C function pointer

风格不统一 提交于 2020-01-13 07:55:07
问题 I have a third-party C library that provides this header: //CLibrary.h #include <Windows.h> #include <process.h> typedef void (WINAPI *CLibEventCallback)(int event, void *data); __declspec(dllexport) bool CLibStart (CLibEventCallback callback, void *data); // CLibrary.c -- sample implementation static CLibEventCallback cb; void _cdecl DoWork (void *ptr) { for (int i = 0; i < 10; ++i) { cb (i*i, ptr); Sleep (500); } } __declspec(dllexport) bool CLibStart (CLibEventCallback callback, void *data

Is there a C++/CLI smart pointer project (e.g. scoped_ptr)?

谁说胖子不能爱 提交于 2020-01-12 04:40:08
问题 Is there a C++/CLI RAII smart pointer class for containment of a native pointer in a managed type? Just wondering, before I go write my own clr_scoped_ptr value class template. I'm aware of the Microsoft-provided: containment of a managed handle in a native class: auto_gcroot containment of a managed handle in a managed class: auto_handle The above two are similar to auto_ptr or unique_ptr . I gave skeleton code for a counted_handle here, similar to shared_ptr But all these are for disposing

How do you convert a 'System::String ^' to 'TCHAR'?

岁酱吖の 提交于 2020-01-11 10:25:32
问题 i asked a question here involving C++ and C# communicating. The problem got solved but led to a new problem. this returns a String (C#) return Marshal.PtrToStringAnsi(decryptsn(InpData)); this expects a TCHAR* (C++) lpAlpha2[0] = Company::Pins::Bank::Decryption::Decrypt::Decryption("123456"); i've googled how to solve this problem, but i am not sure why the String has a carrot(^) on it. Would it be best to change the return from String to something else that C++ would accept? or would i need

how to convert from LPWSTR to 'const char*'

余生颓废 提交于 2020-01-11 06:06:21
问题 After getting a struct from C# to C++ using C++/CLI: public value struct SampleObject { LPWSTR a; }; I want to print its instance: printf(sampleObject->a); but I got this error: Error 1 error C2664: 'printf' : cannot convert parameter 1 from 'LPWSTR' to 'const char *' How can I convert from LPWSTR to char* ? Thanks in advance. 回答1: Don't convert. Use wprintf instead of printf : wprintf See the examples which explains how to use it. Alternatively, you can use std::wcout as: wchar_t *wstr1= L