Unicode Problem with CreateFile

View: New views
5 Messages — Rating Filter:   Alert me  

Unicode Problem with CreateFile

by Brian Heilig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Eiffel Software,

I appear to be having a unicode issue when opening a COM port using
CreateFile. When I execute the attached code (see below) it fails to
open the COM port. However, if I remove -DUNICODE from the compiler
options, the COM port is successfully opened. I guess it has something
to do with the file name, or the way I'm passing it. What am I doing
wrong?

I'm using Eiffel Studio 6.1 and Microsoft C++ Express 2008.

Thanks,
Brian

class

        TEST_DEVICE

create

        make

feature {NONE} -- Initialization

make is
                -- Test opening the com port
        local
                external_name: ANY
                handle: POINTER
                b: BOOLEAN
        do
                external_name := ("COM1").to_c

                handle := cwin_create_file ($external_name,
                        Generic_read | Generic_write,
                        0, Default_pointer, Open_existing, 0,
                        Default_pointer)

                if (handle = Invalid_handle_value) then
                        io.put_string ("It didn't open")
                else
                        io.put_string ("IT OPENED!")
                end

                b := cwin_close_handle (handle)
        end

feature {NONE} -- Externals

cwin_create_file (lpFileName: POINTER; dwDesiredAccess: INTEGER;
                dwShareMode: INTEGER; lpSecurityAttributes: POINTER;
                dwCreationDisposition, dwFlagsAndAttributes: INTEGER;
                hTemplateFile: POINTER): POINTER is
        external
                "C use <windows.h>"
        alias
                "CreateFile"
        end

cwin_close_handle (hObject: POINTER): BOOLEAN is
        external
                "C use <windows.h>"
        alias
                "CloseHandle"
        end

Open_existing: INTEGER is
        external
                "C inline use <windows.h>"
        alias
                "OPEN_EXISTING"
        end

Generic_read: INTEGER is
        external
                "C inline use <windows.h>"
        alias
                "GENERIC_READ"
        end

Generic_write: INTEGER is
        external
                "C inline use <windows.h>"
        alias
                "GENERIC_WRITE"
        end

Invalid_handle_value: POINTER is
        external
                "C inline use <windows.h>"
        alias
                "INVALID_HANDLE_VALUE"
        end

end -- class SECOM_TEST



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


RE: Unicode Problem with CreateFile

by Emmanuel Stapf [ES] :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The solution is to use the following:

l_name: WEL_STRING

create l_name.make ("COM1")

handle := cwin_create_file (l_name.item,
                Generic_read | Generic_write,
                0, Default_pointer, Open_existing, 0,
                Default_pointer)

The issue here was that Eiffel strings are ASCII strings by default and we
now always use the unicode version of Windows API. So you have to use a
windows unicode string (WEL_STRING) as argument.

Usually I do not recommend using the $ operator to pass an Eiffel string to
a C external. A while ago we have introduced MANAGED_POINTER and C_STRING
for that purpose. WEL_STRING is a variant of C_STRING for the Windows
platform.

Hope this helps,
Manu


> -----Original Message-----
> From: eiffel_software@...
> [mailto:eiffel_software@...] On Behalf Of Brian Heilig
> Sent: Tuesday, May 13, 2008 11:47 AM
> To: eiffel_software@...
> Subject: [eiffel_software] Unicode Problem with CreateFile
>
> Dear Eiffel Software,
>
> I appear to be having a unicode issue when opening a COM port
> using CreateFile. When I execute the attached code (see
> below) it fails to open the COM port. However, if I remove
> -DUNICODE from the compiler options, the COM port is
> successfully opened. I guess it has something to do with the
> file name, or the way I'm passing it. What am I doing wrong?
>
> I'm using Eiffel Studio 6.1 and Microsoft C++ Express 2008.
>
> Thanks,
> Brian
>
> class
>
> TEST_DEVICE
>
> create
>
> make
>
> feature {NONE} -- Initialization
>
> make is
> -- Test opening the com port
> local
> external_name: ANY
> handle: POINTER
> b: BOOLEAN
> do
> external_name := ("COM1").to_c
>
> handle := cwin_create_file ($external_name,
> Generic_read | Generic_write,
> 0, Default_pointer, Open_existing, 0,
> Default_pointer)
>
> if (handle = Invalid_handle_value) then
> io.put_string ("It didn't open")
> else
> io.put_string ("IT OPENED!")
> end
>
> b := cwin_close_handle (handle)
> end
>
> feature {NONE} -- Externals
>
> cwin_create_file (lpFileName: POINTER; dwDesiredAccess: INTEGER;
> dwShareMode: INTEGER; lpSecurityAttributes: POINTER;
> dwCreationDisposition, dwFlagsAndAttributes: INTEGER;
> hTemplateFile: POINTER): POINTER is
> external
> "C use <windows.h>"
> alias
> "CreateFile"
> end
>
> cwin_close_handle (hObject: POINTER): BOOLEAN is
> external
> "C use <windows.h>"
> alias
> "CloseHandle"
> end
>
> Open_existing: INTEGER is
> external
> "C inline use <windows.h>"
> alias
> "OPEN_EXISTING"
> end
>
> Generic_read: INTEGER is
> external
> "C inline use <windows.h>"
> alias
> "GENERIC_READ"
> end
>
> Generic_write: INTEGER is
> external
> "C inline use <windows.h>"
> alias
> "GENERIC_WRITE"
> end
>
> Invalid_handle_value: POINTER is
> external
> "C inline use <windows.h>"
> alias
> "INVALID_HANDLE_VALUE"
> end
>
> end -- class SECOM_TEST
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Catcall during projection of EV_FIGURE objects

by d.tuser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>    
I tried to use the EV_FIGURE classes, but there was always a problem
because of catcalls. So I tried the example "egraph" and there is the
same problem. It happens if one clicks e.g. on the "+10" button. The
projection routine calls an agent function resulting in the error:
Catcall detected for  argument#1 `args': expected  TUPLE [EV_MODEL_LINE]
but got TUPLE [EV_MODEL]

Is there a workaround for that?

Regards
Daniel

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: Catcall during projection of EV_FIGURE objects

by Jocelyn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Daniel,

First, note that you can disable catcall warning when the system is
launched by the EiffelStudio debugger. For that, either go to menu
Execution>Exceptions (then first checkboxes of the dialog), or using the
drop down menu of the "[Start]" button.

Otherwise, you can use the most recent eiffel class for
EV_MODEL_PROJECTION_ROUTINES (revision 73517)
https://svn.origo.ethz.ch/eiffelstudio/trunk/Src/library/vision2/interface/model/ev_model_projection_routines.e
(this version should be integrated with next 6.2 release)

--Jocelyn

On 5/13/2008 22:25 PM, Daniel Tuser wrote:

>>    
>>    
> I tried to use the EV_FIGURE classes, but there was always a problem
> because of catcalls. So I tried the example "egraph" and there is the
> same problem. It happens if one clicks e.g. on the "+10" button. The
> projection routine calls an agent function resulting in the error:
> Catcall detected for  argument#1 `args': expected  TUPLE [EV_MODEL_LINE]
> but got TUPLE [EV_MODEL]
>
> Is there a workaround for that?
>
> Regards
> Daniel
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>
>
>  



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: Catcall during projection of EV_FIGURE objects

by d.tuser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jocelyn,

Thanks a lot.

> Hi Daniel,
>
> First, note that you can disable catcall warning when the system is
> launched by the EiffelStudio debugger. For that, either go to menu
> Execution>Exceptions (then first checkboxes of the dialog), or using the
> drop down menu of the "[Start]" button.
>
> Otherwise, you can use the most recent eiffel class for
> EV_MODEL_PROJECTION_ROUTINES (revision 73517)
> https://svn.origo.ethz.ch/eiffelstudio/trunk/Src/library/vision2/interface/model/ev_model_projection_routines.e 
> <https://svn.origo.ethz.ch/eiffelstudio/trunk/Src/library/vision2/interface/model/ev_model_projection_routines.e>
> (this version should be integrated with next 6.2 release)
>
> --Jocelyn
>
> On 5/13/2008 22:25 PM, Daniel Tuser wrote:
> >>
> >>
> > I tried to use the EV_FIGURE classes, but there was always a problem
> > because of catcalls. So I tried the example "egraph" and there is the
> > same problem. It happens if one clicks e.g. on the "+10" button. The
> > projection routine calls an agent function resulting in the error:
> > Catcall detected for argument#1 `args': expected TUPLE [EV_MODEL_LINE]
> > but got TUPLE [EV_MODEL]
> >
> > Is there a workaround for that?
> >
> > Regards
> > Daniel
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
>
>  


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/