473,785 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with microsoft C compiler doesn`t accept things gcc does,how to solve? (encoding)

Here is the example code.

int main(int argc, char *argv[])
{
string Result;
WIN32_FIND_DATA daten;
HANDLE h = FindFirstFile(T EXT("c://test"), &daten);
system("PAUSE") ;
return EXIT_SUCCESS;
}

It works fine with DevCpp and gcc.

The error with microsoft C compiler is that he can`t convert from string
to LPCSTR.

I think the problem is inside the encoding, ansi, unicode, ... Found
some ways to avoid this error but all are not very awesome.

Please tell me the best way to solve this.
Jul 16 '07 #1
17 4104
Michael Reichenbach wrote:
Here is the example code.
"Example"? Of what?
>
int main(int argc, char *argv[])
You're not using 'argc' or 'argv' in your code here, why declare them?
{
string Result;
'string' is undefined.
WIN32_FIND_DATA daten;
'WIN32_FIND_DAT A' is undefined.
HANDLE h = FindFirstFile(T EXT("c://test"), &daten);
'HANDLE' is undefined. 'FindFirstFile' is undefined. 'TEXT' is
undefined.
system("PAUSE") ;
return EXIT_SUCCESS;
}

It works fine with DevCpp and gcc.
I doubt that.
The error with microsoft C compiler is that he can`t convert from
string to LPCSTR.
By "string" do you mean the standard 'string' type? Then yes, there
is no such conversion (even if by 'LPCSTR' you mean 'char const*').
>
I think the problem is inside the encoding, ansi, unicode, ... Found
some ways to avoid this error but all are not very awesome.

Please tell me the best way to solve this.
To solve WHAT?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 16 '07 #2
Michael Reichenbach wrote:
Here is the example code.

int main(int argc, char *argv[])
{
string Result;
WIN32_FIND_DATA daten;
HANDLE h = FindFirstFile(T EXT("c://test"), &daten);
system("PAUSE") ;
return EXIT_SUCCESS;
}

It works fine with DevCpp and gcc.
That's odd, with gcc I get:

gcct.c: In function `main':
gcct.c:3: error: `string' undeclared (first use in this function)
gcct.c:3: error: (Each undeclared identifier is reported only once
gcct.c:3: error: for each function it appears in.)
gcct.c:3: error: parse error before "Result"
gcct.c:4: error: `WIN32_FIND_DAT A' undeclared (first use in this
function)
gcct.c:5: error: `HANDLE' undeclared (first use in this function)
gcct.c:7: error: `EXIT_SUCCESS' undeclared (first use in this function)
The error with microsoft C compiler is that he can`t convert from
string to LPCSTR.

I think the problem is inside the encoding, ansi, unicode, ... Found
some ways to avoid this error but all are not very awesome.
You obviously haven't posted the real code.

Brian

Jul 16 '07 #3
Ok. You got me. :) It`s was not the real code. I always try to cut down
my problem to a minimum so it`s more easy to figure out.

Here is a new example code. I tested it. It works in DevCpp but not in
Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}
Jul 16 '07 #4

Michael Reichenbach <Re*********@di scardmail.comwr ote in message...
Here is the example code.

int main(int argc, char *argv[]){
// string Result; // not defined, not used!
WIN32_FIND_DATA daten;
HANDLE h = FindFirstFile(T EXT("c://test"), &daten);
system("PAUSE") ;
return EXIT_SUCCESS;
}
It works fine with DevCpp and gcc.
Nope!
The error with microsoft C compiler is that he can`t convert from string
to LPCSTR.
std::string Hi( "Hello" );
LPCSTR pHi = &Hi.at(0); // pick one
char const *pHi2 = &Hi.at(0);
LPCSTR pHi3 = Hi.c_str();
..... etc.
I think the problem is inside the encoding, ansi, unicode, ... Found
some ways to avoid this error but all are not very awesome.
Please tell me the best way to solve this.
#include <iostream>
#include <fstream>

int main(){
std::ifstream in( "c:/test" );
if( not in.is_open() ){
std::cout<<"Fil e not found!\n";
}
system("PAUSE") ;
return EXIT_SUCCESS;
} // main()
--
Bob R
POVrookie
Jul 17 '07 #5
The error with microsoft C compiler is that he can`t convert from string
to LPCSTR.

std::string Hi( "Hello" );
LPCSTR pHi = &Hi.at(0); // pick one
char const *pHi2 = &Hi.at(0);
LPCSTR pHi3 = Hi.c_str();
Is it right? I thought Hi.c_str() returns a temporary c-string, it
will be gone when pHi3 try to dereference it?

Jul 17 '07 #6
On 2007-07-17 01:45, Michael Reichenbach wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut down
my problem to a minimum so it`s more easy to figure out.

Here is a new example code. I tested it. It works in DevCpp but not in
Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}
1. Quote the text you are replying to.

2. In what way does it not work in Visual Studio (what version of VS by
the way?), does it kick you in the face or what. Post the error messages
or whatever you get.

See http://www.parashift.com/c++-faq-lit...t.html#faq-5.8 for
more info on what to include in your posts.

--
Erik Wikström
Jul 17 '07 #7
sun1991 wrote:
:::: The error with microsoft C compiler is that he can`t convert
:::: from string to LPCSTR.
:::
::: std::string Hi( "Hello" );
::: LPCSTR pHi = &Hi.at(0); // pick one
::: char const *pHi2 = &Hi.at(0);
::: LPCSTR pHi3 = Hi.c_str();
:: Is it right? I thought Hi.c_str() returns a temporary c-string, it
:: will be gone when pHi3 try to dereference it?

It returns a pointer to a C-string (which might be a copy of Hi's
content). The pointer is valid as long as Hi isn't potentially
modified.

Bo Persson
Jul 17 '07 #8
On Jul 16, 6:45 pm, Michael Reichenbach <Reichenb...@di scardmail.com>
wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut down
my problem to a minimum so it`s more easy to figure out.

Here is a new example code. I tested it. It works in DevCpp but not in
Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;

}- Hide quoted text -

- Show quoted text -
Do you have UNICODE (or maybe it's _UNICODE, I always forget)
defined? There is no way that code should fail under windows unless
FindFirstFile is expecting a wide character string, and it shouldn't
expect a wide string unless you have _UNICODE or UNICODE defined.

See if the following works:
int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(L "c://test", &FindFileDat a); //notice
the L
system("PAUSE") ;
return EXIT_SUCCESS;
}

Venturing into off-topicness, but assuming this fixes it, one possible
reason it works with one compiler but not the other could be that
you're defining the preprocessor symbol through your project settings
(Project -Project Propert -C++ -Preprocessor), which obviously
GCC doesn't know about.

The way windows functions work is that there's always 2 versions of
most WinApi functions. One ends with an 'A' and expects char*, the
other ends with a 'W' and expects wchar_t*. Then, based on the value
of various preprocessor symbols, a version of every function with
neither A nor W is #defined to the A or W version. So if you have
UNICODE defined, FindFirstFile actually is FindFirstFileW( wchar_t*,
WIN_32_FIND_DAT A*), and if you don't have UNICODE defined,
FindFirstFile actually is FindFirstFileA( char*, WIN32_FIND_DATA *).
The same is true for many other functions as well.

Jul 17 '07 #9
Michael Reichenbach wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut
down my problem to a minimum so it`s more easy to figure out.
That's a good idea, but what you post has to be a complete program.
Here is a new example code. I tested it. It works in DevCpp but not
in Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}

This compiled on gcc?
gcct.c:2:21: windows.h: No such file or directory
gcct.c:7: warning: data definition has no type or storage class
gcct.c:8: error: `FindFileData' undeclared here (not in a function)
gcct.c:8: error: initializer element is not constant
gcct.c:8: warning: data definition has no type or storage class
gcct.c:9: error: parse error before string constant
gcct.c:9: warning: data definition has no type or storage class


Brian
Jul 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5623
by: trexim | last post by:
Hi, I am trying to create a Web Reference for CSTA using the URL http://www.ecma-international.org/standards/ecma-348/csta-wsdl/csta-wsdl-all-operations.wsdl Visual .Net complains that: " The document was understood, but it could not be processed. - The WSDL document contains links that could not be resolved. - There was an error downloading
18
6177
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the strcat (mystract). Program below. However this appears not to have fixed the problem and I don't know why it shouldn't ? Any further help as to what else I am doing wrong will be appreciated regards
5
2346
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and run this works fine. but if build in unicode release or release this does't work. IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
4
4580
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET forum). I don't use server controls in it (apart from Page). The problem occurs on the page where visitor can post a new messages. Basically, it's a form with couple of
5
8631
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
16
4929
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
2
7053
by: Peter2 | last post by:
Hi, I have a problem posting non-ASCII characters in FORM fields between classic ASP and ASP.NET. I use a fully patched Windows 2000 Advanced Server with .net 2.0 and visual Studio 2005 installed, IIS, IE6 etc ... When an *.ASPX page receives the post, it drops non-ASCII characters, for example it drops character é from word Montréal. Specifying explicit encoding on ASP/ASPX page doesn't help. The encoding works without doing anything...
3
3447
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I got no reply, in an OpenGL group somebody recommended me to use Visual C++ which I did. That worked OK but I do would like to use Watcom. In the meantime I found solutions to several of the errors I got but one is left which I cannot find a...
159
7129
by: bernard | last post by:
howdy! please recommend a good c compiler. - should be small - should be fast - should come with a good ide - should be inexpensive i am using windows os.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.