Thursday, April 29, 2010
Control characters in source file after ftp
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
Getting the hyper link to work in CRichEditCtrl
Set the SetEventMask for your m_MyRichEdit (this is my control variable for the CRichEditCtrl class) to understand links
m_MyRichEdit.SetEventMask( \Now, add a override function for OnNotify in your class. In the .h file, add
m_MyRichEdit.GetEventMask() | ENM_MOUSEEVENTS)
afx_msg BOOL OnNotify (WPARAM wParam, \Add the corresponding function similar to the one below
LPARAM lParam, LRESULT *pResult);
BOOL CParentDlg:: OnNotify (WPARAM wParam, LPARAM lParam, LRESULT * 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.
{
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);
)
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
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
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
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
MyVCLibrary.def : Declares the module parameters for the DLL.My exported function prototype is
LIBRARY "MyVCLibrary"
DESCRIPTION 'My VC Library DLL'
EXPORTS
; Explicit exports can go here
MyExportedFunction
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
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 directoryThe 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
Tuesday, January 01, 2008
Difference between CR and LF
The main difference is that
Generally speaking, under Windows and DOS, lines of text in a file end with the two byte character sequence
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
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
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
Wednesday, October 24, 2007
Too much security
./myapp : error while loading shared libaries :. There are two ways to escape this pain.
/usr/local/lib/libmylib.so :cannot restore segment prot
after reloc permission denied.
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?
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
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.
Thursday, April 05, 2007
loading shared libraries with gdb
While trying to validate a particular utility which uses a shared library (which again was developed by me and resides in user-specified path), gdb reported error that it was not able to find the shared library (although compiling the utility was not a problem). ldd also was not able to find the library, although i had used ldconfig -n /path/to/lib/dir and properly created the soname.
After some googling, I found that gdb was trying to use the ld.so.conf directory and its contents to search for the shared library objects. So, I added my path to /etc/ld.so.conf/ directory. After this, the shared object loaded without any complaint.
mmMmm...
Monday, March 26, 2007
A good kernel compilation link
Friday, March 16, 2007
Expat's little problem
Parse error at line XXX:
not well-formed (invalid token)
The XML file was good in all aspects, is what I had thought. Expat (ver 2.0.0) didnt think so. The bad part was that it parsed the whole file (including ending token) and THEN he gave the above error. Out of the wild, a thought struck me (yup, it happens to me too).
I opened the XML file and added a new line AFTER the last token. And Voila! it worked. Now, expat was happy. I was happy. All was well that ended (well actually, started) well. Need to report this to the developers(shud have been).