This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: need -mrtd to create Excel DLL?


Lester,
 It works! Thank you. Assuming these will be archived, maybe this can help
someone else.

Since I'm wondering if Excel was caching something, I decided to use C# and
it works!
 Thanks,
    Siegfried

Here is the example of calling cygwin C from C#:
------begin here ------

//  Begin commands to execute this file using MS.NET with bash
//  cat <<EOF >cdll.h
//  #ifndef cdll_h_included

//  #define cdll_h_included

//

//  /*

//   * When building the DLL code, you should define BUILDING_DLL so that

//   * the variables/functions are exported correctly. When using the DLL,

//   * do NOT define BUILDING_DLL, and then the variables/functions will

//   * be imported correctly.

//   *

//   * You need to be using egcs-1.1.1 or newer.

//   *

//   * Building the DLL:

//   *  - define BUILDING_DLL, which defines DLLIMPORT
__attribute__((dllexport))

//   * Building the client code:

//   *  - DO NOT define BUILDING_DLL, which defines DLLIMPORT to be one

//   *    __attribute__((dllimport))

//   */

//

//  #if BUILDING_DLL

//  # define DLLIMPORT __declspec (dllexport)

//  #else /* Not BUILDING_DLL */

//  # define DLLIMPORT __declspec (dllimport)

//  #endif /* Not BUILDING_DLL */

//

//  DLLIMPORT double dll_double_square (double);

//  #endif /* cdll_h_included */

//  EOF
//  cat <<EOF >cdll.c
//  #include "cdll.h"                     
//  DLLIMPORT double                      
//  dll_double_square (double d)          
//  {                                     
//    return d * d;                       
//  }                                     
//  EOF
//  gcc cdll.c -DBUILDING_DLL=1 -mrtd -g -O2 -Wall -mno-cygwin -mrtd -shared
-o cdll.dll -Wl,--out-implib=cdll.lib -Wl,--compat-implib
-Wl,--add-stdcall-alias -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import
-Wl,--enable-auto-image-base  -Wl,--export-all-symbols
-Wl,--output-def=cdll.def -Wl,--no-whole-archive 
//  c:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/csc  /checked /incr /debug
/out:test.exe test.cs
//  ./test 4 2 10 2.3 4.23
//  rm test.exe
//  rm test.exe.incr
//  rm test.pdb
//  End commands to execute this file using MS.NET with bash


class test {
  [System.Runtime.InteropServices.DllImport ("cdll.dll",
CallingConvention=System.Runtime.InteropServices.CallingConvention.Cdecl)]
       public static extern double dll_double_square(double d);
  static public void Main(string[] args){
    System.Console.WriteLine("hello");
    for(int ii = 0; ii<args.Length; ii++) 
      System.Console.WriteLine("args["+ii+"]="+double.Parse(args[ii]) + "
Square = " + dll_double_square(double.Parse(args[ii])));
  }
}

----- end of file -----

Here is an example of calling g77 from from C#:
--------------------begin file here----
/**
 * Begin commands to execute this file using MS.NET with bash
 * cat <<EOF >f77dll.f
 *          function dll_double_square_f77 (value)
 *          double precision dll_double_square_f77, value
 *          print*, '  dll_double_square_f77 value=', value
 *          dll_double_square_f77 = value**2
 *          return
 *          end
 * EOF
 * g77 f77dll.f -DBUILDING_DLL=1 -mrtd -g -O2 -Wall -mno-cygwin -mrtd
-shared -o f77dll.dll -Wl,--out-implib=f77dll.lib -Wl,--compat-implib
-Wl,--add-stdcall-alias -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import
-Wl,--enable-auto-image-base  -Wl,--export-all-symbols
-Wl,--output-def=f77dll.def -Wl,--no-whole-archive 
 * c:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/csc  /checked /incr /debug
/out:test.exe test.cs
 * ./test 4 2 10 2.3 4.23
 * rm test.exe
 * rm test.exe.incr
 * rm test.pdb
 * End commands to execute this file using MS.NET with bash
 */

class test {
  [System.Runtime.InteropServices.DllImport ("f77dll.dll",
CallingConvention=System.Runtime.InteropServices.CallingConvention.Cdecl)]
       public static extern double dll_double_square_f77__(ref double d);
  static public void Main(string[] args){
    System.Console.WriteLine("hello");
    for(int ii = 0; ii<args.Length; ii++) {
      double x = double.Parse(args[ii]);
      System.Console.WriteLine("args["+ii+"]="+x + " Square = " +
dll_double_square_f77__(ref x));
    }
  }
}
--------------------end file here-------------



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]