clr

Unboxing for dynamic type

十年热恋 提交于 2020-01-07 08:52:21
问题 Consider the following code: public class Foo1 { public dynamic dowork() { return 10; } } And in my Main , I call like: int i = new Foo1().dowork(); The return value is 10. My question is why no Unboxing is required here?But in watch I've verified the Return Type of dowork is System.Object . 回答1: It is unboxing - but it's doing it implicitly. There's an implicit conversion from any dynamic expression to any type. The exact conversion performed will depend on the execution-time type of the

How does one Create Managed C++ Static Library in Visual Studio (Error C1189)

老子叫甜甜 提交于 2020-01-07 02:17:05
问题 It seems it is not possible to create a static linked library in managed /CLR generated code. I started by creating a C++ /CLR Library which defaulted to a DLL Library. When I change it to Static library (.lib) I get the error: C1189 "Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]" I don't want to include MFC DLL. I have selected Use Standard Windows Libraries so not sure why it thinks I am building MFC

Calling static function of C# .NET in C (ICLRRuntimeHost_ExecuteInDefaultAppDomain)

夙愿已清 提交于 2020-01-06 10:40:48
问题 I have this class KernelHelper which is written in C# .NET Framework 2.0. What I want to do is call its static functions in a C program. namespace Kernel.Client { public class KernelHelper { public static int testc(string msg) { // Removing the message box does not change anything System.Windows.Forms.MessageBox.Show(msg); return 0; } // ... } } which compiles and does not seem to make any problems so far. But calling ICLRRuntimeHost_ExecuteInDefaultAppDomain() returns 0x80131513 which is

How to control the connect timeout with the Winsock API?

情到浓时终转凉″ 提交于 2020-01-06 08:03:44
问题 I'm writing a program using the Winsock API because a friend wanted a simple program to check and see if a Minecraft server was running or not. It works fine if it is running, however if it is not running, the program freezes until, I'm assuming, the connection times out. Another issue is, if I have something like this (pseudo-code): void connectButtonClicked() { setLabel1Text("Connecting"); attemptConnection(); setLabel1Text("Done Connecting!"); } it seems to skip right to attemptConnection(

What is contained in a PE Header and CLR Header as part of managed Module in .NET executables?

♀尐吖头ヾ 提交于 2020-01-06 02:11:25
问题 What is meant by PE header in a .net assembly? I have read that .net programs are compiled into a portable executable which will contain IL Code and Meta Data. But these terms PE Header and CLR Header are new. Are they different from IF Code and Metadata? If so what do they contain and when will one need to use it? 回答1: The PE file format is used for executables in Windows, like progams and DLLs, but also for some other data like .FON font files. The PE header is the header of the file, which

How to use Finalize with managed resources?

自闭症网瘾萝莉.ら 提交于 2020-01-05 23:15:12
问题 I'm not 100% clear on how an instance of class A can be defined to exist until after the last instance of class B is finalized. Or in other words, I'd like all B's to call close&dispose methods in A inside the B finalisation... and for that to happen before A itself is finalized. The scenario: A. I've got a managed wrapper for an unmanaged resource. For an analogy, lets call A a file system B. managed resources that refer to A, that in turn have requested an unmanaged resource via the A

Necessary to pin_ptr on C++ CLR Value types, why?

╄→尐↘猪︶ㄣ 提交于 2020-01-04 19:02:34
问题 Since .NET Value types (managed C++ structs) are stored on the Stack why is it (or, alternatively is it actually) necessary to pin_ptr them in order to pass a pointer to an unmanaged function? Eg. BYTE b[100]; If I pass &b to an unmanaged function without first pinning it, may the stack become corrupted? Is the CLR stack subject to change in the same way as the GC Heap? I am led to believe that the CLR Stack uses unusual optimizations such as using processor registers which makes it

Necessary to pin_ptr on C++ CLR Value types, why?

我怕爱的太早我们不能终老 提交于 2020-01-04 19:02:18
问题 Since .NET Value types (managed C++ structs) are stored on the Stack why is it (or, alternatively is it actually) necessary to pin_ptr them in order to pass a pointer to an unmanaged function? Eg. BYTE b[100]; If I pass &b to an unmanaged function without first pinning it, may the stack become corrupted? Is the CLR stack subject to change in the same way as the GC Heap? I am led to believe that the CLR Stack uses unusual optimizations such as using processor registers which makes it

Necessary to pin_ptr on C++ CLR Value types, why?

我的梦境 提交于 2020-01-04 19:02:08
问题 Since .NET Value types (managed C++ structs) are stored on the Stack why is it (or, alternatively is it actually) necessary to pin_ptr them in order to pass a pointer to an unmanaged function? Eg. BYTE b[100]; If I pass &b to an unmanaged function without first pinning it, may the stack become corrupted? Is the CLR stack subject to change in the same way as the GC Heap? I am led to believe that the CLR Stack uses unusual optimizations such as using processor registers which makes it

Literals and implicit narrowing conversions

被刻印的时光 ゝ 提交于 2020-01-04 17:54:27
问题 a) Shouldn’t the following assignment cause an error, since number 100 is a literal of type int and since compiler doesn’t allow implicit narrowing conversions? byte b = 100; b) If compiler doesn’t complain about implicit narrowing conversion from int literal to type byte , then why doesn’t it also allow an implicit narrowing conversion from double literal to type float ( I realize we could avoid this error by specifying float literal using F/f suffix )? byte b=16; //OK float f1=16.9; //error