public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Question regarding building dlls
@ 2000-12-18 15:33 Greg Clinton
  2000-12-18 16:36 ` Charles S. Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Clinton @ 2000-12-18 15:33 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

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.clinton@wonderware.com

------------------------------mydll.cpp------------------------------
#include <windows.h>

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 <windows.h>

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@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@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@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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question regarding building dlls
  2000-12-18 15:33 Question regarding building dlls Greg Clinton
@ 2000-12-18 16:36 ` Charles S. Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Charles S. Wilson @ 2000-12-18 16:36 UTC (permalink / raw)
  To: Greg Clinton; +Cc: 'cygwin@cygwin.com'

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.clinton@wonderware.com
> 
> ------------------------------mydll.cpp------------------------------
> #include <windows.h>
> 
> 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 <windows.h>
> 
> 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@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@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@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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-12-18 16:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-18 15:33 Question regarding building dlls Greg Clinton
2000-12-18 16:36 ` Charles S. Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).