Tag: visual studio

Entries for tag "visual studio", ordered from most recent. Entry count: 45.

Warning! Some information on this page is older than 3 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: > 1 2 3 4 ... 6 >

18:35
Tue
12
Apr 2011

Pointing to DLL Files in Visual CPP

When coding in Visual C++, we sometimes need to use some DLL libraries like FMOD, wxWidgets, Intel TBB etc. We download or build the library, setup directories to include and library files, finally #include <header.h>, #pragma comment(lib, "library.lib"), compile, run and...

Certainly our program also needs DLL file at runtime. Sure we have to attach it to the program when we distribute it, but do we really need to copy all these libraries to the Debug and Release subdirectories in our project? For a project run from Visual C++ to find required DLL files, they must be placed either in:

or in the PATH environmental variable. That's an option I've discovered yesterday. To use it in Visual C++, navigate to project properties / Configuration Properties / Debugging / Environment and set it to something like: PATH=$(PATH)$;C:\my_libraries\library_1\DLL_dir

If you do it correctly, your program launched from Visual C++ (with or without debugger - F5 or Ctrl+F5) will now be able to find required DLL libraries without need to copy them to your project directory.

Comments (7) | Tags: windows c++ visual studio | Author: Adam Sawicki | Share

19:42
Sat
12
Mar 2011

Static C++ Code Analysis with PVS-Studio

By the courtesy of its authors, I have a chance to evaluate PVS-Studio - a static code analyzer for C, C++ and C++0x. This commercial application is installed as a plugin in Visual Studio 2005/2008/2010. Fortunately I have Visual Studio 2008 Professional at home so I could try it with the code of my personal projects. PVS-Studio differs from other tools of this kind, like free Cppcheck, by finding three types of errors or warnings: general, related to OpenMP and 64-bit portability issues.

After opening my solution in Visual Studio, I choose a command from the special menu to analyze all the code.

A progressbar appears while PVS-Studio does the computations, utilizing almost 100% of all 4 CPU cores. Finally, a dockable panel appears with a list of found issues.

The general category warns about exact float comparison with == and stuff like that. It managed to find few places where I forgot the "&" character while passing a vector as const refefence parameter, rightly telling that it will cause "decreased performance". But its greatest find in my CommonLib library code was this unbelievable bug:

Some messages look funny. Should I code some general, abstract, portable, object-oriented, Alexandrescu-style template-based solution here just to avoid copying some code into several similar instructions? :)

I didn't check how the OpenMP validation works because I don't currently use this extension. As for 64-bit compatibility issues, I have lots of them - just because my code is not prepared to be compiled as 64-bit. PVS-Studio seem to do a good job pointing to places where fixed-length 32-bit integers are mixed with pointers, array indexing etc.

Overall, PVS-Studio looks like a good tool for C++ programmers who care about the quality of their code. Finding issues related to OpenMP and 64-bit compatibility can be something of a great value, if only you need such features.

Too bad that PVS-Studio, opposite to Cppcheck, is a Visual Studio plugin, not a standalone application, so it obviously requires you to have a commercial MSVS version and do not work with Express edition. But this is understandable - if you need OpenMP or 64-bit, you probably already use Visual Studio Professional or higher.

PVS-Studio analyzes C, C++ and C++0x. It doesn't work with C++/CLI language, but that's not a big flaw too. I use C++/CLI at work, but I can see it's quite unpopular, niche language. Its compilation or analysis would also be very difficult because it mixes all features from both native C++ and .NET. Even Microsoft didn't find resources to implement IntelliSense for C++/CLI in Visual Studio 2010.

Comments (16) | Tags: software engineering c++ tools visual studio | Author: Adam Sawicki | Share

20:14
Fri
11
Mar 2011

Visual Studio 2010 Service Pack 1 Released Yesterday

Yesterday Microsoft publicly released Visual Studio 2010 Service Pack 1. It is big (1.48 GB) and the installation takes quite long. It applies to all Visual Studio 2010 versions and components, including C++ Express, C# Express etc. Here is the list of changes and here is download link (you can find link to ISO file with offline installer at the bottom of that page). There are lots of fixes and improvements, but most of them apply to managed or web technologies like Silverlight. What's interesting for a C++ programmer is the addition of intrinsics to enable the extensions on the AMD and Intel new microprocessors that will be released next year - Intel AVX and AMD Bulldozer. Microsoft also claims to optimize and fix C++ compiler. Changelist mentions fixing lots of IDE crashes, including incompatibility with AMD CodeAnalyst.

Overall I think the new SP1 for VS2010 is worth installing, unless you have "Windows SDK for Windows 7 and .NET Framework 4" installed in your system. In that case an unsolved issue would happen so you should NOT install the Service Pack.

By the way: MSDN Library - the extensive documentation of C, C++, WinAPI, OpenGL, .NET and lots of other technologies - is available for free in form of an offline application for some time, but the latest version is MSDN Library for Visual Studio 2008 SP1. Do you know how to download some newer release? Or maybe that "Windows SDK" ships with it?

Comments (1) | Tags: c++ visual studio windows | Author: Adam Sawicki | Share

22:09
Tue
04
Jan 2011

Generating LIB File for DLL Library

I've been recently trying to use libVLC - functionality of great, codec-less VLC media player enclosed in form of DLL library. By the way I've came across a great article: GenerateLibFromDll and now I know how to generate LIB file for any DLL library! Here is detailed description of the problem:

When you have a DLL library you want to use in your C++ code, you may do it dynamically by using LoadLibrary and GetProcAddress functions from WinAPI, but it's more convenient to do it statically. But it's not enough to just #include signatures of library functions and use them in your project. You also need to link with some LIB file, even if the file is not a real static library with compiled code, but only a few-kilobyte-long list of imported functions. I believe that's just another flaw of C++ language, because other languages like for example C# don't need this even when importing functions from native DLL libraries.

If you have some SDK prepared for Visual C++ or compile the library by yourself, you also get the LIB file next to DLL. But if you have only the library, that article shows following steps to generate matching LIB:

1. From Start menu run "Visual Studio Command Prompt".

2. Execute command:

dumpbin /exports DLL_FILE.dll > DEF_FILE.def

This command prints some information about given DLL library in textual form to its standard output. We redirect it to a text file with DEF extension. But to make it real DEF file, we need to edit it.

3. Open DEF_FILE.def in some text editor and edit it to contain only the names of exported functions in form of:

EXPORTS
function_1_name
function_2_name
function_3_name
...

4. From the Visual Studio Command Prompt, execute another command:

lib /def:DEF_FILE.def /out:LIB_FILE.lib /machine:x86

And there you have it! The so much required LIB file generated from DLL library. You only need signatures of these functions with proper parameters and return values declared in some H header file and you can successfully use your DLL by linking with LIB file created by yourself :)

Comments (1) | Tags: visual studio c++ windows winapi | Author: Adam Sawicki | Share

00:16
Thu
06
May 2010

Compiling wxWidgets 2.9.0 in Visual C++ 2010 Express

NEW! (2011-02-18) I posted this entry months ago, wxWidgets keeps evolving and so it may no longer work. For building wxWidgets 2.9.1 in Visual C++ 2010, I now recommend you follow steps described here: Visual Studio C++ 2010 - Microsoft Visual C++ Guide - wiki.wxwidgets.org and here: Fixed wxWidgets 2.9.1 project files Visual Studio 2010 - forums.wxwidgets.org.

My old blog entry:

Today I wanted to compile wxWidgets library (version 2.9.0, which contains lots of interesting new features, including wxPropertyGrid control) under Visual C++ 2010 Express. A strange error appeared that stopped the build and explained nothing specific about the cause:

Microsoft.CppCommon.targets(151,5): error MSB6001: Invalid command line switch for "cmd.exe". The path is not of a legal form.

It took me some time to find a correct solution on Google, as many of them didn't work. (Copy setup.h file to some another directory? Made no difference in my case. Use the wx.dsw - project file for oldest IDE version? Didn't work either, my Visual says it cannot import such projects.)

Finally I've found this forum topic: http://forums.wxwidgets.org/viewtopic.php?t=27630. Sami Hamlaoui on 25th April 2010 posted a ZIP archive there containing converted and fixed project for Visual C++ 2010 that you can download and use to successfully build wxWidgets 2.9.0. Thanks for that!

After you build all projects in Debug and Release configuration, you just need to setup include and library paths in the IDE:

...\wxWidgets-2.9.0\include
...\wxWidgets-2.9.0\include\msvc

...\wxWidgets-2.9.0\lib\vc_lib

And finally you can use wxWidgets in your projects. To do that, you need to #include files such as and link with these libraries:

comctl32.lib, rpcrt4.lib, winmm.lib, advapi32.lib, wsock32.lib

and desired wx libraries like wxbase29ud.lib and wxmsw29ud_core.lib ("d" is for debug, use versions without "d" in Release configuration). Also remember that the new wxWidgets has no ASCII support, so you have to use Unicode character set.

Comments (3) | Tags: wxwidgets visual studio | Author: Adam Sawicki | Share

23:18
Thu
29
Apr 2010

DXGI Format Cheatsheet

Today I've prepared another small, single page cheat sheet related to DirectX 11:

DXGI_Format_Cheatsheet.pdf
DXGI_Format_Cheatsheet.odt

I've also solved my problem with Visual C++ 2010 Express that crashed every compilation on my computer. I've submitted this bug to Microsoft Connect, expecting that it may be because I have a 64-bit Windows 7 or because I also have Visual Studio 2008 Professional installed. But with the help from Microsoft I've figured out that it was just because of the AMD CodeAnalyst profiler. Uninstalling this program helped me so my VC2010 doesn't crash any more :D

Comments (1) | Tags: visual studio directx rendering | Author: Adam Sawicki | Share

20:06
Sun
27
Sep 2009

C primer for C++ programmers

I've never learnt pure C programming language, only C++. It does not mean I never use global variables or fopen function, but I it makes no sense for me to code in pure C when there is a C++ compiler available. But today I've decided to skim the classic book "The C Programming Language" by Brian W. Kernighan and Dennis Ritchie. Here is what I've found out:

You can actually code in C using Visual C++. To do this, you need to: (+) Create empty project, (+) Add a file with .c extension, (+) Enter project options, (+) Nagivate to Configuration Properties / C/C++ / Advanced, (+) Set "Compile As" to "Compile as C Code (/TC)".

The C language is similar to C++ except it lacks features such as:

There are some differences between C++ and C though. For example, you don't have to state type of function parameter or return type if you want to it to default to int. Following lines are equivalent:

int MyFunc1(int a, int b) { }
MyFunc2(a, b) { }

Compiler is generally more liberal when it comes to type checking and function calling. You can call function with more arguments than expected and it only generates warning. You can declare function with empty parameter list like MyFunc() which means unknown parameter list! To explicitly state that a function takes 0 parameters you have to write MyFunc(void).

Local variables can be defined only before any other statements in a block. You also cannot define a variable inside for loop. Example:

void Func(void)
{
  int a = 1; // OK
  Foo();
  int b = 2; // Error!
  {
    int c = 3; // OK
  }
}

C requires different syntax for using structures. If you define a structure like this:

struct Struct1 { int x; };

You have to prefix the name of this type with "struct" keyword each time you use it, just like this:

struct Struct1 *myObj;

But luckily typedef construct works in C, so the common solution to this problem is to use it like this:

typedef struct { int x; } Struct1;
...
Struct1 *myObj;

Comments (3) | Tags: c++ c visual studio | Author: Adam Sawicki | Share

20:24
Fri
25
Sep 2009

What is C++/CLI ?

Today I've started learning C++/CLI. It's a Microsoft technology that allows to write managed code for .NET platform in C++. But I can see it's not just a Microsoft idea to introduce custom language extensions. It's a massive piece of technology and even some C++ gurus were involved in its development, like Herb Sutter and Stanley Lippman. It's also approved as ECMA-372 standard.

So what exactly is C++/CLI? It's yet another language for .NET, just like C# or VB.NET, but it has the unique feature of being compatible with native C++ and being able to freely mix managed and unmanaged code.

For many people it may trigger some bad connotations with ugly syntax like __gc, __interface, __property etc., but that's not true. Syntax like this existed in Managed Extensions for C++, but C++/CLI is its new, improved version introduced in Visual Studio 2005.

Here is a screenshot from my first experiment, where I've created a property grid control from .NET next to a native Direct3D9 device initialized inside a panel control.

Just look at how old good native code can be mixed with managed one:

#include <d3dx9.h>
namespace ManagedCpp02 {
  using namespace System::Windows::Forms;

...

public:
  Form1()
  {
    PropertyGrid^ propertyGrid1 = gcnew PropertyGrid();
    ...
    IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);
    System::Diagnostics::Debug::Assert(d3d != nullptr);

Microsoft wasn't afraid to introduce new keywords and operators to the language. These designed to operate on managed code work next to the native ones, so you can define and use native and managed classes next to each other just like this:

class NativeClass { };

// Allocate from unmanaged heap - memory must be freed.
NativeClass *nPtr = new NativeClass();
delete nPtr;

ref class ManagedClass { };

// Allocate from managed heap - garbage collected.
ManagedClass ^mPtr = gcnew ManagedClass();

Comments (7) | Tags: c++ .net visual studio | Author: Adam Sawicki | Share

Pages: > 1 2 3 4 ... 6 >

STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2014 Adam Sawicki
Copyright © 2004-2014 Adam Sawicki