Using 'VS2010 Parallel Patterns Library' in VC++ - winforms

I have created a vc++ windows form application (VS 2010) and when I tried to include ppl.h (Parallel Patterns Library) I got the following compile error.
Error: Concurrency Runtime is not supported when compiling /clr. c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\concrt.h 27"
I want to use "parallel_for" algorithm in my program which is provided by 'VS 2010 Parallel Patterns Library'.
Can anyone tell me how to overcome the above problem and how to use 'Parallel Patterns Library' inside a windows forms application?

You appear to be writing a WinForms managed project in C++/CLI (why?...). In the managed world there is the the Task Parallel Library (TPL) and its System::Threading::Tasks::Parallel::For. You don't have to (can't) use PPL in a project targeting the clr, at least not in the managed part of it. Are you working on a mixed (managed/unmanaged) interoperability project? If so, separate managed and native parts properly. Then, use PPL inside native component and TPL inside managed components. Have a look at this blog entry, for example.

Related

WinSDK 7.1: Getting Started with the Windows SDK Tools for Native Windows app development?

I finally was able to successfully install the Windows SDK tools (v.7.1) on my Windows Vista system. I already had the GCC compiler installed and that is what I currently use to compile C code.
Where do I find the documentation for the WinSDK and how should I go about including it in GCC?
I couldn't find any explanations in the release notes or anything. However, if you can find something that explains it, feel free to give me a link.
This might sound weird to you, but you didn't need to download any separate Windows SDK to develop for Windows, because Visual Studio, and MingW/GCC, and others, already commonly include all that most people would need. (Some people would say, that Visual Studio and other tools, ship with their own version of the SDK, but I think that's merely confusing the issue further.)
You need Visual Studio first. And maybe, some day later, you might want to add the Windows SDK add on to it, but it is not intended to be used by itself, or in combination with GCC.
Basically, some of the SDK content duplicates stuff that is already included in Visual C++ and Visual Studio and some of it is additional tools like WinDbg.
Let me explain. The Windows SDK is indeed, useful for doing certain things in Windows that beginners are unlikely to need to do. For example, if you need to integrate with some specialized APIs, the Windows SDK contains a lot of documentation, examples, and a more complete set of header files that weren't included in Visual Studio because they're less frequently used APIs. The core API headers and documentation for Windows are already in Visual Studio, so technically, Visual Studio already contains the core SDK, and the so called SDK is an "auxiliary SDK", or a "low level SDK for purists, advanced users, and certain kinds of systems or native-level programming", but not needed, for most typical end-user applications development.
But if you want to learn Win32 native programming using C or C++, or you just want to write native Windows applications you PROBABLY don't need anything that comes in the SDK, and even then you need Visual Studio first, and the SDK second. Let me explain:
Many tools that let you write pure native Windows applications, provide higher level APIs, including Visual Studio, which gives you MFC or ATL. None of those tools need the SDK to work. The SDK, so called, is more of a "extra crap that we don't ship with visual studio because hardly anybody needs it", which Microsoft abbreviated to SDK. I know. Weird.
You don't need the SDK at all if you intend to use GCC. If you want to write an application for Windows in bare C or bare C++, you can just install mingw if you insist on using gcc and working from the command line.
The normal way to write native applications is to use the free Microsoft Visual C++ Express edition, and you can use it to write either C or C++ apps, and it includes the header files and libraries you need to write almost any native windows application feature you need, without any need for the SDK. Visual Studio is a nice modern IDE, and lots of convenient cool features like code completion and so on. The SDK you downloaded doesn't contain any of that.
Anything you do need to know about the raw Win32 APIs you can learn using the Web format of the MSDN documentation, or the help in Visual Studio. The basic Windows APIs like WinCreateWindow, are documented already in the Visual Studio help and MSDN help, and you don't need the SDK docs for most of the core windows APIs.
If you're just getting started, can I suggest you should just go get the free (but not open source) Visual Studio 2010 Express. That's the recommended way to get started, not the SDK.
I'm quite sure that the Windows 7 SDK that you downloaded is not intended for use with GCC anyways, and if you need a version of windows header files that work with a Gnu C/C++ compiler, any basic Win32 APIs like GDI and the basic Windowing API stuff is already bundled in mingw version of gcc.
You might also want to know about the DDK, which is like the SDK but which is oriented towards Device Driver and native NT-mode development.

CUDA integration with Windows Forms/WPF

Currently I have a console application, which is fine for me, but not for others. I need to create a GUI. I am developing for Windows 7 using Visual Studio 2010 and CUDA 3.2 build customizations.
Can I simply create a GUI in Windows Forms / WPF and then just state an extern "C" function, that will be resolved to a function calling a CUDA kernel? I tried to do so just now and I had a lot of compilation errors, including some CLR stuff. After a quick googling I have the impression, that it isn't as simple as it seemed.
-- edit
The generalized question is: how to include CUDA code in C++ Windows Forms / WPF application?
My partner and I had the same problem. We decided to write GUI in C# Windows Forms because of simplicity. However, we couldn't find any way of using CUDA in the same project (not even for Managed C++). There might be some way of doing it, but here is our solution: we created another project which was written in native c++ and produced dll file. Then, we used P/Invoke (Platform Invoke) in C# so, that we could call exported functions from dll. In the dll, there should be kernel and some device functions, but you should create another function which calls kernel and which will be exported. You can google P/Invoke and find out how to import native c++ functions from dll to c# application.
If you're using Visual Studio 2010, you can get started by downloading Cuda Toolkit v4.2 and then downloading CudaFy.net. A search for each on google will get you to the correct pages. Then you make sure nvcc is running. It is necessary to compile C# code into low level (cuda) code. You can then download sample apps to test how they work. You can start here

Usage of dlib library in Visual Studio 2010

I would like to ask for help in using dlib for my little thesis project. Specifically, I need to use the BOBYQA optimisation routine.
I am writing the project in MS Visual Studio 2010 Express in C language. I have zero experience in using libraries such as dlib and I don't have any idea what a makefile is and how to write one.
I have found a little hint here but due to my lack of experience in the matter, I just can't figure out how to compile and make use of dlib in my code.
I would like to ask for a step by step instruction how to incorporate dlib into my code, i.e.:
where exactly should I extract the dlib folder from the zip file?
should I add some files to the Visual Studio project?
are there any other problems I am not yet aware of?
I would also be very grateful for a simple example code of usage (my function to be optimised has 6 parameters).
If you are using visual studio then you don't have to use makefiles. You can create your project just like you normally would. Then to use dlib all you have to do is add dlib/all/source.cpp to your project and add the folder containing the dlib folder into your include search path. If you only use BOBYQA then you don't even have to add dlib/all/source.cpp.
If this is your first time using visual studio and you are getting hung up on how to create the project then I would suggest using CMake. It's very easy to use and it will setup an appropriate visual studio project for you automatically. Moreover, there is an example application which comes with dlib examples/optimization_ex.cpp which shows how to call BOBYQA and this example can be built using cmake with the following commands:
cd examples
mkdir build
cd build
cmake ..
Then you should find a visual studio project inside the build folder all setup and ready to go. It will be setup to build all the dlib examples. If you edit the CMakeLists.txt file in the examples folders you can remove examples you aren't interested in.
I tried two methods (1) and (2) under but it wasn't the intention of Dlib. The method (3) looks like working at this moment.
There is an example in Visual Studio 2013 at How to setup Dlib with Visual Studio 2013 without CMake?.
The difference in 2010 version, you have to use Property -> Configuration Properties -> (1) VC++ Directories or (2) C/C++ -> General
Regarding the source.cpp file, I just added on Source Files.
The method that I successfully applied is (so far)
(3) #include "dlib/image_processing/frontal_face_detector.h"
The dlib folder should be located in current source directory (Where does Visual Studio look for C++ header files? and https://msdn.microsoft.com/en-us/library/36k2cdd4(v=VS.100).aspx for details)

How do I compile C++/CLI code for Silverlight?

I have a C++/CLI library that I would like to use in a Silverlight application. It is supposed to be possible to write code for Silverlight in any .NET language, but so far I've only worked out how to compile C#. Silverlight does not seem to be able to use DLLs compiled for .NET.
I'm using Visual Studio 2010 and Silverlight 4. The only new projects available for Silverlight are C# projects. Porting the code to C# is not a practical option.
How do I compile C++/CLI code for Silverlight?
I think I may have gotten a VS2010 C++/CLI class library project to build with references to (only) Silverlight assemblies.
Update
Ok, it is possible. But it is not nice.
First, you must convince the C++ compiler to NOT load the .NET Framework, using an undocumented compiler switch. But that's not the worst part.
Set your C++/CLI project "Common Language Runtime Support" to /clr:safe
Next, under References, remove all references.
Next, in the C++/CLI project properties, under C++ > Command Line, enter /d1clr:nomscorlib /FU"C:\Program Files (x86)\Microsoft Silverlight\4.0.50917.0\mscorlib.dll"
Now, save the project and exit Visual Studio. Open the .vcxproj in a text editor, and change the framework version setting. You want it to be the same as a C# Silverlight project:
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
Now, reopen Visual Studio, and build the project. You'll get an error because the compiler auto-generated a file with #using<mscorlib> and the search path finds the .NET Framework version first.
Silverlight,Version=v4.0.AssemblyAttributes.cpp(1): fatal error C1197: cannot reference 'c:\windows\microsoft.net\framework\v4.0.30319\mscorlib.dll' as the program has already referenced 'c:\program files (x86)\microsoft silverlight\4.0.50917.0\mscorlib.dll'
Double-click the error to open the auto-generated file. Replace the path-less reference with e.g. (here's where you put your references, not in the project properties)
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\mscorlib.dll>
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\System.dll>
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\System.Core.dll>
Luckily, the compiler leaves your changes in-place. So you should be good as long as no one cleans your temp directory.
Building should now succeed.
Then, you need to go add the DLL created by the C++/CLI project to your Silverlight application. Note that you can't set up a project reference, because VS2010 still isn't convinced that the C++/CLI is a Silverlight project. So you'll have to browse and add the reference as an assembly file. (And it won't automatically switch between Debug and Release to match the Silverlight application).
Final Notes
I got it to run an empty Silverlight application in Debug mode and stop at a breakpoint in the middle of C++/CLI code. Also the C++/CLI code successfully returned a value to C# and the local variable in C# received the correct value. So I guess it's working.
I went through a bunch more steps trying to make this work, but I don't think they affected the outcome. If you run into errors, though, let me know and I'll try to figure out what I omitted from this answer.
Ben Voigt, thanks for this, it worked for me too.
Also, if your C++ code does anything that is specific to the C++ language (i.e. not entirely IL portable) like using stack semantics for an array, you'll get the following error:
could not find assembly 'Microsoft.VisualC.dll' etc.
If you recompile with the full .NET Framework and then dump the IL code, you'll find references to "''.$ArrayType$$$BY06$$CB_W modopt" or something similar. This tells you where to change the code.
I found that after I installed the Silverlight SDK and it got added to "\Program Files(x86)\Reference Assemblies" I did not have to go through all of Ben Voigt's steps, just changing the project file was enough.
Another note, you can also use:
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
if you want to target Windows Phone (install the SDK first).
Silverlight does not support native C++ libraries, nor any P/Invoke scenarios due to security concerns. If your library is pure .Net you might be able to decompile it with ILDASM and recompile for Silverlight with ILASM.
Silverlight is not a powerful development platform like .NET which is tightly integrated with operating system. First of all silverlight is supposed to run on any operating system, so there is no choice of Native API anywhere in silverlight.
Silverlight also does not support MSIL completely, so there is lot of problem in compiling and recomiping it at IL level.
Can you say more about what kind of C++/CLI code you have? Most Rich internet applications (Silverlight's target) do not include any of high powerful computation, instead they are plain simple HTML+JS alternatives. For powerful graphics, you can use Silverlight's PixelShadder support.
Reflector
What you can do alternatively is,
Compile your C++/CLI to regular .NET DLL, use Reflector to disassemble and generate C# source code from your dll, it may not be perfect, but you will have most of your logic converted back in C#.
I was able Ben Voigt's solution to work with some minor changes in Visual Studio 2013
Here is what I did different.
Unload the silverlight project that you want to reference it in. Right click and choose edit project.csproj
Copy the Target Framework Settings. For me this was
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
For the compiler switch /d1clr:nomscorlib This was not working for me. Also a reference to mscorlib for silverlight was automatically added to the complied output without specifying it on the command line options. This is how I got around it.
Open the project in Just Deompile
Load the Assembly Editor Plugin
Navigate the tree to the references
Delete the reference to the non silverlight mscorlib from the reflexil menu.
Right click on the top level of the tree for the assembly, and save as under the reflexil menu.
I haven't tested all of the functions, but the ones I have tested so far worked as expected.
Thank you Ben, your post has saved me a lot of time. I was thinking I was going to have to port my library:)

Sketchables in WPF with .NET 4, can't load System.Core version=2.0.5.0

Sketchflow newbie (couple days), WPF newbie (few weeks).
Workspace details:
WinXP, Visual Studio 2010 Ultimate, Expression Studio Ultimate (using Expression Blend 4 with SketchFlow). Downloaded the Sketchables 0.9 release and built a release version (Debug version is already built).
Issue details:
Start up Expression Blend 4, create a WPF Sketchflow project. Build it (successful). Add references to either the release or debug versions of the Sketchables library (in the Desktop, rather than the SL folder) and try to build again. The build fails with error:
Unknown build error, 'Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXX' or ore of its dependencies. The local assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
Now, I've seen some issues with a similar error, specifically a couple of issues where the problem was caused by trying to load a Silverlight control in a WPF project. However, I'm not knowledgeable enough to know if it's related. On a hunch, I tried a Silverlight project. Sure enough, building a Silverlight Sketchflow project and adding the Sketchables library builds cleanly.
So, the question is this: Does anyone have any ideas about what's actually causing this error within the Sketchables source, on pointers on how to track it down so I can work on it and get a clean library build for WPF?
Chuck's right. The Sketchables.Common dll is a Silverlight class library. Easy way to fix is to create a Sketchables.Common.WPF project and make it a regular class library. Copy over the classes from the SL library project, compile, and then change the reference in Sketchables.WPF to point to Sketchables.Common.WPF instead of Sketchables.Common. Your Blend project should now build.
A more advanced way is to share both Common projects to same files, but I won't go into that here. Search for share (link) files between projects and you'll find answers for that.
You have identified the cause of the problem, the assembly you are trying to reference in your WPF project was compiled for Silverlight (the 2.0.5.0 version number is a giveaway that it is Siverlight).
You might want to check with the author of the controls to see if there is a way to compile it for WPF.

Resources