Go to Post And, just for the record, dlavery is on my mental ignore list from September until January if the thread involves the word "hint" at all. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-08-2005, 21:00
sciguy125 sciguy125 is offline
Electrical Engineer
AKA: Phil Baltar
FRC #1351
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Sunnyvale, CA
Posts: 519
sciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond repute
Send a message via AIM to sciguy125 Send a message via MSN to sciguy125 Send a message via Yahoo to sciguy125
CreateFile() problem

Are there any windows programmers around? I'm having some issues with CreateFile() from the win32 api. I'm compiling with MinGW and it's giving me the following error:

loader\serialio.cpp:192: error: cannot convert `const char*' to `const WCHAR*' for argument `1' to `void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'

here's the appropriate code:

port = CreateFile(dev.c_str(),GENERIC_READ|GENERIC_WRITE, 0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

dev is a std::string. I'm new to windows programming, so I might be missing something. All the documentation I can find, however, says that the first parameter should be a null terminated string. c_str() is supposed to give me that. I've also tried to use the following and I get an idential error:

port = CreateFile("COM1",GENERIC_READ|GENERIC_WRITE,0,0,O PEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

Which leads me to believe that it's not that simple.
__________________

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GE/S/P a-- e y-- r-- s:++ d+ h! X+++
t++ C+ P+ L++ E W++ w M-- V? PS+ PE+
5- R-- tv+ b+ DI+++ D- G
------END GEEK CODE BLOCK------
  #2   Spotlight this post!  
Unread 16-08-2005, 23:50
sciguy125 sciguy125 is offline
Electrical Engineer
AKA: Phil Baltar
FRC #1351
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Sunnyvale, CA
Posts: 519
sciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond repute
Send a message via AIM to sciguy125 Send a message via MSN to sciguy125 Send a message via Yahoo to sciguy125
Re: CreateFile() problem

I figured it out. My Makefile was trying to be helpful and defined UNICODE in the compiler options. Apparently, the compiler doesn't like that. I'm not really sure why it's defined or why it works without it, but it taking it out fixed the problem.
__________________

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GE/S/P a-- e y-- r-- s:++ d+ h! X+++
t++ C+ P+ L++ E W++ w M-- V? PS+ PE+
5- R-- tv+ b+ DI+++ D- G
------END GEEK CODE BLOCK------
  #3   Spotlight this post!  
Unread 17-08-2005, 02:26
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: CreateFile() problem

Quote:
Originally Posted by sciguy125
Apparently, the compiler doesn't like that. I'm not really sure why it's defined or why it works without it, but it taking it out fixed the problem.
Just FYI, this is because standard ASCII strings (char*) use 8 bits per character but Unicode (WCHAR*) use more (16 bits I believe). The compiler correctly stopped you from passing a string of 16 bit characters to a function that is expecting 8 bits per character. If it hadn't, your program would have behaved very unexpectedly.
  #4   Spotlight this post!  
Unread 17-08-2005, 11:25
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Re: CreateFile() problem

Quote:
Originally Posted by Dave Flowerday
Just FYI, this is because standard ASCII strings (char*) use 8 bits per character but Unicode (WCHAR*) use more (16 bits I believe). The compiler correctly stopped you from passing a string of 16 bit characters to a function that is expecting 8 bits per character. If it hadn't, your program would have behaved very unexpectedly.
To add just a little bit more information to this, when UNICODE is defined, WCHAR is 16-bits but when it is not defined WCHAR is only 8-bits (the same as a regular char). This is why the cast was failing.

Matt
  #5   Spotlight this post!  
Unread 17-08-2005, 13:37
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: CreateFile() problem

Quote:
Originally Posted by sciguy125
I figured it out. My Makefile was trying to be helpful and defined UNICODE in the compiler options. Apparently, the compiler doesn't like that. I'm not really sure why it's defined or why it works without it, but it taking it out fixed the problem.
I knew it had to be something like that because of the CreateFileW, and the WCHAR* in the error message. I assumed, though, that you needed wide character strings for some reason, and I was looking around for a way to create a wide string from an 8 bit one.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming Problem: Extremely Frustrating chantilly_team Programming 19 12-02-2005 23:00
Physics Problem Venkatesh Math and Science 13 30-11-2004 20:30
Ok one problem cantwell03 Programming 3 13-02-2003 07:28
The problem with scouting... archiver 2001 10 23-06-2002 23:49
Major problem with chipphua motors aka Scott White Motors 18 19-03-2002 19:44


All times are GMT -5. The time now is 00:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi