473,837 Members | 1,677 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 4109
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
5627
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
6185
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
2351
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
4584
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
8636
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
4935
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
7062
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
3448
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
7144
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
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9683
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
10579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9412
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
7814
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
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5852
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
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
4050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.