Tag: windows

Entries for tag "windows", ordered from most recent. Entry count: 43.

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

Pages: > 1 2 3 4 5 6 >

# New jEdit Launcher - How to Install

20:12
Mon
17
Jan 2011

Writing programs in some managed technologies like Java or .NET instead of native C/C++ has many disadvantages. First and the most obvious one is smaller efficiency and greater memory consumption. That's why, for example, I prefer uTorrent over Azureus as BitTorrent client. Second flaw is harder access to native system API. That's why my friend Przemek created libraries for accessing new Windows 7 taskbar features from Java, Python and Qt code and sells them as his startup Strix Code.

Finally it's sometimes harder to integrate such programs with system shell. With .NET it's not the case because it creates EXE files so they can work as normal programs and even system services (I'm not sure about shell extensions and device drivers). With Java it's more difficult because there program is a JAR file. As jEdit is still my favourite text editor (second after Visual C++ of course), I was looking for a way to integrate it with Windows so it was my default editor for TXT and other text files. Recently I've found New jEdit Launcher - a package that serves this purpose very well, but unfortunately it's quite hard to setup. So in case you also use jEdit and look for a way to do it, here are the steps, checked under Windows XP as well as 7:

  1. Unpack New jEdit Launcher to some directory. Windows 7 causes lots of problems with Program Files so I prefer some other places, let's say "h:\Program_Files\New jEdit Launcher".
  2. Run command prompt ("cmd.exe"). On Windows 7 you must do it as Administrator, so open Start menu, type "cmd", right-click on the black "cmd.exe" icon and select "Run as administrator".
  3. From the command prompt, enter the "bin" subdirectory of New jEdit Launcher like this:
    > h:
    > cd "\Program_Files\New jEdit Launcher\bin"
  4. Call the magic command to register DLL file:
    > regsvr32 jeditext.dll
  5. Now launch registery editor through Start > Run > "regedit" and create entries as decribed in "New jEdit Launcher\README.html" documentation in "Installing" section.
  6. Second bunch of required registry entries (described in "Configuration" section) can be entered more conveniently, through "New jEdit Launcher\config\launcher.reg" file. Open this file in some text editor (Notepad or... jEdit :) and fix the paths to your Java JRE and jEdit directories. Enter path to "javaw.exe" not "java.exe" as the "Java Executable", because you don't want system console to be shown along with jEdit window. Values "jEdit Target" and "jEdit Working Directory" must point to the place where you have jEdit installed. Don't forget that all backslashes in these paths must be doubled, like "h:\\Program_Files\\jEdit 4.3.2\jedit.jar"!!!
  7. Now run this "launcher.reg" file through double-clicking on it. After confirming the warning/question, the registry entries should be created.
  8. Check if it works by running "New jEdit Launcher\bin\jedit.exe" file. jEdit should be started if it wasn't already running.
  9. You can create a shortcut to this "jedit.exe" file in your Start menu. This way you have a shortcut to jEdit with pretty icon instead of default Java one, as when linking directly to the "jedit.jar" file.
  10. Associate TXT and possibly other file types (extensions) with this "jedit.exe" program. It's done differently in Windows XP and 7 but generally you can find the appropriate configuration window it in the Control Panel. This way all text files will be opened by jEdit and they also (unfortunately) get jEdit icon.

Comments | #windows Share

# Generating LIB File for DLL Library

22:09
Tue
04
Jan 2011

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 | #visual studio #c++ #windows #winapi Share

# JustSendIt Prototype

20:00
Thu
07
Oct 2010

It's not a new idea for me, but last weekend it made me angry again that I couldn't send a file from my laptop to my desktop PC over my home local network. It may seem strange and it's really shocking to me because transferring data is the most fundamental thing we do when using any kind of network. But at the same time I don't know about any program that would simply allow me to send a file to a destination machine without being overly sophisticated or causing some strange technical problems. Here are solutions I've considered:

Network Neighbourhood - most natural way of passing files between Windows computers. I tried to share some folder on my laptop to access it from my PC and it didn't work, despite machines could contact each other via hostname or IP. Same happened when I shared a folder on my desktop and tried to enter it from my laptop. Well, we all know that this service often stop working randomly... Disabling Windows Firewall on both machines didn't help either.

FTP - I have FileZilla FTP server installed on both machines and I know it's quite good software, but that day I couldn't make it work. I could logon to the server from remote machine, but not to transfer any file. I tried different settings on client side like Passive Mode etc., but it changed nothing. I don't like the idea of using FTP to transfer files anyway, because why do I have to install the server, setup user accounts etc. when I just want to transfer a file? Besides, FTP protocol is known for causing technical problems because it opens separate connections on different ports to transfer data.

Other possibilities to send a file over a network are:

So finally I've used an USB flash memory stick to copy this file :P But after this, I've recalled my old idea about a simple program to transfer files over a network called JustSendIt [PL]. Then I decided to code a quick prototype of such program in C# and here it is: JustSendIt Prototype. It requires .NET Framework 4.0 to work.


If you have some computers at home or at work that you transfer files between or if you want to a file to your friend over the Internet, you are sure one of the computers have public IP or is set as DMZ so the other can connect to it, the way to send a file is:

  1. Run JustSendIt Prototype on both machines.
  2. On the receiving machine, go to Receive tab and press Load button to see your computer name and IP address..
  3. On the sending machine, go to Send tab, click Browse button to select a file to be sent, as well as enter the name or IP of the destination computer.
  4. On receiving machine, press the big Receive! buton to start waiting for incoming connections.
  5. On sending machine, press the big Send! button to connect to the second machine.
  6. On the receiving machine, a dialog pops-up to as user about the directory where to save the incoming file.
  7. After confirming this dialog, the file is transferred until finished.

I hope some day I'll find enough motivation to polish and finish this program :)

Comments | #networking #tools #windows Share

# Coding Windows Services in C++

18:31
Fri
01
Oct 2010

Services in Windows are like daemons in Linux - resident programs that work in background. I've recently learned how to code them in C++ using WinAPI. Here is a quick tutorial about this:

All the documentation you need to develop services can be found in MSDN Library. If you have it offline, go to: Win32 and COM Development / System Services / DLLs, Processes and Threads / SDK Documentation / DLLs, Processed, and Threads / Services. You can also read it online HERE. I talk only about native C and C++ code here, but services can also be written in .NET.

What are pros and cons of services, comparing to normal applications? Service can be automatically started with the system and work all the time, no matter if any user logs on and off. It can have extensive priviledges to access files on hard disk and the like, no matter what limitations do the logged-in user have. But service cannot interact directly with the user - it cannot show console or any window. So the only way for a service to do any input/output is to read some configuration files, write some log files or to communicate with some other client process ran by the user, e.g. via TCP socket connected to "localhost".

Service is written as a console application that uses special WinAPI functions to communicate with so called SCM - Service Control Manager. Example entry point routine looks like this:

// Standard console application entry point.
int main(int argc, char **argv)
{
    SERVICE_TABLE_ENTRY serviceTable[] = {
        { _T(""), &ServiceMain },
        { NULL, NULL }
    };
       
    if (StartServiceCtrlDispatcher(serviceTable))
        return 0;
    else if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
        return -1; // Program not started as a service.
    else
        return -2; // Other error.
}

StartServiceCtrlDispatcher is the first service-related function used here. It needs an array because a process can implement multiple different services, but I show only single-service process here. The function blocks for the entire execution time of working service and fails if program was run as normal application, not as a service. While service is working, a callback function is being executed, which I called ServiceMain here. It should initialize service and then execute all the code in loop until system wants to stop the service. You can also exit the function and thus stop the service at any time if you want (e.g. if some critical error occured).

// Main function to be executed as entire service code.
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
    // Must be called at start.
    g_ServiceStatusHandle = RegisterServiceCtrlHandlerEx(_T("SERVICE NAME"), &HandlerEx, NULL);
   
    // Startup code.
    ReportStatus(SERVICE_START_PENDING);
    g_StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    /* Here initialize service...
    Load configuration, acquire resources etc. */
    ReportStatus(SERVICE_RUNNING);

    /* Main service code
    Loop, do some work, block if nothing to do,
    wait or poll for g_StopEvent... */
    while (WaitForSingleObject(g_StopEvent, 3000) != WAIT_OBJECT_0)
    {
        // This sample service does "BEEP!" every 3 seconds.
        Beep(1000, 100);
    }

    ReportStatus(SERVICE_STOP_PENDING);
    /* Here finalize service...
    Save all unsaved data etc., but do it quickly.
    If g_SystemShutdown, you can skip freeing memory etc. */
    CloseHandle(g_StopEvent);
    ReportStatus(SERVICE_STOPPED);
}

RegisterServiceCtrlHandlerEx is a function that must be called first to register your application as a service, pass its name and a pointer to your control event handler function. Then you do some initialization, execute main service code in a loop and after it's time to stop it, do the cleanup and exit.

Service should report its state to the SCM with SetServiceStatus function. It can be called at any time and from any thread and informs the system about if your service is stopped, running, starting, stopping, paused etc. This function takes quite sophisticated SERVICE_STATUS structure, but I believe it can be simplified to three main cases which I enclosed in the following functions: ReportStatus reports basic status like SERVICE_STOPPED, SERVICE_RUNNING, SERVICE_START_PENDING or SERVICE_STOP_PENDING.

SERVICE_STATUS_HANDLE g_ServiceStatusHandle; 
HANDLE g_StopEvent;
DWORD g_CurrentState = 0;
bool g_SystemShutdown = false;

void ReportStatus(DWORD state)
{
    g_CurrentState = state;
    SERVICE_STATUS serviceStatus = {
        SERVICE_WIN32_OWN_PROCESS,
        g_CurrentState,
        state == SERVICE_START_PENDING ? 0 : SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN,
        NO_ERROR,
        0,
        0,
        0,
    };
    SetServiceStatus(g_ServiceStatusHandle, &serviceStatus);
}

Third member of the SERVICE_STATUS structure - dwControlsAccepted - indicates which events will be accepted by the service after this call. I want to accept events informing about system shutdown and allow user to stop the service. I could also pass SERVICE_ACCEPT_PAUSE_CONTINUE here, which means I supported pausing and resuming the service.

ReportProgressStatus function reports service status during initialization and finalization - SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING. I don't actually use it, but if the startup or shutdown of your service takes a lot of time, you should periodically report progress with this function. CheckPoint is simply a counter that should be incremented with each call, telling that service is making some progress. WaitHint is an estimated time it will take to finish initialization, finalization or to perform its next step. By default, system waits about 30 seconds for your service to start or stop and you should not exceed that without a good reason.

void ReportProgressStatus(DWORD state, DWORD checkPoint, DWORD waitHint)
{
    g_CurrentState = state;
    SERVICE_STATUS serviceStatus = {
        SERVICE_WIN32_OWN_PROCESS,
        g_CurrentState,
        state == SERVICE_START_PENDING ? 0 : SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN,
        NO_ERROR,
        0,
        checkPoint,
        waitHint,
    };
    SetServiceStatus(g_ServiceStatusHandle, &serviceStatus);
}

Finally, there is a way for a service to shutdown and inform the system that some critical error occured. To do this, report SERVICE_STOPPED and pass error code. The code will be saved along with information about service failture to the system event log.

void ReportErrorStatus(DWORD errorCode)
{
    g_CurrentState = SERVICE_STOPPED;
    SERVICE_STATUS serviceStatus = {
        SERVICE_WIN32_OWN_PROCESS,
        g_CurrentState,
        0,
        ERROR_SERVICE_SPECIFIC_ERROR,
        errorCode,
        0,
        0,
    };
    SetServiceStatus(g_ServiceStatusHandle, &serviceStatus);
}

HandlerEx is a function to handle events sent by the system to control your service - stop it, pause, inform about the system shutdown or simply query for current status. You must always call SetServiceStatus in this function. It can be executed in different thread, so you must synchronize it with the code in ServiceMain. I do this with g_StopEvent - an event that will be set when the service should exit.

// Handler for service control events.
DWORD WINAPI HandlerEx(DWORD control, DWORD eventType, void *eventData, void *context)
{
    switch (control)
    {
    // Entrie system is shutting down.
    case SERVICE_CONTROL_SHUTDOWN:
        g_SystemShutdown = true;
        // continue...
    // Service is being stopped.
    case SERVICE_CONTROL_STOP:
        ReportStatus(SERVICE_STOP_PENDING);
        SetEvent(g_StopEvent);
        break;
    // Ignoring all other events, but we must always report service status.
    default:
        ReportStatus(g_CurrentState);
        break;
    }
    return NO_ERROR;
}

That's all the code I wanted to show. Now, because service cannot be run as normal program, you must learn how to install and uninstall it. Fortunately there is a simple command line program for this distributed with Windows - sc. To install your service, enter following command (exactly like this, with "binPath=" SPACE "PATH"):

sc create SERVICE_NAME binPath= FULL_PATH_TO_EXE_FILE

To uninstall it:

sc delete SERVICE_NAME

To control your service - start it, stop it or query its status - use commands:

sc start SERVICE_NAME
sc stop SERVICE_NAME
sc query SERVICE_NAME

Or simply run Administrative Tools / Services (another way to access it is Start / Run / "services.msc").

Two kinds of command line arguments can be passed to a service. First are argc, argv parameters taken by main function. They come from a command line fixed during installation of the service. Second are argc, argv arguments taken by ServiceMain function. They are different - argv[0] is the service name and the rest are arguments that you passed as additional parameters when calling "sc start" command.

Of course there is more to be told on this subject. Service can depend on some other services, can be automatically started with the system or only on demand, can have priviledges of a selected user or one of standard ones, like "LocalSystem" (biggest priviledges on local system, the default), "LocalService" or "NetworkService". See MSDN Library for details.

Comments | #c++ #windows #winapi Share

# Deeper Look Inside Windows

21:38
Thu
01
Jul 2010

Typically Linux users spend much time dealing with details of their system while Windows users blame all errors on bad Microsoft and Bill Gates, especially nowadays as for more and more people computer usage shrinks only to a web browser. But sometimes it's nice and useful to look into the system, deeper than to the list of files on disk or installed programs in Control Panel / Add or remove programs. Here are some Windows applications that may help with that (use Google to find them by name):

Starting with tools that ship with Windows itself, we have:

More information about the system can be revealed with free programs, like:

Do you know any other tools like these or other types of system information that are worth seeing?

Comments | #windows Share

# SVN in My Windows Made Me Angry

16:41
Thu
11
Feb 2010

Today I had an unpleasant adventure with SVN. Although I'm now going to use Mercurial (with TortoiseHG client) for my home projects, as this whole distributed revision control systems looks quite promising, I wanted to checkout some SVN repository and it turned out to be much bigger problem than I expected.

The obvious solution is to install and use TortoiseSVN - great shell extension for Windows. Unfortunately it doesn't work in my 64-bit Windows 7. Setup succeeds, but then no new items appear in context menus for directories. I tried to install both 64-bit and 32-bit versions, two times, with restarting my computer. Nothing helped. I tried to disable read-only attribute for TortoiseSVN directory, give full permission to this directory for all users, maually run TSVNCache.exe (because it doesn't start automatically) and nothing helped. I also ensured shell extensions are successfully installed by using ShellExView. Google knows this problems, but not the solution.

So then I installed RapidSVN - a normal Windows SVN client. Such application seems even nicer for me than shell extension. But then another obstacle appeared: opening repository in RapidSVN failed with error message: rapidsvn Error: Error while updating filelist (Can't create tunnel: The system cannot find the file specified. ). I though: Fuuuu! After issues with new Windows version here come Linux-like issues with some command-line or config driven, small and independent programs that never smoothly work together. I knew it was probably because the repository I wanted to checkout have an URL starting with svn+ssh:// so the SVN client probably needs to create an SSH tunnel.

After some searching in Google I found a solution. I needed to download PuTTY package and set special environmental variable to point to the plink.exe program that, according to Google, work as SSH tunnel. This variable is named "SVN_SSH" and its value must be like "E:\\PuTTY\\plink.exe" - without quotes, but with these double backslashes! Here I was sure it had to come from the Linux/Unix world, noone other would come up with something like this :P

It seemed to work so I was a step further, but still I couldn't access the SVN repository. This time when checking out, an empty console appeared and freezed so the RapidSVN didn't go any further. I wanted to try some "easy" solution so I installed another windowed client - Qsvn, as well as console SVN client - SilkSVN, but it seemed to recognize and run this SSH tunnel and finally freeze in same situation. So after another Googling I've found this post, opened configuration file "C:\Users\MY_LOGIN\Application Data\Subversion\config" and inserted this line into it:

ssh = E:/PuTTY/plink.exe -l REPOSITORY_LOGIN -pw REPOSITORY_PASSWORD

It finally worked and I could access the repository, but it took me so much time that it made me really angry. I hope I'll live to see the day when there will be no such stupid problems with software. Meanwhile, now you can understand why do I always *very* carefully handle all errors in my code (check returned values, throw exceptions, write logs) - to always know exactly what, when, where and why went wrong, so no annoying things can happen like "context menu items don't show up and I don't know why" or "empty console window opens and freezes".

Comments | #svn #windows #software #tools #version control Share

# Adventures with Windows XP and Windows 7

18:07
Sun
22
Nov 2009

So I'm back after hardware upgrade and system reinstallation. What I want to write about today is my recent adventures with installing Windows. I've decided to install Windows 7 64-bit (as I believe it's already good and very promising platform which will soon become a standard) and Windows XP 32-bit (in case something I need wouldn't work in Win7, like the connection with my Mio palmtop).

I've installed Windows 7 first. While inside the installer, I've created an NTFS partition for that system, called "Win_7". Win7 created one additional 100 MB NTFS partition at the very beginning of my disk, named it "System Reserved" and didn't mount it as any drive letter. Oh well, maybe it's just needed for something...

Then I wanted to install old good Windows XP. Unfortunately WinXP SP2 setup doesn't recognize my SATA disk. I didn't want to switch it from native SATA (AHCI) to IDE emulation mode in BIOS as it degrades performance AFAIK. My motherboard manual and many other sources give a solution as a driver which has to be recorded on a... floppy disk and given to WinXP setup. And I don't even have a floppy disk drive!

Fortunately I've googled another solution. This article shows how to prepare your own "distribution" of Windows XP install CD with selected drivers and updates already integrated inside. All I had to do was to copy original install CD to my hard disk, download and unpack SATA/RAID drivers for my motherboard, install freeware nLite program and use it to burn new CD. It works perfectly! Now I have WinXP install CD which recognizes my SATA disk.

While installing XP, I've created another (third) NTFS partition. I named that partition "Win_XP" and set up WinXP on it. Everything went fine and the only strange thing was different naming of partitions in both systems (you can't change drive letter of the system partition).

But then I was unable to start my Win7 as WinXP installation overwritten MBR with its own, old bootloader without detecting Win7 and adding it to the boot menu. It's interesting that WinXP, although installed on the "Win_XP" partition (E:), placed its Boot.ini file on the "System Reserved" partition.

I tried to modify boot.ini to add Win7 to the menu, but nothing seemed to work. The WinXP boot manager simply isn't able to start Windows 7 and that's exactly what I've found when searching Google. Win7 has its own, new boot menu which has to be used to be able to boot this system.

To restore MBR of Windows 7:

Now, how to add WinXP entry to the Win7 boot menu? The new boot manager of Windows 7 is not such simple text file as boot.ini was, but it's a database stored in this invisible "System Reserved" partition. User can edit the menu using bcdedit command line tool (you must run Command Prompt as Administrator to use it), but there is another solution: a freeware application called EasyBCD. Not only it simplifies this task by providing GUI, but it's also able to switch MBR between XP and Vista/7 version and it also works in Windows XP! It seemed like I was almost there...

But unfortunately the Win7 boot menu sees partitions just like Win7 does, so the first partition - the one where WinXP placed its boot.ini file - was invisible to it. My solution (© Reg ;) was to run WinXP (by switching MBR to XP version), to copy files needed for booting - boot.ini, ntdetect.com, ntldr - from "System Reserved" to "Win_XP" partition and point WinXP entry in the 7 boot menu to the "Win_XP" partition (E:). Finally I could switch back to Win7 MBR with my boot menu working for both systems.

Comments | #windows Share

# Mounting Drives and Directories in Windows

17:27
Sat
10
Oct 2009

You don't have to use only drive letters C:, D:, E: and so on for subsequent disk partitions. Windows gives much freedom in managing drive letters and partitions, if you know how to do that.

First, you can change a drive letter for a hard disk partition or removable disk drive. For example, I like to have my DVD as drive X:. To do that:

Second, you can mount whole partition or drive in an existing, empty directory. To do that:

And finally, you can do the opposite - mount a directory as a separate drive. The way to do it is quite different, as it requires to use a console command:

subst s: d:\Dir\Subdir

To remove such drive, use the following command:

subst s: /D

Comments | #windows Share

Pages: > 1 2 3 4 5 6 >

STAT NO AD
[Stat] [STAT NO AD] [Download] [Dropbox] [pub] [Mirror] [Privacy policy]
Copyright © 2004-2018