Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3A3EADAF.816AFF71@ece.gatech.edu> Date: Mon, 18 Dec 2000 19:37:03 -0500 From: "Charles S. Wilson" X-Mailer: Mozilla 4.75 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: Greg Clinton CC: "'cygwin AT cygwin DOT com'" Subject: Re: Question regarding building dlls References: <43F59FF02E07D31199220008C733ED53010FA5F7 AT exchange-dev DOT b3 DOT wonderware DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Take a look at http://cygutils.netpedia.net/dllhelpers-0.2.6.tar.gz based on earlier work by Mumit Khan, but updated to reflect the capabilities of current gcc/binutils. Contains examples of building dll's in C, C++, and Fortan. --Chuck Greg Clinton wrote: > > I'm having trouble with dll's that I build with gcc and dlltool. Any > time I try do do anything useful within a dll function, such as call > new or call any Win32 API, I get an access violation. Does anyone see > what I'm doing wrong? Below I provide mydll.cpp, mydll.def, myprog.c, > and build.bat. I'm using gcc version 2.95.2-5 19991024 (cygwin experimental) > Ultimately I intend to build an inproc COM server. > > Thanks in advance for your help. > Greg Clinton > greg DOT clinton AT wonderware DOT com > > ------------------------------mydll.cpp------------------------------ > #include > > int main() > { > return 0; > } > > extern "C" int WINAPI > mydll_init(HANDLE h, DWORD reason, void *foo) > { > return 1; > } > > > extern "C" int WINAPI > calc() > { > int *p = new int; > delete p; > return 34; > } > > ------------------------------mydll.def------------------------------ > LIBRARY > > EXPORTS > mydll_init > calc > > --------------------------------myprog.c------------------------------ > #include > > typedef int (WINAPI *CalcProc)(); > > int main() > { > int i; > HMODULE hModule = LoadLibrary("mydll.dll"); > CalcProc calc = (CalcProc) GetProcAddress(hModule, "calc"); > i = calc(); > FreeLibrary(hModule); > return i; > } > > ------------------------------build.bat------------------------------ > set path=%path%;c:\cygwin\bin > set include=c:\cygwin\usr\include; > gcc -c myprog.c > gcc -c mydll.cpp > gcc -s -Wl,--base-file,mydll.base -o mydll.dll mydll.o -Wl,-e,_mydll_init AT 12 > > dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp > --dllname mydll.dll > gcc -s -Wl,--base-file,mydll.base,mydll.exp -o mydll.dll mydll.o > -Wl,-e,_mydll_init AT 12 > dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp > --dllname mydll.dll > gcc -Wl,mydll.exp -o mydll.dll mydll.o -Wl,-e,_mydll_init AT 12 > gcc -o myprog myprog.o > myprog.exe > > -----------------------myprog.exe.stackdump----------------------------- > Exception: STATUS_ACCESS_VIOLATION at eip=6E677963 > eax=6E677963 ebx=140D1074 ecx=0240FF08 edx=77FCD348 esi=6107C0E8 > edi=00000000 > ebp=0240F75C esp=0240FBF8 program=C:\temp\MyDll\myprog.exe > cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023 > Stack trace: > Frame Function Args > 0240F75C 6E677963 (00000000, 00000000, 00000000, 00000000) > 0240FC04 6E677963 (140D1074, 6107C0E8, 00000000, 0240FCF4) > 0240FD24 140D1209 (00000004, 00000000, 00000000, 00000004) > 0240FD54 140D1084 (00000004, 0240FDA0, 61040551, 00000004) > 0240FD84 00401091 (00000001, 0A011218, 0A010008, FFFFFFFE) > 0240FF10 610038AD (00000000, 03EEDEE4, 8046A640, 87F00280) > 0240FF40 61003A8D (00401054, 03EEDEE4, 8340BAC0, 8049F5BE) > 0240FF60 61003ACC (00000000, 00000000, 8340BC50, 00000005) > 0240FF90 004010FF (00401054, FFFFFFFF, 80430B27, 00000000) > 0240FFC0 0040103D (03EEDEE4, 0000064A, 7FFDF000, 03EEDC7C) > 0240FFF0 77E87903 (00401000, 00000000, 000000C8, 00000100) > End of stack trace > > -- > Want to unsubscribe from this list? > Check out: http://cygwin.com/ml/#unsubscribe-simple -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple