Showing posts with label visual studio. Show all posts
Showing posts with label visual studio. Show all posts

Wednesday, August 13, 2014

Lua in Visual Studio 2013


Build Lua for Windows using Visual Studio 2013 is a very straightforward task.

Project to build lua.exe:
  1. Create Project > Visual C++ > Empty Project
  2. Add Existing Item ...
    • Select all files under src except luac.c
  3. Project Property > All Configurations > Configuration Properties > C/C++ > Preprocessor > Preprocess Definitions, add: _CRT_SECURE_NO_WARNINGS

That is it.

To build luac.exe, simply repeat above steps. When selecting files, select all files, except lua.c.

Wednesday, August 28, 2013

OpenCV in Visual Studio 2012

It's surprisingly easy, just took about 15 minutes to see some example code running.

Steps to create the first OpenCV project using Visual Studio 2012
  1. Download: opencv.org > OpenCV for Windows
  2. Run the downloaded executable and decompress to d:\opencv (to help the examples below)
  3. Open Visual Studio 2012, create new project  Visual C++ > Win32 > Win32 Console Application
  4. Add "Include Directories": Project Properties > Configuration Properties > C/C++ > General > Additional Include Directories, add: D:\opencv\build\include
  5. Change to static link (optional, but if this is not done, then the library below need to be changed slightly): Project Properties > Configuration Properties > C/C++ > Code Generation > Runtime Library, select Multi-threaded (Debug)
  6. Add "Library Directories": Project Properties > Configuration Properties > Linker > General > Additional Library Directories, add:D:\opencv\build\x86\vc11\staticlib (or  D:\opencv\build\x86\vc11\lib if you don't want static link)
  7. Add lib files: Project Properties > Configuration Properties > Linker > Input >Additional Dependencies, add the libraries listed below. (Note: 1. comctl32 is a Windows library; 2. replace "246" to version number you have; 3. files ending with "d" is debug version, for release configuration, remove it)
IlmImfd.lib
libjasperd.lib
libjpegd.lib
libpngd.lib
libtiffd.lib
opencv_calib3d246d.lib
opencv_contrib246d.lib
opencv_core246d.lib
opencv_features2d246d.lib
opencv_flann246d.lib
opencv_gpu246d.lib
opencv_haartraining_engined.lib
opencv_highgui246d.lib
opencv_imgproc246d.lib
opencv_legacy246d.lib
opencv_ml246d.lib
opencv_nonfree246d.lib
opencv_objdetect246d.lib
opencv_ocl246d.lib
opencv_photo246d.lib
opencv_stitching246d.lib
opencv_superres246d.lib
opencv_ts246d.lib
opencv_video246d.lib
opencv_videostab246d.lib
zlibd.lib
comctl32.lib


Now, for a quick sanity check, run one of the sample code from opencv.org (the example I used is "Hough Circle Transform" http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html
 
Environment:
  • Windows 7
  • Visual Studio 2012
  • OpenCV 2.4.6

Monday, June 07, 2010

MSDN Library is Gone in Visual Studio 2010

I consider this another major setback in Visual Studio 2010.

Visual Studio 2010 come with a help system that is the worst since Visual Studio 2002.

Pros:
  • web-based, can be views in IE, as well as FireFox;
  • Encourage the use of better search engines like Google?
Cons:
  • No auto-complete search box;
  • Search result is worse than Google;
  • Left pane only has three fixed positions, cannot be resized or hidder;
To compensate the lack of auto-complete, I have stopped using my local help system and starting to use Google as my MSDN document explorer which did an excellent job.

Monday, April 12, 2010

Visaul Studio 2010 First Impression

It is officially released today. Tried a little bit and did not like it at all.

#1 problem: sluggish GUI response! No kidding. I thought Eclipse is slow, now I see something slower. No wonder it's release date was postponed to fix performance problem.

Of course, there is also problem finding my way around the IDE. Cannot seem to find a way to generate create script for my database project.

Friday, December 04, 2009

VC++ Redistributing

Symptom: I keep bumping into this issue. Once in a while my VC++ application does not even start on the targe computer.

Cause: The root cause is that the target computer does not have the VC++ library to support the applications. I works with server products, so I usually just install VC++ library once and expect all my future updates can be done by xcopy only. However, because I turned on auto-update on my development computer, my Visual Studio 2005 keep changing the library it is linked against. So once in a while xcopy deployment is broken.

Fix:
  • Sometimes it can be fixed by simply running Windows Update
  • Run VC++ Redistributable Package on the target computer. It is located here: %PROGDIR%\Microsoft Visual Studio 8\SDK\v2.0\Bootstrapper\Packages\
  • More options here: Choosing a Deployment Method

Monday, August 10, 2009

Server Explorer Missing

Symptom: Visual Studio 2005 Server Explorer is missing.
Reason: A while back, Visual Studio failed to load the server explorer at starup time, and showed a dialog to disable it. I guess I accidentally clicked "yes".

Solution: run this command in Visual Studio 2005 command line environment:
devenv /resetskippkgs

Thursday, July 24, 2008

C++/CLI Gotchas

C++/CLI is a hybrid monster. I am very green in the world of C++/CLI. Below are a few very stupid problems I have met.

Example 1: If you are writing unsafe code in C++/CLI with mixed managed code and unmanaged code, it proved to be more dangerous than plain old C++. Here are a few examples of using System::String together with char (C native data type). Without thorough understanding of the new .NET String class will create code that compiles perfectly but return unexpected results to you in run time.

String^ str = "";
char ch = 'a';
str += ch; //result: str="97", instead of "a", because it called ch.ToString()
str = gcnew String(&ch); //result: str="a@#!$%", because &ch is considered to be a string
str = gcnew String(&ch, 0, 1); //result: str="a" as expected.


Example 2: Visual Studio 2005 Debugger is a liar

int i;
i=1000;
... //all the code in between so that you forgot what is defined
for(int i=0; i < 3; i++)
{
...
}
int k = i++; //if you set a break here, Visual Studio Debugger will tell you i=4??!

I agree that the code above is stupid which is an artifact from trying to correct old VC++ code. But Debugger giving a wrong answer wouldn't help!

Monday, July 07, 2008

C++/CLI Warning C4945

Reason: This warning was generated because I referenced multiple C# projects in the C++/CLI project, and they all have "copy local" set to true.

Solution: Change reference to the C# projects, set all "copy local ..." properties to false.

A hotfix is available, which does not seem to be in SP1 as of 7/7/2008. So this fix probably will never be publicly available. This proves again C++/CLI is not on the top of TODO list for Visual Studio team.

Reference:
Microsoft KB 922271: http://support.microsoft.com/kb/922271

Wednesday, May 07, 2008

Convert VC++6 to VC++7 -- (2)

Below is a laundry list of the problems and solutions.

Compiler Error: fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory
Solution: change include from fsream.h to fstream, and add using namespace std;
Related problems: ios::nocreate and ios::noreplace are deprecated. ios::nocreate is replace by ios::in

CFile::ReadHuge() and CFile::WriteHuge() are obsolete. Use CFile::Read() and CFile::Write() instead.

Replace &afxChNil by empty string "".

Compiler Error:
  • error C2059: syntax error : '<'
  • error C2143: syntax error : missing ';' before '<'
  • error C2182: 'ConstructElements' : illegal use of type 'void'
  • error C2988: unrecognizable template declaration/definition
Solution: ConstructElements and DestructElements are deprecated. Remove definition of these functions. Ref: Microsoft KB 318734

WINVER default changed to 0x0501 (Windows XP). If your program still want to support Windows 2000, the the following line must be included in the project:
#define WINVER 0x0400

CPropetySheetEx, CPropertyPageEx are deprecated, they are included back to CPropertySheet and CPropertyPage.


CString s(45) no longer compiles. Because CString is changed to template based function with more constructors. This definition has ambiguous overloaded constructors. Change to CString s((TCHAR)45).



VC++7.1 has stricter type requirements. For example, conversion from HANDLE to int and uint is not allowed.

Compiler Error:
error C2668: 'sqrt' : ambiguous call to overloaded function
Solution:
sqrt, fabs, log and other CRT math functions support both double and float type now. An integer input to these functions will cause the error above.
Example:
int i = 10;
float f = sqrt(i); //error C2688
float f = sqrt((float)i); //compiles ok


Compiler Error:
error C2440: 'static_cast' : cannot convert from 'void (__thiscall XXXXXXXX::* )(void)' to 'void (__thiscall XXXXXX::* )(NMHDR *,LRESULT *)'
Solution:
Function signature of event handler OnKillfocus was changed from void Func(void) to void Func(NMHDR*, LRESULT*).

Thursday, May 01, 2008

Convert VC++6 to VC++7 -- (1)

VC++6 is a pretty solid product, which can still produce decent software in Windows XP. But Microsoft has decided to stop support for VC6 for about 2 years now. With the arrival of VS2008 and Windows Vista, it might finally be the time to convert those old projects that you still want to keep alive into a newer platform.

To start the conversion is really easy, just open the .dsp file in Visual Studio 2003. It will convert the project for you automatically, and generate the .vcproj and .sln files. If you are lucky, the next step is press F7 to build the solution and press F5 to run it, and you are done. Unfortunately, 90% of us will need to change the code to make it even compile. VC++6 is less standard compliant than VC++7 and there are some other breaking changes in VC++7.

This series will report problems I've seen when I convert a VC++6 project to VC++7 and some tips to help smooth the process.

Tip 1: for a project that is still actively maintained, during the conversion care must be taken so that changes do not break the software under VC++6. Use this to allow the code changes exists peacefully in VC++6:

#if _MSC_VER >=1500
//this is VC++9.0 or above
#elif _MSC_VER >= 1400
// this is VC++8.0
#elif _MSC_VER >= 1310
// this is VC++7.1
#elif _MSC_VER > 1300
// this is VC++7.0
#else
//assume VC++6
#endif

Friday, November 02, 2007

Aptana Out of Beta: 1.0 Released

Just noticed that Aptana has been out of beta. In the 2.0 era when everything stays "BETA" forever, this is a rare achievement.

In version 1.0, an open-source Community edition and a commercial Professional edition are available at the same time. The professional edition definitely deserves the nominal price it asked for. But as its name suggests, only professionals really have an urge for that edition. The free Community edition has enough features for 90 percent of its potential users.

My main IDE is still Visual Studio 2005. But the Javascript editor in Aptana is the best I ever seen. Its auto-complete is way better than even the latest Visual Studio 2008 Beta2.

Friday, September 28, 2007

Open Source File in Visual Studio 2005 with Auto-Complete

Just discovered this convenient feature of Visual Studio. It is not well publicized by Microsoft, but I believe it is one of those hidden gems of VS2005.

If you type ">open" followed with the file name in the "Command Windows" or "Find/Command Box", Visual Studio will search the whole solution and try to auto-complete the file name for you (see screenshot below).


There are 2 other approaches to open a source file in VS2005: 1. use the open file dialog; 2. expand the solution tree and double click on the file of interest.

This feature is very useful when you have solution with many projects. If you can remember the file's name, this feature allow you to open a file in under 10 seconds. With the other 2 approaches, you will have to browse up and down the project trees to find the file.

Thursday, July 12, 2007

Delay Load DLL and __HrLoadAllImportsForDll

Here are a few tips for delay loaded DLLs based on my experience with Visual Studio 2003 (Visual C++ 7.1)

  1. Delay load can be easily setup using the Visual Studio IDE by the following steps:
    • Open project property page: Linker > Input
    • In Additional Dependencies, add library: delayimp.lib;
    • In Delay Loaded DLLs, add all the DLLs you want to delay load.
      TIP #1: if you have more than one DLLs, the file names must be separated by ";", e.g.: rapi.dll;ceutil.dll. If you forget this, and try something like: rapi.dll ceutil.dll, then the linker will treat the whole string as the file name of a single file and fail to find a file with that name. There will be a subtle warning during build: LINK : warning LNK4199: /DELAYLOAD:rapi.dll ceutil.dll ignored; no imports found from rapi.dll ceutil.dll, which most likely will be ignored.
  2. Detect if the delay loaded DLLs exists on the host computer:
    The whole purpose of delay loaded DLLs is to allow our program to be more flexible. It can be loaded on computers that do not have certain DLLs, and it can choose to use those DLLs when they are present. So, there is always a need to know if we can load the delay loaded DLLs on the host computer. __HrLoadAllImportsForDll is the recommended function by MSDN documentation to do the job.
    TIP #2:Do not use __HrLoadAllImportsForDll because it use memcmp to compare DLL file names byte by byte which is too strict. File names in Windows system is not case sensitive, so the file names can be the same even if memcmp fails. This function will return module not found error code even when the DLL files are installed on host computer. I end up lift the implementation from delayhlp.cpp, and replace memcmp with _tcsicoll which is case insensitive.

Wednesday, February 21, 2007

The Best of Both Worlds (Visual Studio + Eclipse)

I use Visual Studio 6.0, 2003 and 2005 every day. But when it comes to write Javascript code, Visual Studio left a lot to be desired.

The emerge of Aptana plug-in make me seriously consider install Eclipse on my development computer. Here is what I do to take advantage of Aptana's superior JS edit functions in my Visual Studio web project.
1. add a simple eclipse project under my web application development folder (this will only add one file to my project: .project);
2. associate "*.aspx" to "Aptana HTML Editor", "*.css" to "Aptana CSS Editor", "*.js" to "Aptana JS Editor";
3. add my JS library to "Code Assistant Profiles";

From now on, no matter I am writing javascript in a .js file or .aspx file, I can use Eclipse. When I am working on C# code and ASP.NET controls, I go back to VS2005.

Please look at the screen-shot to see what Aptana can do: code auto-complete with documentation of parameters, tree structured outline of code file, code refactor, code snippets, to name a few. (a side note: also get "Firebug" for JS and CSS debugging in Firefox.)