public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Problem going from .o -> .dll
@ 2003-01-13  3:04 Travis Whitton
  2003-01-13  3:04 ` Dave Hooper
  0 siblings, 1 reply; 4+ messages in thread
From: Travis Whitton @ 2003-01-13  3:04 UTC (permalink / raw)
  To: cygwin

Hello,
I've created a very small C library using Cygwin to manipulate the serial
port under Windows. My intention is to create a ruby wrapper around the
library and perform some OLE automation, but I've hit a brick wall. I
have a small test program that I'm testing the library with, and it
works perfectly when I compile it against the libraries object file.

I.e.,
gcc -c serial.c
gcc -o driver driver.c serial.o

$ ./driver.exe
(push a button on the scale attached to the serial port)
+  0.1118 g

However, if I compile to object file to a .dll file as indicated in the
Cygwin documentation, things go awry.

I.e.,
gcc -c serial.c
gcc -I. -L. -shared -o serial.dll serial.o
gcc -I. -L. -o driver driver.c -lserial

$ ./driver.exe
EOF
g(smiley face)Err: Close failed

The program no longer blocks to wait for serial data, and it produces
garbage. The only change is that I'm linking against the dll file
instead of the .o file. I have no prior experience with dll creation, so
I'm at a loss as to what to try next. I didn't want to post my entire
program to the list out of courtesy, but you can get it here:

http://grub.ath.cx/~travis/libserial/libserial.tar.gz

Any help would be greatly appreciated,
Travis Whitton <whitton@atlantic.net>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* Re: Problem going from .o -> .dll
  2003-01-13  3:04 ` Dave Hooper
@ 2003-01-13  3:04   ` Travis Whitton
  2003-01-13  3:23     ` Jim
  0 siblings, 1 reply; 4+ messages in thread
From: Travis Whitton @ 2003-01-13  3:04 UTC (permalink / raw)
  To: cygwin

> This is not a forum for debugging other peoples' code, but ...
> 
> 1.  You are using HANDLE *  instead of HANDLE
> 2.  Your logic for nul termination is totally wrong:
> snip....
> Try that little lot and see what happens.  At the worst it will let you
> diagnose any real error correctly.

Thank you kindly for the suggested fixes. I have applied them; however,
the problem is still there. I guess I can just build my wrapper using
the object file instead of a dll file, but I am curious why the two
would behave differently.

-
Travis Whitton <whitton@atlantic.net>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* Re: Problem going from .o -> .dll
  2003-01-13  3:04 Problem going from .o -> .dll Travis Whitton
@ 2003-01-13  3:04 ` Dave Hooper
  2003-01-13  3:04   ` Travis Whitton
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Hooper @ 2003-01-13  3:04 UTC (permalink / raw)
  To: Travis Whitton; +Cc: cygwin

> $ ./driver.exe
> EOF
> g(smiley face)Err: Close failed

This is not a forum for debugging other peoples' code, but ...

1.  You are using HANDLE *  instead of HANDLE
2.  Your logic for nul termination is totally wrong:
      c->buffer[nBytesRead + 1] = '\0';
    should be
      c->buffer[nBytesRead] = '\0';
    (think about why)
3.  Your logic for detecting End Of File also looks wrong - Quote from
msdn.microsoft.com:  "The ReadFile code to check for the end-of-file
condition (eof) differs for synchronous and asynchronous read operations. 
When a synchronous read operation reaches the end of a file, ReadFile
returns TRUE and sets *lpNumberOfBytesRead to zero".
4.  I would also personally check that CreateFile isn't returning NULL (as
well as your current test for INVALID_HANDLE_VALUE) as that will also
indicate an error.  I also habitually set nBytesRead=0 before calling
ReadFile although I cannot honestly tell you if that will make a
difference.

Try that little lot and see what happens.  At the worst it will let you
diagnose any real error correctly.

d

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* Re: Problem going from .o -> .dll
  2003-01-13  3:04   ` Travis Whitton
@ 2003-01-13  3:23     ` Jim
  0 siblings, 0 replies; 4+ messages in thread
From: Jim @ 2003-01-13  3:23 UTC (permalink / raw)
  To: cygwin

> Thank you kindly for the suggested fixes. I have applied them; however,
> the problem is still there. I guess I can just build my wrapper using
> the object file instead of a dll file, but I am curious why the two
> would behave differently.
> 
cause a DLL is an exe file with a funny extension it's not just objects.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

end of thread, other threads:[~2003-01-08 21:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-13  3:04 Problem going from .o -> .dll Travis Whitton
2003-01-13  3:04 ` Dave Hooper
2003-01-13  3:04   ` Travis Whitton
2003-01-13  3:23     ` Jim

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