Thursday, August 14, 2008

Regular expressions: Remove last appearance of some element

If you want to match A, B and C but don't want C to be the last element you can do it using this regular expression:



[ABC]+(?<!C)





Note that [ABC]+ can be mutch more complex then this is.

Wednesday, August 13, 2008

Binding ASP.NET TreeView to a DataSet or an ObjectDataSource

Excellent article:

http://www.varjabedian.net/archive/2008/04/22/binding-asp.net-treeview-to-a-dataset-or-an-objectdatasource.aspx

Wednesday, August 06, 2008

Monday, August 04, 2008

Retrieve local ip address


CStringArray straIPAddresses;


straIPAddresses.RemoveAll();

WSADATA wsa_Data;

int wsa_ReturnCode = WSAStartup(0x101,&wsa_Data);

char szHostName[255];

gethostname(szHostName, 255);

struct hostent *host_entry;

host_entry = gethostbyname(szHostName);

int nAdapter = 0;

while ( host_entry->h_addr_list[nAdapter] )

{

char * szLocalIP;

szLocalIP = inet_ntoa (*(struct in_addr *)host_entry->h_addr_list[nAdapter]);

nAdapter++;

straIPAddresses.Add(szLocalIP);

}

WSACleanup();


Saturday, August 02, 2008

Detect available serial ports

You can use class found at http://www.naughter.com/enumser.html to detect available serial ports on your PC. Class is using seven different methods to enumerate serial ports.

Monday, July 21, 2008

Remote Debugging

Sometimes you need to debug application on remote machine. To do that you need to copy files for remote debugging on to remote machine. You can find those files in:

c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger


Run msvsmon.exe on remote machine and set security.

In Visual Studio, in project settings, go to Configuration Properties Debugging, chose Remote Windows Debugger (from Debugger to launch), set other parameters and press F5.
If you have set all correctly, application on remote machine will be started.

Friday, June 27, 2008

Locate current opened file in solution explorer

To locate current opened file in solution explorer you can use this macro:


Sub LocateInSolutionExplorer()
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
End Sub

Tuesday, June 24, 2008

Convert std::string to std::wstring

// std::string -> std::wstring
std::string s("string");
std::wstring ws;
ws.assign(s.begin(), s.end());

// std::wstring -> std::string
std::wstring ws(L"wstring");
std::string s;
s.assign(ws.begin(), ws.end());

Monday, June 16, 2008

Add custom library or form in Visual Studio Macros

  1. Create custom class library in language that you prefer.
  2. In Build events Post build events add: copy "$(TargetPath)" "$(DevEnvDir)PublicAssemblies\"
  3. In macro from where you whant to use your custom library add reference to your class library
  4. You are now free to use your custom library in your macro