c++-cli

Unresolved external symbol errors without #pragma comment lib command

风流意气都作罢 提交于 2019-12-11 11:28:00
问题 I added a project to my VS2008 solution and set a dependency to this newly added project in my startup project via the project settings window. The problem was that I had unresolved external symbol errors all over the place, but once I wrote the line #pragma comment (lib, "path_to/my_lib.lib") inside the file using the functions of my library, everything worked just fine. Specifically, I added that line right after my include #include "path_to/my_lib.h" #pragma comment (lib, "path_to/my_lib

Is it possible to reference a user control in the same Windows::Forms project?

China☆狼群 提交于 2019-12-11 10:36:45
问题 I have a Windows::Forms application and I want to add a custom control to it (which basically displays some images and links them with some bezier curves I'm drawing). I'm sure I've managed to get Windows Forms designer to display the custom controls in the same project before but I can't get it to work this time. It just says: C++ CodeDOM parser error: Line: 524, Column: 33 --- Unknown type 'MyNamespace.MyCustomControl'. Please make sure that the assembly that contains this type is

a member of managed class cannot be of a non-managed class type

会有一股神秘感。 提交于 2019-12-11 10:28:40
问题 I'm writing a program in c++/clr and i need to code lexical analyzer. And i have in it these: std::map <std::string, int> classes = { { "keyword",0 },{ "identifier",0 },{ "digit",0 },{ "integer",0 },{ "real",0 },{ "character",0 },{ "alpha",0 } }; std::vector<std::string> ints = { "0","1","2","3","4","5","6","7","8","9" }; std::vector<std::string> keywords = { "if","else","then","begin","end" }; std::vector<std::string> identifiers = { "(",")","[","]","+","=",",","-",";" }; std::vector<std:

What libraries do I need to link my mixed-mode application to?

試著忘記壹切 提交于 2019-12-11 10:24:32
问题 I'm integrating .NET support into our C++ application. It's an old-school MFC application, with 1 extra file compiled with the "/clr" option that references a CWinFormsControl. I'm not allowed to remove the linker flag "/NODEFAULTLIB". (We have our own build management system, not Visual Studio's.) This means I have to specify all necessary libraries: VC runtime and MFC. Other compiler options include "/MD" Next to that: I can't use the linker flag "/FORCE:MULTIPLE" and just add everything :

Using Windows API functions in .NET

情到浓时终转凉″ 提交于 2019-12-11 10:23:34
问题 I asked a question some time ago here: COM vs non-COM DLL about calling a classic C++ program from .NET. The answer (from Hans Passant) was to write a wrapper class in Visual C++, which worked out well in my project (I did get some help with this from another developer who is more commerically experienced with C++). My question is: is there wrapper classes created for some of the functions in the WINAPI. For example, the code below works without a wrapper class: Imports System.Runtime

How to properly configure MSVC's compiler options with QtCreator?

a 夏天 提交于 2019-12-11 10:06:00
问题 I'm trying to migrate from Visual Studio 2008 to QtCreator in a project that uses C++/CLI extensions. This just means that I need to use the -clr compiler option when compiling my files. I've managed to add it by adding the following line to my project.pro file: QMAKE_CXXFLAGS += -clr However, there is a conflicting option in my compiler's call that is conflicting with this one. It is the -EHsc option. But I can't find where these options get included and how to disable it. My default call to

Conversion between managed and unmanaged types in C++?

我怕爱的太早我们不能终老 提交于 2019-12-11 09:07:16
问题 When I use a GUI in C++ the text fields are stored as managed strings, i think. I need a way to convert them to standard ints, floats and strings. Any help? 回答1: You can convert a System.String into an unmanaged char * using Marshal.StringToHGlobalAnsi. Make sure you free it when you're done by calling Marshal.FreeHGlobal. To convert the strings to numeric values, you can use the regular .NET parsing functions such as Int32.Parse . 回答2: To use managed memory in native code, you must copy the

Hooking a C# event from C++/CLI

不羁的心 提交于 2019-12-11 09:06:15
问题 So I have a C# class that has the following event: public class CSClient { public delegate void OnMessageHandler(Object sender, EventArgs e); public event OnMessageHandler OnOptionsEvent; } Then I have a C++/CLI class, for which I want to subscribe to OnOptionsEvent. I have tried something like this: void CSClientWrapper::Start() { GCHandle h = GCHandle::FromIntPtr(IntPtr(_impl)); CSClient^ obj = safe_cast<CSClient^>(h.Target); __hook(&CSClient::OnOptionsEvent, obj, &CSClientWrapper:

How to use Boost classes in a .NET C++CLI GUI application

青春壹個敷衍的年華 提交于 2019-12-11 08:25:04
问题 I am writing a Windows Forms GUI application in Visual Studio 2012 using C++CLI and I really need to use the Boost bidirectional map to coordinate some GUI element values with values in some internal structs. I downloaded and unzipped the boost package and then in my project's Properties menu I added the Boost location to Configuration Properties -> VC++ Directories -> Include Directories. But, when I add the boost include (and nothing else, not even declaring a boost::bimap object) #include

Marshal between C# byte array and C++ byte array

二次信任 提交于 2019-12-11 08:18:00
问题 I have a C# array<System::Byte> and I want that to translate to a C++ byte* . How can I do that? I am using C++/CLR because it lets me use managed/unmanaged code in the same project. I'm basically writing a DLL and making a few methods that can be called via C#, but that contain unmanaged C++ code. So basically, my C++/CLR method header is this: void testMethod(array<Byte>^ bytesFromCSharp); and inside of that testMethod I would like to translate the bytesFromCSharp into a byte* which can be