Frequently Asked Questions on Windows
  1. How to resolve "Parameter format not correct" error?
  2. How to change the user's default home directory in Ch?
  3. How to use 'awk.exe', 'find.exe' and 'grep.exe' correctly in windows?
  4. How to run Windows command in Ch shell without being blocked?
  5. How to write programs for serial com port processing?
  6. How to generate plotting using a static SIGL library?
  7. How to zoom back to the original plotting in Ch Pro or SIGL after zooming out?
  8. How to rotate the 3D display to a special view such as XY plane, YZ and ZX?
  9. I got the error: Unable to find msvcr80.dll, how to fix it?
  10. I got the error: Runtime Error! R6034. An application has made an attempt to load the C runtime library incorrectly.
  11. Where can I find the list of supported Unix commands in Windows?
  12. How to call functions in a Windows DLL library from Ch
  13. How to compile C/C++ programs in ChIDE or Ch Shell?
  14. How to compile in Windows 64 bit machine with 32 bit compiler instead of default 64 bit compiler in Ch?
  15. man.exe works in ch shell but it will hangup inside console2, how to fix it?

Q: How to resolve "Parameter format not correct" error?

It happens when you try to run MS-DOS command in Unix syntax. For example,

    C:/> dir /temp/*exe
         Parameter format not correct - "emp".
    C:/>
One can run the command using
C:/> dir \temp\*.exe
The similar error you might get is "The syntax of the command is incorrect" or "Invalid switch - /temp", When you run the command
C:/> type /Ch/bin/dirs.ch
You can fix it by running:
C:/> type \Ch\bin\dirs.ch

Q: How to change the user's default home directory in Ch?

The home directory for the user in Ch is set to the user's home directory by default. You can follow Microsoft's link below to change the user's default home directory.

http://support.microsoft.com/kb/320043

Q: How to use 'awk.exe', 'find.exe' and 'grep.exe' correctly in windows?

The gnuwin32 utilities needs slight modification to work correctly in windows. Here are some examples:

  • awk

    You may need to add escape before $. Here is an example.

        cat file_name | awk "{print \$1}"
            awk "{print \$1}" < file_name
    
  • grep

    when using "grep string */*", you will get the error:"C:\Ch\bin\grep.exe */*: No such file or directory".

    To check files under each directory recursively, you can use the following command to get around such a problem:

       grep -r string .
    
  • find

    Sometimes, you will get the following problem in windows

       C:/home>find . -name "*.txt"
       find: paths must precede expression
       Usage: find [-H] [-L] [-P] [path...] [expression]
    
    You can try the following solution.
        c:/home>find . -iregex ".+\.txt" 
    
    or
        c:/home>find . -iregex ".*\.txt" 
    

Q: How to run Windows command in Ch shell without being blocked?

Like in Unix, a command in Windows can be executed in the background by appending "&" at the end of the command. For example,

         c:/> notepad &

Q:How to write programs for serial com port processing?

Ch supports all Windows serial port I/0 functions listed in CHHOME/include/windows/conio.h, you can find more information at Microsoft developer network web site http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_resources.asp .

The Windows APIs used for serial port communication are listed below. They are all supported in Ch.

CreateFile()
SetupComm()
GetCommState()
CommState()
BuildCommDCB()
SetCommTimeouts()
WriteFile()
ReadFile()
The sample files can be found at http://groups.yahoo.com/group/ch_language/files/SerialDemo/ and Ch Bhand package http://chbhand.sourceforge.net

Q: How to catch any keys in Windows?

You can use function kbhit(). Here is the sample code.

#include <conio.h> int main() { char c; printf("hit a key\n"); while (!kbhit()) ; // Waits for keystroke while (kbhit()) c= getch(); // Empties buffer //while (!kbhit()) // ; // Waits for keystroke printf("you hit the key = '%c'\n", c); }

Q: How to generate plotting using a static SIGL library?

To link a static SIGL library, in the files

C:/silib/demos/chapter2/Makefile C:/silib/demos/chapter3/Makefile Change CFLAG=-I"C:/silib/include" -DM_PI=3.14159265358979323846 LFLAG="C:/silib/lib/libchplot.lib" to CFLAG=/MD -I"C:/silib/include" -DM_PI=3.14159265358979323846 LFLAG="C:/silib/lib/libchplot_a.lib" to use static lib libchplot_a.lib in Windows.

Q: How to zoom back to the original plotting in Ch Pro or SIGL after zooming out?

You can zoom in or zomm out by holding and dragging with the right mouse button.

To zoom in, move the mouse while holding down the right mouse button, It will report the upper left and lower right corners of the zoom. While the mouse is focused on the plot, type 'p' will go back the previous zoom stack, type 'n' will go to the next zoom stack. and type 'a' or 'u' will go to the original state.

Q: How to rotate the 3D display to a special view such as XY plane, YZ and ZX?

You can rotate it by mouse though it is slow. Member functions such as

changeViewAngle(double rot_x, double rot_z);
are available to rotate and view in different angles.

Q: I got the error: Unable to find msvcr80.dll, how to fix it?

You need to use runtime library: Multi-threaded DLL (/MD).

Go to Project->Property->Configuration Porperties->C/C++->Code Generation, then set "RunTime Library" to Multi-threaded DLl (/MD).

For redistributing your packages, you may need the end user to install Microsoft Visual C++ 2005 Redistributable Package. Here is the link for (X64) and the link for X86 32 bit.

Q: I got the error: Runtime Error! R6034. An application has made an attempt to load the C runtime library incorrectly.

You need to make sure if you can get the example demos listed in C:\silib\demos\VC to work.

Then, make sure you can follow the following steps to get the application to work first.

- change to Release from debug mode in your Visual studio configuration 
- change to use static library libchplot_a.lib
- change to /MT compile option
- Use MFC in Static Library

Q: Where I can find the list of supported Unix commands in Windows?

Appendix G in Ch User's Guide (CHHOME/docs/chguide.pdf) contains most commonly used Unix commands in Windows. These commands are located in the directory CHHOME/bin (such as C:\Ch\bin) in Windows. You can also find them in the link below.
http://www.softintegration.com/docs/ch/shell/unixcommands.html

Q: How to call functions in a Windows DLL library from Ch?

Ch cannot use LoadLibrary() and GetProcAdr() with .DLL file to call functions in a DLL library directly. Special handling is required. It doesn't require to modify your C/C++ source code. You can find the sample code at the directory:

 
  C:\ch\demos\SDK\chapters\runc2chf_dll\chf
Ch Std and Ch Pro comes with Ch SDK. It can be used to interface any binary C lib. Ch SDK has been used to interface Window API, X11/Motif, ODBC, OpenGL, etc. You can find more about Ch SDK at
http://www.softintegration.com/products/sdk/chsdk/
and CHHOME/ch/docs/chsdk.pdf
All examples described in chsdk.pdf can be found in CHHOME/demos/SDK such as C:/Ch/demos/SDK/ directory.

You may also take a look at examples CHHOME/demos/SDK/chapters/runc2chf/chf/ http://www.softintegration.com/products/thirdparty/velleman/

The source code for these two examples might be helpful to you. To call C/C++ functions in binary module, you might need to set the environment in Ch shell first to get the job done. It is handled using standard C functions in dynamically loaded lib. These C functions are not needed in a typical C/C++ program.

The best way to link .lib is to follow the examples we provided. The source code for examples in these four chapters are located in CHHOME/demos/SDK/compilation, twospaces, run_c2chf, classes.

The "compilation" directory contains the code related to chapter 1. The "twospaces" directory is related to chapter 2. The run_c2chf directory is related to chapter 3. The "classes" directroy is related to chapter 7.

The examples in "compilation" directory can be used to test if your environment setting is correct. All programs are written in either C/C++ code which can be compiled. You can type "nmake" or "nmake -f Makefile.win" to generate the binary executable code.

An example of using Ch SDK is Ch K8055 Package at http://www.softintegration.com/products/thirdparty/velleman/ It contains the source code for building Ch interface to the Velleman USB interface board K8055. In this example, a simplified header file k8055d_c.h is used to generate Ch function files *.chf and dynamical loaded library libk8055d_c.dl.

If you build a Ch interface and provide us with necessary information, we can add a link to you like we have done for Ch K8055 Package http://www.softintegration.com/products/thirdparty/velleman/ for K8055 at http://www.vellemanusa.com/us/enu/download/files/

Q: How to compile C/C++ programs in ChIDE or Ch Shell?

To compile a C/C++ program, you need to have a C/C++ compiler installed first. You may install a Visual Studio Express Edition, which is free.

After you have installed a Visual Studio, you need to open the file _chrc in your home directory. You can run from a Ch shell and type "cd ~" to go to your home directory. If you don't have the _chrc in your home directory, you can run the command "ch -d" to create the file _chrc in your home directory. The file _chrc contains the default configuration for visual studio that you can comment out to get it work. By default, Ch and ChIDE support C/C++ compiler in Visual Studio 32 bit in windows 32 bit or Visual Studio 64 bit in windows 64 bit.

By default, Visual Studo is installed with 32 bit compiler in Windows 64 bit operating system. You need to select "Custom" option and make sure "64 bit compiler" is selected during the installation.

If you installed Visual Studio first, then install Ch, you don't need to do anything. the installation of Ch will setup all compilation options correctly. Otherwise, you will need to configure C/C++ compiler in the startup file _chrc.

Now you can compile the code in both Ch Shell and ChIDE.

If you have ChIDE, You can open the file _chrc from ChIDE.

In ChIDE, click Options->Open ChIDE Local Startup File will open the startup file _chrc in your home directory for editing.

Once you open the file startup file _chrc, you can uncomment the code related to using a C/C++ compiler in a Visual Studio. File _chrc contains the configuration for different versions of Visual Studio, you can uncomment the configuration related to your version of Visual Studio and save it. You can follow the procedure below to compile and run the program.

Tools->Compile to compile
Tools->Link to link
Tools->Build to invoke a Makefile
Tools->Go to run a generated binary executable program.
You can find the sample Makefile from the file C:\ch\demos\bin\Makefile.

Q: How to compile in Windows 64 bit machine with 32 bit compiler instead of default 64 bit compiler in Ch?

In windows 64 bit OS, Ch will set up to use the default 64 bit compiler. However, the visual studio 2010 will setup configuration using 32 bit compiler by default. You can edit the ~/_chrc file by commenting out the default configuration and use the configuration below, where ~ is your home directory assuming you use visual studio 2010. If you don't have such a file ~/_chrc, you can run "ch -d" from ch shell to create it

If you don't use visual studio 2010, you need to make changes based on the configuration below.


_path = stradd(_path, "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin;",
        "c:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/Tools;"
        "c:/Windows/Microsoft.NET/Framework/v4.0.30319;"
        "c:/Windows/Microsoft.NET/Framework/v3.5;"
        "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/VCPackages;"
        "c:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE;"
         "c:/Program Files (x86)/HTML Help Workshop;"
         "c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin;"
         );

putenv(stradd("LIB=C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/;"
       "C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib;", getenv("LIB")));

putenv(stradd("INCLUDE=C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include;",
         "C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include;.;", getenv("INCLUDE"))); 

Q: man.exe works in the ch shell, but it will hangup inside console2, how to fix it?

You need to apply the following patch from microsoft. http://support.microsoft.com/kb/2458000