public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* DllMain not called
@ 2020-02-07  8:47 Olivia Nelson
  2020-02-07 14:49 ` Marco Atzeri
  0 siblings, 1 reply; 10+ messages in thread
From: Olivia Nelson @ 2020-02-07  8:47 UTC (permalink / raw)
  To: cygwin

I have a simple C program that output something to DbgView on startup:

#include <windows.h>
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        OutputDebugStringA("DLL_PROCESS_ATTACH called");
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

I didn't observe anything when the DLL is loaded, what was wrong?

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

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

* Re: DllMain not called
  2020-02-07  8:47 DllMain not called Olivia Nelson
@ 2020-02-07 14:49 ` Marco Atzeri
  2020-02-07 15:07   ` Olivia Nelson
  0 siblings, 1 reply; 10+ messages in thread
From: Marco Atzeri @ 2020-02-07 14:49 UTC (permalink / raw)
  To: cygwin

Am 07.02.2020 um 09:46 schrieb Olivia Nelson:
> I have a simple C program that output something to DbgView on startup:
> 
> #include <windows.h>
> BOOL APIENTRY DllMain( HMODULE hModule,
>                         DWORD  ul_reason_for_call,
>                         LPVOID lpReserved
>                       )
> {
>      switch (ul_reason_for_call)
>      {
>      case DLL_PROCESS_ATTACH:
>          OutputDebugStringA("DLL_PROCESS_ATTACH called");
>      case DLL_THREAD_ATTACH:
>      case DLL_THREAD_DETACH:
>      case DLL_PROCESS_DETACH:
>          break;
>      }
>      return TRUE;
> }
> 
> I didn't observe anything when the DLL is loaded, what was wrong?
> 

This seems a pure Windows program, not a Unix like.

How you compiled it and how are you tring to run it ?

Regards
Marco

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

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

* Re: DllMain not called
  2020-02-07 14:49 ` Marco Atzeri
@ 2020-02-07 15:07   ` Olivia Nelson
  2020-02-07 15:46     ` Marco Atzeri
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Olivia Nelson @ 2020-02-07 15:07 UTC (permalink / raw)
  To: cygwin

I compile it like this:
gcc dll.c -shared -fPIC -o dll.dll

I tried to run it with LoadLibraryA

But DllMain is not called.


On Fri, Feb 7, 2020 at 10:49 PM Marco Atzeri <marco.atzeri@gmail.com> wrote:
>
> Am 07.02.2020 um 09:46 schrieb Olivia Nelson:
> > I have a simple C program that output something to DbgView on startup:
> >
> > #include <windows.h>
> > BOOL APIENTRY DllMain( HMODULE hModule,
> >                         DWORD  ul_reason_for_call,
> >                         LPVOID lpReserved
> >                       )
> > {
> >      switch (ul_reason_for_call)
> >      {
> >      case DLL_PROCESS_ATTACH:
> >          OutputDebugStringA("DLL_PROCESS_ATTACH called");
> >      case DLL_THREAD_ATTACH:
> >      case DLL_THREAD_DETACH:
> >      case DLL_PROCESS_DETACH:
> >          break;
> >      }
> >      return TRUE;
> > }
> >
> > I didn't observe anything when the DLL is loaded, what was wrong?
> >
>
> This seems a pure Windows program, not a Unix like.
>
> How you compiled it and how are you tring to run it ?
>
> Regards
> Marco
>
> --
> 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
>

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

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

* Re: DllMain not called
  2020-02-07 15:07   ` Olivia Nelson
@ 2020-02-07 15:46     ` Marco Atzeri
  2020-02-07 18:19     ` Joost Kraaijeveld
  2020-02-07 19:10     ` Joost Kraaijeveld
  2 siblings, 0 replies; 10+ messages in thread
From: Marco Atzeri @ 2020-02-07 15:46 UTC (permalink / raw)
  To: cygwin

Am 07.02.2020 um 16:07 schrieb Olivia Nelson:
> I compile it like this:
> gcc dll.c -shared -fPIC -o dll.dll
> 
> I tried to run it with LoadLibraryA
> 
> But DllMain is not called.
> 
> 

you are building a Cygwin dll, that requires the Cygwin1.dll
but probably do you not intend it and need a standalone one that
requires only the MS system dll's.

install the Mingw crosscompiler x86_64-w64-mingw32-gcc.exe
that is in the package

$ cygcheck -f /usr/bin/x86_64-w64-mingw32-gcc.exe
mingw64-x86_64-gcc-core-7.4.0-1

and compile as
x86_64-w64-mingw32-gcc.exe -Wall dll.c -shared -fPIC -o dll.dll

Regards
Marco

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

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

* Re: DllMain not called
  2020-02-07 15:07   ` Olivia Nelson
  2020-02-07 15:46     ` Marco Atzeri
@ 2020-02-07 18:19     ` Joost Kraaijeveld
  2020-02-07 19:10     ` Joost Kraaijeveld
  2 siblings, 0 replies; 10+ messages in thread
From: Joost Kraaijeveld @ 2020-02-07 18:19 UTC (permalink / raw)
  To: cygwin

Does

static void __attribute__((constructor)) 
static void __attribute__((destructor)) 

work?

See also: 
https://stackoverflow.com/questions/2053029/how-exactly-does-attribute-constructor-work




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

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

* Re: DllMain not called
  2020-02-07 15:07   ` Olivia Nelson
  2020-02-07 15:46     ` Marco Atzeri
  2020-02-07 18:19     ` Joost Kraaijeveld
@ 2020-02-07 19:10     ` Joost Kraaijeveld
  2020-02-08  0:12       ` DllMain not called in CreateRemoteThread Olivia Nelson
  2 siblings, 1 reply; 10+ messages in thread
From: Joost Kraaijeveld @ 2020-02-07 19:10 UTC (permalink / raw)
  To: cygwin

Does

static void __attribute__((constructor)) 
static void __attribute__((destructor)) 

work?


See e.g. 
https://stackoverflow.com/questions/2053029/how-exactly-does-attribute-constructor-work




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

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

* Re: DllMain not called in CreateRemoteThread
  2020-02-07 19:10     ` Joost Kraaijeveld
@ 2020-02-08  0:12       ` Olivia Nelson
  2020-02-08  5:40         ` Marco Atzeri
  0 siblings, 1 reply; 10+ messages in thread
From: Olivia Nelson @ 2020-02-08  0:12 UTC (permalink / raw)
  To: cygwin

Sorry, I made a mistake. I've updated the title ..

To summarize:

1. I can load the DLL compiled with cygwin with LoadLibraryA,
     but not remotely with CreateRemoteThread.
2. The same DLL compiled with msvc works with both LoadLibraryA and
CreateRemoteThread

Answer to Joost:
constructor and destructor are called with LoadLibraryA, but not with
CreateRemoteThread either

Answer to Marco
1. I can't use mingw, it does not provide sys/XXX.h, e,g socket
2. I copied cygwin1.dll to system32, and it works outside cygwin environment

Here's a implementation of the DLL injector in C#:
https://codingvision.net/miscellaneous/c-inject-a-dll-into-a-process-w-createremotethread


On Sat, Feb 8, 2020 at 3:10 AM Joost Kraaijeveld
<J.Kraaijeveld@askesis.nl> wrote:
>
> Does
>
> static void __attribute__((constructor))
> static void __attribute__((destructor))
>
> work?
>
>
> See e.g.
> https://stackoverflow.com/questions/2053029/how-exactly-does-attribute-constructor-work
>
>
>
>
> --
> 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
>

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

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

* Re: DllMain not called in CreateRemoteThread
  2020-02-08  0:12       ` DllMain not called in CreateRemoteThread Olivia Nelson
@ 2020-02-08  5:40         ` Marco Atzeri
  2020-02-09 14:52           ` Olivia Nelson
  0 siblings, 1 reply; 10+ messages in thread
From: Marco Atzeri @ 2020-02-08  5:40 UTC (permalink / raw)
  To: cygwin

please bottom post on this mailing list

Am 08.02.2020 um 01:12 schrieb Olivia Nelson:
> Sorry, I made a mistake. I've updated the title ..
> 
> To summarize:
> 
> 1. I can load the DLL compiled with cygwin with LoadLibraryA,
>       but not remotely with CreateRemoteThread.
> 2. The same DLL compiled with msvc works with both LoadLibraryA and
> CreateRemoteThread
> 
> Answer to Joost:
> constructor and destructor are called with LoadLibraryA, but not with
> CreateRemoteThread either
> 
> Answer to Marco
> 1. I can't use mingw, it does not provide sys/XXX.h, e,g socket
> 2. I copied cygwin1.dll to system32, and it works outside cygwin environment
> 
> Here's a implementation of the DLL injector in C#:
> https://codingvision.net/miscellaneous/c-inject-a-dll-into-a-process-w-createremotethread
> 

Which of the sys/XXX.h are you looking for ?

$ cygcheck -l mingw64-x86_64-headers | grep "/sys/"
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sec_api/sys/timeb_s.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/cdefs.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/fcntl.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/file.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/locking.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/param.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/time.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/timeb.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/types.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/unistd.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/utime.h

for what I know the Windows program use winsock2.h and winsock.h
for their own socket interface

$ cygcheck -l mingw64-x86_64-headers | grep "sock"
/usr/x86_64-w64-mingw32/sys-root/mingw/include/hvsocket.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/mswsock.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/_socket_types.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h


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

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

* Re: DllMain not called in CreateRemoteThread
  2020-02-08  5:40         ` Marco Atzeri
@ 2020-02-09 14:52           ` Olivia Nelson
  2020-02-10 18:50             ` Andrey Repin
  0 siblings, 1 reply; 10+ messages in thread
From: Olivia Nelson @ 2020-02-09 14:52 UTC (permalink / raw)
  To: cygwin

I need to use unix socket() interface, mingw does not seem to provide
the following headers:

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <sys/wait.h>


On Sat, Feb 8, 2020 at 1:40 PM Marco Atzeri <marco.atzeri@gmail.com> wrote:
>
> please bottom post on this mailing list
>
> Am 08.02.2020 um 01:12 schrieb Olivia Nelson:
> > Sorry, I made a mistake. I've updated the title ..
> >
> > To summarize:
> >
> > 1. I can load the DLL compiled with cygwin with LoadLibraryA,
> >       but not remotely with CreateRemoteThread.
> > 2. The same DLL compiled with msvc works with both LoadLibraryA and
> > CreateRemoteThread
> >
> > Answer to Joost:
> > constructor and destructor are called with LoadLibraryA, but not with
> > CreateRemoteThread either
> >
> > Answer to Marco
> > 1. I can't use mingw, it does not provide sys/XXX.h, e,g socket
> > 2. I copied cygwin1.dll to system32, and it works outside cygwin environment
> >
> > Here's a implementation of the DLL injector in C#:
> > https://codingvision.net/miscellaneous/c-inject-a-dll-into-a-process-w-createremotethread
> >
>
> Which of the sys/XXX.h are you looking for ?
>
> $ cygcheck -l mingw64-x86_64-headers | grep "/sys/"
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sec_api/sys/timeb_s.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/cdefs.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/fcntl.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/file.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/locking.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/param.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/time.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/timeb.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/types.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/unistd.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/utime.h
>
> for what I know the Windows program use winsock2.h and winsock.h
> for their own socket interface
>
> $ cygcheck -l mingw64-x86_64-headers | grep "sock"
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/hvsocket.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/mswsock.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/_socket_types.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock.h
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h
>
>
> --
> 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
>

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

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

* Re: DllMain not called in CreateRemoteThread
  2020-02-09 14:52           ` Olivia Nelson
@ 2020-02-10 18:50             ` Andrey Repin
  0 siblings, 0 replies; 10+ messages in thread
From: Andrey Repin @ 2020-02-10 18:50 UTC (permalink / raw)
  To: Olivia Nelson, cygwin

Greetings, Olivia Nelson!

> I need to use unix socket() interface, mingw does not seem to provide
> the following headers:

There's no UNIX interfaces in native applications.
Choose one or another, not both.

> #include <sys/types.h>
> #include <sys/socket.h>
> #include <sys/mman.h>
> #include <sys/wait.h>


Also, please no top posting in this list.
And quoting email addresses is strongly discouraged. Don't feed the spam bots.


-- 
With best regards,
Andrey Repin
Monday, February 10, 2020 21:44:10

Sorry for my terrible english...


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

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

end of thread, other threads:[~2020-02-10 18:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07  8:47 DllMain not called Olivia Nelson
2020-02-07 14:49 ` Marco Atzeri
2020-02-07 15:07   ` Olivia Nelson
2020-02-07 15:46     ` Marco Atzeri
2020-02-07 18:19     ` Joost Kraaijeveld
2020-02-07 19:10     ` Joost Kraaijeveld
2020-02-08  0:12       ` DllMain not called in CreateRemoteThread Olivia Nelson
2020-02-08  5:40         ` Marco Atzeri
2020-02-09 14:52           ` Olivia Nelson
2020-02-10 18:50             ` Andrey Repin

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).