clr

Boost Threads with CLR

落花浮王杯 提交于 2019-11-30 08:59:32
Using Visual Studio 2008 and Boost Libraries 1.46.1 I want to compile and link the following with the /CLR flag: #include <boost/thread/thread.hpp> void run() {} int main(int argc, char *argv[]) { boost::thread t(run); } The first error is about a forward-declared dummy-struct in boost::thread. This post works around this by declaring: namespace boost { struct thread::dummy {}; } Sure, I now can compile, but then I get the linker warning Warning 1 warning LNK4248: unresolved typeref token (0100001F) for 'boost.detail.win32._SECURITY_ATTRIBUTES'; image may not run Running the application

'System::String ^' to 'LPCWSTR'

ぃ、小莉子 提交于 2019-11-30 08:20:45
问题 I want to convert System::String ^ to LPCWSTR . for FindFirstFile(LPCWSTR,WIN32_FIND_DATA); Please help. 回答1: The easiest way to do this in C++/CLI is to use pin_ptr : #include <vcclr.h> void CallFindFirstFile(System::String^ s) { WIN32_FIND_DATA data; pin_ptr<const wchar_t> wname = PtrToStringChars(s); FindFirstFile(wname, &data); } 回答2: To convert a System::String ot LPCWSTR in C++/CLI you can you use the Marshal::StringToHGlobalAnsi function to convert managed strings to unmanaged strings.

Destruction of Native Objects with Static Storage Duration

徘徊边缘 提交于 2019-11-30 08:03:35
2012-12-09 Summary: In a normal mixed-mode application global native C++ destructors run as finalizers. It's not possible to change that behavior or the associated timeout. A mixed-mode assembly DLL runs C++ constructors/destructors during DLL load/unload - exactly as a native DLL. Hosting the CLR in a native executable using the COM interface allows both the deconstructors to behave as in a native DLL (the behavior I desire) and setting the timeout for finalizers (an added bonus). As far as I can tell the above applies to at least Visual Studio 2008, 2010 and 2012. (Only tested with .NET 4)

Why does this generics scenario cause a TypeLoadException?

ⅰ亾dé卋堺 提交于 2019-11-30 08:02:23
问题 This got a bit long-winded, so here's the quick version: Why does this cause a runtime TypeLoadException? (And should the compiler prevent me from doing it?) interface I { void Foo<T>(); } class C<T1> { public void Foo<T2>() where T2 : T1 { } } class D : C<System.Object>, I { } The exception occurs if you try to instantiate D. Longer, more exploratory version: Consider: interface I { void Foo<T>(); } class C<T1> { public void Foo<T2>() where T2 : T1 { } } class some_other_class { } class D :

SecurityException: ECall methods must be packaged into a system module

我是研究僧i 提交于 2019-11-30 07:45:07
问题 I have a (C#) function similar to the following. private static bool SpecialCase = false; public void Foo() { if (SpecialCase) { InternalMethod(); return; } Console.WriteLine(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void InternalMethod(); When I execute this with the .NET Framework 4 inside the debugger, the method successfully prints blank line to the console and returns. When I execute it outside the debugger, it throws an exception with the following message:

CLR Sync Block Address

泪湿孤枕 提交于 2019-11-30 07:45:06
When I do: public class Employee { public int exp; } class Program { static void Main(string[] args) { Employee o1 = new Employee(); o1.exp = 3; lock (o1) { //I am here } } } and get memory of o1 (address is 0x022cf940): I realized couple of things mentioned below: Green rectangle is sync block, which is 12 Blue rectangle is 4 byte address of type Red rectangle is 4 byte integer, which is 3; Question: Where is the space of sync blocks and how can I find it? What does "12" stand for? The sync block has more than one use. It can store the value of Object.GetHashCode() so that an object always

Does a Silverlight memory profiler exist?

坚强是说给别人听的谎言 提交于 2019-11-30 07:29:00
问题 CLR profiler does not seem to work with the Silverlight CLR. Does another memory profiler exist? 回答1: Doesn't seem to be one available yet. However, as recommended in this forum thread, you can convert your Silverlight app to a WPF application and profile that: There is no tool as of now but as a workaround you can easily create a desktop (WPF) version of your Silverlight client from the same code base and few tweaks (refer Scot's blog for an example on this - http://weblogs.asp.net/scottgu

What is LINQ Actually Compiled To?

最后都变了- 提交于 2019-11-30 07:22:22
Background The background for this is that I had a recent conversation in the comments with another clearly knowledgeable user about how LINQ is compiled. I first "summarized" and said LINQ was compiled to a for loop. While this isn't correct, my understanding from other stacks such as this one is that the LINQ query is compiled to a lambda with a loop inside of it. This is then called when the variable is enumerated for the first time (after which the results are stored). The other user said that LINQ takes additional optimizations such as hashing. I couldn't find any supporting documentation

Accuracy of Math.Sin() and Math.Cos() in C#

荒凉一梦 提交于 2019-11-30 07:15:04
问题 I am terribly annoyed by the inaccuracy of the intrinsic trig functions in the CLR. It is well know that Math.Sin(Math.PI)=0.00000000000000012246063538223773 instead of 0. Something similar happens with Math.Cos(Math.PI/2) . But when I am doing a long series of calculations that on special cases evaluate to Math.Sin(Math.PI/2+x)-Math.Cos(x) and the result is zero for x=0.2, but not zero for x=0.1 (try it). Another issue is when the argument is a large number, the inaccuracy gets

CLR/CLI linker fails with error LNK2022 - Custom attributes are not consistent

拟墨画扇 提交于 2019-11-30 07:09:04
问题 Environment: Visual Studio 10, CLR/CLI Class Library project, built with Platform Toolset v100 , targeting framework version v3.5 . I am aware that this question was already asked here, but I did not find an answer that solved the problem for my case, so bringing this up again. While building a CLR/CLI Class Library (DLL) project the linker is failing with the following errors: MSVCMRT.lib(managdeh.obj) : error LNK2022: metadata operation failed (80131195) : Custom attributes are not