I've read already tremendous amount of articles, tutorials, and instructions about how to solve my problem - but still - no gain. I just can't put it into work.
My goal is pretty simple: I want to compile a DLL file using Cygwin gcc tool, and then use it within MSVC2010. I'm actually want to do it with my own DLL code, but as for simplicity - I've tried the very basic example on Cygwin's site - and failed with that too.. What I've done so far: (Most is taken from Cygwin User's Guide, DLL section: https://cygwin.com/cygwin-ug-net/dll.html#dll-build) 1. Created mydll.c file as following: ***** mydll.c ******* #include <stdio.h> int hello() { printf ("Hello World!\n"); } ************************ 2. Compiled mydll.c into mydll.dll using gcc -c mydll.c and gcc -shared -o mydll.dll mydll.o 3. Opened an empty Win32 Console project in Visual Studio, with the following code as test.c (code taken from Oleg's code in here, and based on this) : ******** CygwinDLLTest.c ******** #include <windows.h> typedef int (*PFN_HELLO)(); typedef void (*PFN_CYGWIN_DLL_INIT)(); int main() { PFN_HELLO fnHello; HMODULE hLib, h = LoadLibrary(TEXT("cygwin1.dll")); PFN_CYGWIN_DLL_INIT init = (PFN_CYGWIN_DLL_INIT)GetProcAddress(h,"cygwin_dll_init"); init(); hLib = LoadLibrary (TEXT("D:\\test\\mydll.dll")); fnHello = (PFN_HELLO) GetProcAddress (hLib, "hello"); return fnHello(); } ******************************************** 4. Set the path variable on Windows system to include "Cygwin\bin\" directory. 5. Build & Run. I ended up with the following exception: 0xc0000005: Access violation reading location 0x003a0048. Here is the full MSVC2010 Debug Output: ********************************* 'CygwinDLLTest.exe': Loaded 'C:\Users\xxxx\Documents\Visual Studio 2010\Projects\CygwinDLLTest\Debug\CygwinDLLTest.exe', Symbol loaded. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\kernelBase.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'D:\Cygwin\bin\cygwin1.dll', Binary was not built with debug information. cYgFFFFFFFF 6119F510 0cYgstd 0x27a70b d 3'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'D:\test\mydll.dll', Binary was not built with debug information. First-chance exception at 0x611075a8 in CygwinDLLTest.exe: 0xc0000005: Access violation reading location 0x003a0048 Unhandled exception at 0x611075a8 in CygwinDLLTest.exe: 0xc0000005: Access violation reading location 0x003a0048 The program '[784] CygwinDLLTest.exe: Native' has exited with code 0 (0x0). ********************************* Now, it's important to notice that the problem wasn't loading those DLL's, as their handlers all got an address different from NULL. The line in the code that cause the exception, was the call to the hello func, inside the DLL file. And before you go and say anything about extern "C" or __declspec(dllimport/dllexport) - won't help. I've tried all of them and it didn't help. (although, AFAIK - I'm using Explicit Linking in terms of MS, orDynamic Loading in terms of UNIX, so __declspec(dllimport/dllexport) is not necessary). I'm really hope the problem is not at the stack definition, as lying over here: "Make sure you have 4K of scratch space at the bottom of your stack" Because I've no clue how to make this happen on MSVC2010 (and apparently, neither do Oleg...:) Now, I know there's a direct reference to my problem in Hans Passant's words over here - still - I couldn't understand how to solve my problem. PS - for whomever wants, this my DLL Dumpbin.exe output: ********************************* Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file D:\test\mydll.dll File Type: DLL Section contains the following exports for mydll.dll 00000000 characteristics 0 time date stamp Thu Jan 01 02:00:00 1970 0.00 version 1 ordinal base 1 number of functions 1 number of names ordinal hint RVA name 1 0 00001120 hello Summary 1000 .bss 1000 .data 1000 .debug_abbrev 1000 .debug_aranges 6000 .debug_info 1000 .debug_line 1000 .debug_loc 1000 .debug_ranges 1000 .debug_str 1000 .edata 1000 .eh_frame 1000 .idata 1000 .rdata 1000 .reloc 1000 .text ********************************* Thank you in advance! -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple