Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Fri, 17 Sep 2004 08:21:57 -0700 From: Lester Ingber To: cygwin AT cygwin DOT com, mingw-users AT lists DOT sourceforge DOT net Subject: file I/O and calling executables from a DLL? Message-ID: <20040917152157.GA1568@ingber.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i I'm having problems executing file I/O and calling executables from a DLL? I know this sounds simple, and this works fine under Excel, but I'm having problems doing this with TradeStation. Is there anything I should know about changes in paths, root directories, etc., that can occur under different applications? I have modified a simple code to prepare a DLL from a fairly well-known tool, dllhelpers, http://www.xraylith.wisc.edu/~khan/software/gnu-win32/dllhelpers.html and I have produced an equally good DLL using a Makefile enclosed. I've just added a call to another independent executable. This works just fine (using either the more standard dllhelper way or using my own Makefile) under Excel using the dllhelpers-prepared dlltest.xls. Here's some simple code I prepared to explain what I've done. I'm using *all* the most current Curr downloads via setup.exe from cygwin.com. Makefile for cdll.c: ------------8<------------ top cut -> bottom ------------->8------------ DLL_OPTION=-mrtd # I found this necessary for DLLs to work CYGWIN_OPTION=-mno-cygwin $(DLL_OPTION) CC = gcc CDEBUGFLAGS = -g -O -Wall CFLAGS = $(CDEBUGFLAGS) $(CYGWIN_OPTION) LDFLAGS = $(CYGWIN_OPTION) obj_libs = cdll.o dllmodule = cdll dependency_libs = -lm all: $(CC) $(CFLAGS) -c -o ${obj_libs} cdll.c $(CC) $(CFLAGS) -mrtd -shared -o ${dllmodule}.dll \ -Wl,--out-implib=${dllmodule}.lib \ -Wl,--compat-implib \ -Wl,--add-stdcall-alias \ -Wl,--enable-stdcall-fixup \ -Wl,--enable-auto-import \ -Wl,--enable-auto-image-base \ -Wl,--whole-archive ${obj_libs} \ -Wl,--export-all-symbols \ -Wl,--output-def=${dllmodule}.def \ -Wl,--no-whole-archive ${dependency_libs} ------------8<------------ bottom cut <- top ------------->8------------ cdll.c (In Tradestation, you have to change double->float): ------------8<------------ top cut -> bottom ------------->8------------ #include #include #include #include #include double dll_double_square (double d); double dll_double_square (double d) { char trd_comm[200]; FILE *ptr_comm; /* I tried this with a system() call, but it still doesn't work when dll_double_square is called in TradeStation */ sprintf (trd_comm, "run_trd.exe"); ptr_comm = popen (trd_comm, "r"); pclose (ptr_comm); return d * d; } ------------8<------------ bottom cut <- top ------------->8------------ Makefile for trd.c: ------------8<------------ top cut -> bottom ------------->8------------ CYGWIN_OPTION=-mno-cygwin CC = gcc CDEBUGFLAGS = -g -O -Wall CFLAGS = $(CDEBUGFLAGS) $(CYGWIN_OPTION) LDFLAGS = $(CYGWIN_OPTION) obj_libs = trd.o all: $(obj_libs) @$(CC) $(LDFLAGS) -o run_trd.exe $(obj_libs) -lm ------------8<------------ bottom cut <- top ------------->8------------ trd.c: ------------8<------------ top cut -> bottom ------------->8------------ #include #include #include #include #include int main (); int main () { char trd_comm[50]; FILE *ptr_comm; sprintf (trd_comm, "mkdir ..\\IO\\%s", "test_dir"); ptr_comm = popen (trd_comm, "r"); pclose (ptr_comm); printf ("mkdir test_dir\n"); return 0; } ------------8<------------ bottom cut <- top ------------->8------------ I have the same non-results in TradeStation, but OK results in Excel, if I simply create the test_dir within cdll.c, e.g., *not* calling any other executable. In TradeStation, the code returns just fine, and goes on to do other stuff, but the commands I cite just are not being executed? I also tried including explicit paths, e.g., prefacing the executable and file with c:\cygwin\..., and not even using any relative paths like "..", but with no positive effect. Thanks. Lester -- 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/