Friday, May 27, 2011

Disappeared Window Manager

I use Ubuntu 10.04 at home. I am a GNOME guy since the days of RHL 9. One day, suddenly, all of a sudden, the maximize, minimize and close icons on all my windows just disappeared. Just like that. Didnt know what hit me. I had to go to the menu item, and close it. Then Googling, I found out that there is this guy called "metacity", a window manager, who is incharge of these kinds of stuff in the GUI for GNOME. From this link, I found out how to give it a boot, and bring back my lifesavers.

All you had to do is:

1. Check if its already running
ps aux | grep metacity


2. Then, if its not (even if its running), just load it.
sudo metacity


3. If it gives an error like "Window manager warning: Screen 0 on display ":0.0" already has a window manager;", then just force it

 sudo metacity --replace


There is a catch here. this will occupy a terminal window. So, I'd suggest, you give the system a restart, if you arent into anything utterly serious.

I expertly went ahead and killed that process, and my whole GUI went for a toss. Nothing worked (except the mouse). So, I had to run to my second login screen, do a
kill -9 METACITY-PID
of the metacity manager, and restart it with
sudo metacity --display=:0.0 --replace


And then, after I had saved my documents, I restarted the system. All is well, that restarted well.


Source link

Friday, September 17, 2010

Disable Autorun for USB Pen drives and CD Drives

Disabling autorun for USB drives prevents a lot of virus from jumping into the system as most of the "small" guys use the AutoRun feature to trigger themselves. There is a way to disable it completely.

Click "Start / Run" and type "gpedit.msc". It should open a windows like the one below

(Click on it to open a bigger image).


In that go to the branch on the left hand side frame following the below path

"Local Computer Policy / Computer Configuration / Administrative Templates / System"

Clicking on "System" will list lots of items on the right window. One of them is "Turn Off Autoplay".

Double click on that, make sure to select "Enabled" radio button and on the list box below, select "All Drives".

This should disable Autorun in all usb and cd/dvd drives on the system.

Rebooting Mac

Mac has the uncanny habit of screwing itself up (atleast mine does) and then not telling the user what happened. Let me explain. All of a sudden, the initial grey screen comes up with the loading "rotator" thingy. And thats about it. Nothing more happens. And when I force shutdown and restart, it does not actually start from the beginning, meaning it does not do a "CHUNNNGGG" chime sound when restarting.

And again, the cloud was the Good Samaritan (who else is there). Pressing the keyboard combination of "Command(Apple)-Option-P-R" and holding it like that (NB: it needs some skill to hold this key combination) until the chime sounds twice should resolve the issue. But, my machine seems to be a bit more adamant than that. Even though I have "CHUNNNG"ed it, it still stops are the rotator screen. :-( Will update the post as and when I find a solution.

Source: TUAW

Thursday, April 29, 2010

Control characters in source file after ftp

<p align="justify">My friend had a problem with a Linux file. he had ftp'd a file from windows into Linux. Now, every line in that file has a ^M at its end. He wanted a way to avoid it, and/or remove the control characters from such files.

Browsing thru the web, there were multiple answers provided.

1. While uploading via ftp, use the ASCII mode, not the binary mode. This will translate the line ends properly. Binary mode is to be used for programs and archive files only (like zip, tar, etc..)
2. dos2unix (and its complementary unix2dos utility)
3. cat file | tr -d "\r" > newfile
4. sed 's/.$//' infile.txt > outfile.txt
5. col -bx < oldfile > newfile

Disclaimer: I have not tried this in any of the ways mentioned. I am just listing it for easy access only.</p>

Saturday, November 14, 2009

xp disk defragmenter does not analyze or defrag

My system (as usual) was starting too sluggishly for my liking to start the defragmentation. But, when I clicked "Analyze" or "Defrag", nothing happened. I mean, absolutely nothing. No error messages. Not even a warning. Something in the lines of "hey moron, you are doing something wrong here" would have been more appropriate. Well, like any dumb user, I entered the realm of Google, and ended up triggering the defrag.exe from the command prompt. There, I got something. "Windows cannot connect to the Disk Defragmenter engine". Now, if only I KNEW where and how the hell I kick start that damn engine. Once again Larry ewing's nerds helped me from yonder. It seemed that the "DCOM Server Process Launcher" was not running. It had to be kick started for the defragger to skate board on. So, I clicked "Start/Run" and typed in "services.msc" and opened the services window. (the more normal way would be to go to My Computer, right click on it, Manage, and click services, bah, am a lazy guy). Kick started it, (but it acutally didnt. I had to set the mode to "Automatic" and restart the system). Then, I launched our guy, and voila, we are up and running.... Okay, he is working RIGHT NOW. Off I go. Tata

Thursday, August 06, 2009

Mouse scroll in VB6 IDE

VB6 had the dubious distinction of the only IDE without a supported mouse scroll in the code window. Fortunately, in true Microsoft style, they have given workarounds and patches to overcome this disability. Check this Microsoft's link on how to enable/activate mouse scrolling in the VB IDE

Friday, June 19, 2009

How to Enable Tooltip for Dialog Controls

Lets get things straight. You want the user to be more dumb and want him/her to get an idea of what he wants to do with all the controls on his screen without reading the help file? Then dive right in. Else, Ciao. Have a good day.



Step 1: Enable the tooltip command using the command EnableToolTips (TRUE). Ideal location to include this line would be in your class' init routine CYourClass::InitDialog.

Step 2: Windows sends the tooltip related controls in TTN_NEEDTEXT message. We need to handle this. Add the following code to enable your handler in the MessageMap function

BEGIN_MESSAGE_MAP(CMyClassDlg, CDialog)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify)
END_MESSAGE_MAP()


Step 3: Declare the handler function in your header.
afx_msg bool OnToolTipNotify( UINT id, NMHDR* pNMHDR, 
LRESULT* pResult );


Step 4: We are near. Just add then handler code in your cpp. Below is a sample of the same

bool CMyClassDlg::OnToolTipNotify( 
UINT id, NMHDR* pNMHDR, LRESULT* pResult )
{
// Get the tooltip structure.
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;

// Actually the idFrom holds Control's handle.
UINT CtrlHandle = pNMHDR->idFrom;

// Check once again that the
// idFrom holds handle itself.
if (pTTT->uFlags & TTF_IDISHWND)
{
// Get the control's ID.
UINT nID = ::GetDlgCtrlID( HWND( CtrlHandle ));

// Now you have the ID. depends on control,
// set your tooltip message.
switch( nID )
{
case ID_BUTTON1:
// Set the tooltip text.
pTTT->lpszText = _T("First Button");
break;

case ID_EDIT1:
// Set the tooltip text.
pTTT->lpszText = _T("First Edit Box");
break;

default:
// Set the tooltip text.
pTTT->lpszText = _T("Tooltips everywhere!!!");
break;
}

return TRUE;
}

// Not handled.
return FALSE;
}

Friday, October 17, 2008

No Help inside VC IDE

I recently implemented the Help feature for an application. But, pressing F1 key or clicking on the corresponding button did not work out at all. No help window popped up. After much googling, I fell on this. This does not work when the application is run from inside the VC IDE. So, I went to the Debug directory and launched the application from there. Voila, help worked. But, still when pressing F1 key, I was getting an error message stating the the HLP file was missing. So, in order to disable that, the ON_WM_HELPINFO needed to be handled. Once that is done, the unwanted error message stops showing its ugly face.

Thursday, September 25, 2008

Adding accelerator keys in VC

A microsoft support link shows in a pretty straightforward way how to implement an accelrator key. Have a go

Getting the hyper link to work in CRichEditCtrl

Trying to get a mouse click to work in RichEdit and not succeeding? I faced a similar issue and ended up with this flow

Set the SetEventMask for your m_MyRichEdit (this is my control variable for the CRichEditCtrl class) to understand links
m_MyRichEdit.SetEventMask( \
m_MyRichEdit.GetEventMask() | ENM_MOUSEEVENTS)
Now, add a override function for OnNotify in your class. In the .h file, add
afx_msg BOOL OnNotify (WPARAM wParam, \
LPARAM lParam, LRESULT *pResult);
Add the corresponding function similar to the one below
BOOL CParentDlg:: OnNotify (WPARAM wParam, LPARAM lParam, LRESULT * pResult) 
{

if (LOWORD (wParam) == IDC_RICHEDIT)
{
MSGFILTER * mf = (MSGFILTER *) lParam;
switch (mf-> msg)
{
case WM_LBUTTONUP:
ENLINK *p_EnLink;
p_EnLink = (ENLINK *)lParam;
m_MyRichEdit.SetSel (p_EnLink->chrg);
CString szLinkString = m_RichEdit.GetSelText ();
break;
)
)

return CDialog:: OnNotify (wParam, lParam, pResult);
)
Now, your szLinkString will have the data you need to manipulate. You can use this with the ShellExecute function to popup whatever you want.

On, by the way, you need to add RTF content if you intend to make that identifiable. It goes something like
CString szT = "{\\rtf1 \\par http " + szAppendString + " \\par}";
My above code will popup a http link using which I Open it in ShellExecute

Tuesday, September 02, 2008

Auto Complete in VC++ 6

When the "Auto Complete" (Complete Word) feature of VC (6 in my case) stops working, all you need to do is
1. close the project
2. Go to the project directory
3. Remove the .ncb file in the directory
4. Re-open the project

Voila, its working !!!
(atleast it started working for me).

Ensoy

Wednesday, August 27, 2008

CTreeCtrl and Checkboxes

While working with CTreeCtrl with checkboxes, I came across these 2 issues

1. You would have set TVS_CHECKBOXES in the .rc file. Then during InitDialog, if
m_myTreeVar.SetCheck( hTreeWnd, TRUE)

is called, it will not work as expected. But, when the same line is called anywhere else later, it will work. To workaround this issue, the following two lines need to be added to simulate a removal/addition of the checkboxes flag at the beginning of InitDialog

m_myTree.ModifyStyle( TVS_CHECKBOXES, 0 );
m_myTree.ModifyStyle( 0, TVS_CHECKBOXES );

2. With the CTreeCtrl, when trying to get the handle of a "clicked" item using hittest, I fell on an issue that it was returning the handle of the NEXT item on the list and not the one which i clicked. The code is as below
 DWORD pos = GetMessagePos();
CPoint pt(LOWORD(pos), HIWORD(pos));
ScreenToClient(&pt);
UINT uFlags = 0;
HTREEITEM hItem = m_MainTree.HitTest(pt, &uFlags);


The above code returned the handle of the next list item from the one clicked. To fix the same, I just modified the "ScreenToClient" as below
m_myTree.ScreenToClient(&pt); 

and Voila!!! it worked!

Wednesday, May 28, 2008

Writing VB.Net app with c or C++ Dll

Added for my reconnaissance.

Step 1. Create a VC project (I used VC++ 6). An empty win32 DLL. The main things are below

Step 1a: For all the functions that needs to be exported, add "_stdcall" before their declaration and definition. For ex, I added
long _stdcall MyExportedFunction(int myinteger)

One VERY IMPORTANT thing to note. The return has to be something other than void as this causes an incompatibility between the DLL and the VB and the application will end up crashing.

Step 1b: Make sure to have a .def added to the VC project. The contents of my def file are


 MyVCLibrary.def : Declares the module parameters for the DLL.
LIBRARY "MyVCLibrary"
DESCRIPTION 'My VC Library DLL'

EXPORTS
; Explicit exports can go here
MyExportedFunction
My exported function prototype is
long _stdcall MyExportedFunction(int);

Now, thats it for the DLL. Compile and get it ready.

Step 2a: Create the VB.NET (I used Visual Studio 2008). In the Form Class, create a declaration as below (in a single line)


Declare Function MyExportedFunction Lib 
"MyVCLibrary.dll" (ByVal pcFilePath As Integer
) As Long

Step 2b: Call the function as below
Call MyExportedFunction(10)
. That's about pretty much to it.

Wednesday, April 09, 2008

Some Linux Tips

This is mainly from my experience in Red hat Linux 9.0 and Fedora Core (from as far back as 5 years). I have used the double quotes just to highlight the phrase to be typed on the command line. Remove the double quotes and type the commands.

How to check free space in my hard disk?

Typing "free" in your terminal command line lists out all the hard drives details.



"How do I find out the location of an executable file?

which <executable>" will show you the location from which it is called.



How can shutdown my machine with a command/shell script?

Create a shell script and put the following line in it (without the double quotes)

"shutdown -h now"

Executing this shell script shuts down your machine.



How do I mount a network shared folder in my LAN ?

For example sake, assume the network machine name is "nwsys" and the shared folder in that is "shared". Now create a directory to which you want to associate the shared folder to. Lets assume you create a folder "myshare" under "root" directory. Now the command will be

"smbmount //nwsys/shared /root/myshare -o username=<username>,workgroup=<workgroup>"

If all directories exist, you would be asked for the password, enter it. If no error message pops up, you are through.

From FC5, smbfs is removed and the command needs to modified to this:

mount -t cifs //nwsys/shared /root/myshare -o 
username=<myname>,workgroup=<myworkgroup>



I  had disconnected my LAN cable and reconnected it. Now, I am not able to connect to network machines through nautilius.

Close all nautilius windows and execute the following command at the command prompt

"killall nautilius"

This restarts the nautilius service and you should be able to connect to network systems.



 I created a shell script in windows and moved into linux. Here, i set all the requisite user rights for execution. When i tried to execute the script, it gives the error

bad interpreter: No such file or directory
The script seems to be syntatically fine.

This is a problem becaus of the difference in OSes. Open the script in vim and type the following command


:set ff=unix

This converts the script to unix based file format.

Tuesday, January 01, 2008

Difference between CR and LF

Sourced from here

The main difference is that and are characters, while EOF is more of a concept - though the end of a file can be denoted by a special marker character, too.

Generally speaking, under Windows and DOS, lines of text in a file end with the two byte character sequence ; these characters have the ASCII values 13 and 10, respectively. Under *nix, a line of text ends with just ASCII character # 10.

Under DOS and Windows, a file might also contain an end of file marker character; the ASCII value of this character is 0x1A (26 decimal). This character was used more to speed things up when working with certain kinds of files (text files, as opposed to binary files) than anything.

Exactly how you open a file, read from it, or write to it, will vary with the programming language or tool that you're using; there are a lot of commonalities between the majority of them, though. Hopefully, a few examples in C will help clear this up. A few important points first, though: a carriage return (CR) - ASCII character code 13 - is also represented by the escape sequence "\r" (not including the quote marks), and a line feed (LF) - ASCII character code 10 - is also represented by the escape sequence "\n" (again, not including the quote marks).

Under DOS or Windows - assuming that we're using the C run-time library (RTL) and not the Windows application programming interface (API), or DOS function calls - you have to tell the RTL how you would like it to treat the file. Your option are "as a text file" and "as a binary file". If you tell the RTL to treat a file as a text file, the following things will happen:

When the sequence is encountered in a file, it's replaced, "behind the scenes", by just , which is ASCII character 10. Which matches the constant '\n'.

If the end-of-file character is encountered, the file's end-of-file flag is set: fgetc() returns the value EOF (defined in stdio.h); feof() will return true (non-zero), and so on.

However, if you tell the RTL to treat the file as a binary file, the data is returned to you "raw" - no end-of-line marker translation is done, you get both the and the ; and, the end-of-file marker - if present - is treated just like any other byte in the file; it's value is returned to you.

With most compilers, under Windows or DOS, in C, a file is opened as a binary file by using fopen() and specifying the letter "b" after the mode you wish to open the file in (r, w, a, etc.). For example, to open a file named "test.dat" in read-only mode, in binary mode (without any translation of the file's contents), one could write:

FILE *f;

if (!(f = fopen(f,"rb")))
{
/* an error occurred */
}

A note regarding porting code between DOS/Windows and *nix systems: if you were to attempt to compile the above code on a *nix system, the compiler might or might not give you an indication that there was a problem: generally speaking, *nix systems always open files in "binary" mode, and "rb" (or "wb", "ab", etc.) is not a valid parameter. Exactly what would happen can be expected to vary from compiler to compiler; on some, the presence of the "b" might cause the fopen() call to fail; others might print a warning message.



One last note regarding end-of-file and translation of characters in "text" mode on DOS and Windows systems: while, in theory, the rules are simple, in practice, they're a lot more complicated. If you were to take a program that used text files in "text" mode, and compile it, on a DOS / Windows system, with different compilers from different vendors, you can expect that, to some extent, you'll get different results. One of the ways they differ in is in how the final pair in a file is treated. In "text" mode, sometimes, you'll get a final "\n", and other times you won't. In "binary" mode, you'll always get the entire contents of the file.

Wednesday, October 24, 2007

Too much security

On a security enhanced linux system (selinux enabled OS), when you try to execute an application which links with user created libraries, you will (in all probabilities) end up with an error like below
./myapp : error while loading shared libaries :
/usr/local/lib/libmylib.so :cannot restore segment prot
after reloc permission denied.
. There are two ways to escape this pain.

1. Kill the source of pain once and for all. Disable selinux. Open /etc/selinux/config and either comment out all lines or modify the following line as below
SELINUX=disabled. Save the file and voila, you are a killer.

2. Request selinux.

Dear Selinux,

Since I have to work with user created libraries, I request you to kindly allow me to access the same and run corresponding applications.

Thanking you,
A Poor suffering soul.


Well, not exactly like this, but something like below (for libraries in /usr/local/lib path)
find /usr/local/lib -name '*.so*' -exec chcon -t 
texrel_shlib_t {} \;

Monday, October 22, 2007

Wrong Architecture issue in Mac

I maintain a common source code base for both PPC and x86 architecture in Mac and just recompile (with different Makefiles) in both architectures. Once, I had forgotten to clean up a library archive which I had compiled in x86. So, when I tried compiling the library in PPC, I ended up with the following error.

ld: common symbols not allowed with MH_DYLIB output format with 
the -multi_module option
mymainfile.o definition of common _gsDeviceFreeMutex (size 44)
/usr/bin/libtool: internal link edit command failed


Just cleaning up the x86-compiled library archive removed the above error. And this drank few hours off my work-day. But, I ended up wiser ;-)

Tuesday, May 08, 2007

static linking in Mac - But when?

This is a linker part of my Makefile for compiling an app in Linux. It statically links a library which again I did.
Shared Library Generation
gcc  -shared -Wl,-soname,libmylib.so   -o libmylib.so.1.0.1 myownfile.o

App Generation
gcc -o testapp -L/usr/local/lib -L. -lmylib appfile1.o appfile2.o appfile3.o


This went fine in Linux. But, in Mac, the app generation started shouting. Yes, I have to compile it as a dylib file. And I did that too.

libtool -o libmylib.A.dylib myownfile.o -L/usr/local/lib -lotherlib

Ok. All are ready. Now, when I tried to compile it as below (similar to Linux), I was encountered with "undefined symbols", the same functions which I was linking from my dylib file. \

gcc -o testapp -L/usr/local/lib -L. -lmylib appfile1.o appfile2.o appfile3.o


aaaaaaarrggghhhhhh.

Googling led me to a startling (er... a rather novice mistake) revelation. With the above flow, the compiler will first encounter that library, see that it has no use, throw it off and then, try to link the object files. Now (and NOWWWW), it tries to solve the dependencies in the object files. Failing to solve, it shouts back at the user "LOSSEERRRRRR".... :-(

So, with the sombre face of a loser, I changed the compile script to follow the reverse pattern, ie, link the object files first and THEN, solve the dependencies, if any.



gcc -o testapp  appfile1.o appfile2.o appfile3.o -L/usr/local/lib -L. -lmylib



Voila. It works.

I did it! I did it! yeah yeah. I did it!

Monday, April 30, 2007

Calling one kernel module function in another

Say I have a LKM foo1.ko which has "my_foo1()" as the exported function. Now, another LKM foo2.ko calls this "my_foo1()". When this second LKM is compiled, it is generating a warning that "my_foo1() undefined!". Though this is just a warning, this can be avoided. How? I found it out via a forum. There are FOUR ways to remove the warning.

ONE: "insmod" foo1 before comiling foo2.

TWO: Compile both the LKMs in the same Makefile, in one shot; like below



$ cat Makefile
obj-m = foo1/foo1.o foo2/foo2.o

here:
make -C /lib/modules/`uname -r`/build M=`pwd` modules


THREE: Starting 2.6.17, you can copy the Module.symvers generated by the compilation of foo1 to the foo2 source directory and compile foo2.

FOUR: Be a proper programmer and ignore it. It works anyway ! Why Worry :-)

Common symbol error in Mac

Multiple C files. Few global variables. A single dynamic library. Thats what I was trying to do in Mac. But, the compiler went jittery and complained
ld: common symbols not allowed with MH_DYLIB output format
. Googling taught me that I need to either initialize the global variable(s) or add "-fno-common" switch to the compiler flags. That solved the issue and I am happy "trying" to link it. Oh Yeah. Am facing another issue. Will update as soon as I find the solution. Cheerio.