From 743d8ae233befdcb0a407e0cd6fa65fe65db53be Mon Sep 17 00:00:00 2001 From: dannybackx Date: Sun, 20 Sep 2009 12:24:35 +0000 Subject: [PATCH] Add a second test program (mainly to help debug the problems reported by the xcsoar team). git-svn-id: svn://svn.code.sf.net/p/cegcc/code/trunk@1382 d7810a3d-100a-0410-8641-c3624a9c11f1 --- cegcc/tools/dll/Makefile | 8 +++-- cegcc/tools/dll/testapi.c | 9 ++++++ cegcc/tools/dll/testapi2.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 cegcc/tools/dll/testapi2.c diff --git a/cegcc/tools/dll/Makefile b/cegcc/tools/dll/Makefile index 2301bd18b..d2dd6aaa8 100644 --- a/cegcc/tools/dll/Makefile +++ b/cegcc/tools/dll/Makefile @@ -1,4 +1,5 @@ -ARCH= i386-mingw32ce +ARCH= arm-mingw32ce +#ARCH= i386-mingw32ce CC= ${ARCH}-gcc SRC= ../../src @@ -6,7 +7,7 @@ CDEF= ${SRC}/mingw/coredll.def ADEF= ${SRC}/w32api/libce/aygshell.def CFLAGS= -D_WIN32_WCE=0x0600 -D_WIN32_IE=0x0600 -all:: dllverify.exe testapi.exe +all:: dllverify.exe testapi.exe testapi2.exe dllverify.exe: dllverify.c ${CC} -o $@ $< @@ -14,5 +15,8 @@ dllverify.exe: dllverify.c testapi.exe: testapi.c ${CC} -o $@ $< +testapi2.exe: testapi2.c + ${CC} -o $@ $< + clean: -rm -f *.o dllverify.exe diff --git a/cegcc/tools/dll/testapi.c b/cegcc/tools/dll/testapi.c index 305afc09d..7911bfcef 100644 --- a/cegcc/tools/dll/testapi.c +++ b/cegcc/tools/dll/testapi.c @@ -1,3 +1,12 @@ +/* + * Test whether a DLL offers one or more APIs mentioned on the command line. + * This version of the program is meant to be used from the command line, + * e.g. via a remote shell connection. + * + * Success or failure are reported via the standard output. + * + * Copyright (c) 2009 by Danny Backx. + */ #include #include #include diff --git a/cegcc/tools/dll/testapi2.c b/cegcc/tools/dll/testapi2.c new file mode 100644 index 000000000..3e3a5a063 --- /dev/null +++ b/cegcc/tools/dll/testapi2.c @@ -0,0 +1,81 @@ +/* + * This application can read a file, and test whether the indicated DLL + * implements the APIs described in the file. + * + * The program has been created to work without command line : input is + * read from a file (\temp\testapi.in.txt) and output is written to + * another file (\temp\testapi.out.txt). Errors may be reported via + * dialogs on the Windows CE console. + * + * File format : a single entry on each line. + * First line mentions the name of the dll to be loaded (e.g. coredll). + * All next lines mention the name of a function that the DLL will be + * searched for (e.g. AppendMenuW). + * + * Copyright (c) 2009 by Danny Backx. + */ +#include +#include +#include + +void (WINAPI *fun)(void); + +char *input = "\\temp\\testapi.in.txt", + *output = "\\temp\\testapi.out.txt"; + +int main(int argc, char *argv[]) +{ + int r, count = 0; + HINSTANCE dll; + wchar_t dllname[64], wapi[64]; + char field[64], dllnm[64]; + + FILE *infile = NULL, + *outfile = NULL; + + infile = fopen(input, "r"); + if (infile == NULL) { + MessageBoxW(0, L"Could not open input file", L"Error", 0); + exit(1); + } + + outfile = fopen(output, "w"); + if (outfile == NULL) { + MessageBoxW(0, L"Could not open output file", L"Error", 0); + exit(2); + } + + fscanf(infile, "%s\n", &field); + mbstowcs(dllname, field, 64); + strcpy(dllnm, field); + dll = LoadLibrary(dllname); + if (! dll) { + DWORD e = GetLastError(); + fprintf(outfile, "LoadLibrary(%s) : cannot load DLL -> error %d\n", dllnm, e); + fclose(outfile); + exit(1); + } + fprintf(outfile, "Testapi2 started (%s)\n", field); + + r = fscanf(infile, "%s\n", &field); + while (r != EOF) { + if (count++ > 2000) { + printf("Terminating\n"); + fprintf(outfile, "Terminating\n"); + fclose(outfile); + exit(1); + } + mbstowcs(wapi, field, 64); + *(FARPROC *)&fun = GetProcAddress(dll, wapi); + if (fun) { + fprintf(outfile, "\t%s implements %s (0x%08X)\n", dllnm, field, fun); + } else { + DWORD e = GetLastError(); + fprintf(outfile, "%s doesn't know about %s\n", dllnm, field); + } + r = fscanf(infile, "%s\n", &field); + } + + fclose(outfile); + exit(0); +} -- 2.11.4.GIT