Discussion:
How to use SHGetFolderPath()?
(too old to reply)
kathy
2006-01-16 17:15:12 UTC
Permalink
In my code, I try to use the SHGetFolderPath(). I already include the
header file "ShlObj.h". But when I try to build it, I got:

c:\temp\MyCode\MyCodeDlg.cpp(277): error C3861: 'SHGetFolderPath':
identifier not found, even with argument-dependent lookup
Vipin
2006-01-16 17:30:25 UTC
Permalink
define _WIN32_IE=0x500 in your preprocessor defines and add shell32.lib in
your linker libraries list.

Then in your code:-
have this

#include <shlobj.h>

void main()
{
ShGetFolderPath(...);

}

Make sure your platform sdk header files precede in the include path order
and the sdk library path also precedes the library path

Also remember using ShGetFolderPath would make your programs non-functional
on operating systems
like 98, so you had better do like this

#define _WIN32_IE 0x5000
#include <shlobj.h>
typedef SHFOLDERAPI (*pfnSHGetFolderPathA)(HWND hwnd, int csidl, HANDLE
hToken, DWORD dwFlags, LPSTR pszPath);
typedef SHFOLDERAPI (*pfnSHGetFolderPathA)(HWND hwnd, int csidl, HANDLE
hToken, DWORD dwFlags, LPWSTR pszPath);

main()
{
HMODULE hmod = LoadLibrary(_T("shell32.dll"));
pfnSHGetFolderPathA ptr = (pfnSHGetFolderPathA) GetProceAddress(hmod ,
"SHGetFolderPathA");
if(ptr)
ptr(...)
else // on unsupported operating systems
{

}
}
--
Vipin Aravind
Microsoft - MVP
Post by kathy
In my code, I try to use the SHGetFolderPath(). I already include the
identifier not found, even with argument-dependent lookup
kathy
2006-01-16 19:14:17 UTC
Permalink
"Make sure your platform sdk header files precede in the include path
order
and the sdk library path also precedes the library path "

How to do this?
Vipin
2006-01-16 19:22:30 UTC
Permalink
For vs .net2003 , it is tools->options->projects->vc++ directories->Show
directories for: Library files.

Add the new path at the end of the list and move them up the list using the
up arrow.
--
Vipin Aravind
Microsoft - MVP
Post by kathy
"Make sure your platform sdk header files precede in the include path
order
and the sdk library path also precedes the library path "
How to do this?
kathy
2006-01-16 20:35:07 UTC
Permalink
thanks
kathy
2006-01-16 20:40:40 UTC
Permalink
I add:

#define _WIN32_IE 0x5000
#include <ShlObj.h>

and also put the SDK lib and SDK include to the top. But same problem.

What I am missing?
kathy
2006-01-16 20:44:14 UTC
Permalink
I also add "shell32.lib" to property->Linker->input->additional
dependencies
Pete Delgado
2006-01-17 20:57:57 UTC
Permalink
Post by Vipin
void main()
What language is that??? For both standard C and C++ that is an invalid
signature for main...

http://www.delorie.com/djgpp/v2faq/faq22_25.html
http://public.research.att.com/~bs/bs_faq2.html

-Pete
Vipin
2006-01-17 21:18:41 UTC
Permalink
What is the problem with this signature? I have been programming in c/c++
exclusively for past 7 years
and this is not my first program, OK. Go create a c/c++ file, compile and
see. I don't care whatever links
you give me.

void main()
{
}
--
Vipin Aravind
Microsoft - MVP
Post by Pete Delgado
Post by Vipin
void main()
What language is that??? For both standard C and C++ that is an invalid
signature for main...
http://www.delorie.com/djgpp/v2faq/faq22_25.html
http://public.research.att.com/~bs/bs_faq2.html
-Pete
Pete Delgado
2006-01-18 17:58:08 UTC
Permalink
Post by Vipin
What is the problem with this signature?
Did you read the links I provided? It is not valid C or C++. The compiler
and runtime are free to do *anything* they want with this. From crashing
your program to launching nuclear missiles.
Post by Vipin
I have been programming in c/c++ exclusively for past 7 years
and this is not my first program, OK.
Then you have been making the same mistake for 7 years. You should be
improving.
Post by Vipin
Go create a c/c++ file, compile and see.
Just because something compiles and links does not make it a correct
program. This issue is addressed in the first link that I gave to you.

The funny thing is that you are repeating the same argument that most novice
programmers. The sad part is that you are an Microsoft MVP and are just as
wrong and you are teaching new programmers incorrect information.

I suppose one could make the case that you never plan to use another
compiler or another platform, however, if you disable language extensions on
the VS 2005 compiler, you will indeed get the proper warning.

C4326: return type of 'main' should be 'int' instead of 'void'

So I guess that means that you can't change the default compiler settings
either if you plan to continue to use the non-standard contruct.
Post by Vipin
I don't care whatever links
you give me.
That's obvious judging from your general attitude.
Post by Vipin
void main()
{
}
Isn't now, and never was standard C or C++...

-Pete
Vipin
2006-01-18 20:10:33 UTC
Permalink
you are a psycho. You simply won't listen and above that you say that I am
not worth being MVP,
what is wrong in the answers I post.

Go read this which clearly states that main can return void.

I don't care with a DJGPP compiler's documentation

This is a Microsoft Newsgroup and read Microsoft documentation if you
consider my posts are worthless.

http://msdn.microsoft.com./library/default.asp?url=/library/en-us/vclang98/HTML/_pluslang_program_startup.3a_.the_main_function.asp
--
Vipin Aravind
Microsoft - MVP
Post by Pete Delgado
Post by Vipin
What is the problem with this signature?
Did you read the links I provided? It is not valid C or C++. The
compiler and runtime are free to do *anything* they want with this. From
crashing your program to launching nuclear missiles.
Post by Vipin
I have been programming in c/c++ exclusively for past 7 years
and this is not my first program, OK.
Then you have been making the same mistake for 7 years. You should be
improving.
Post by Vipin
Go create a c/c++ file, compile and see.
Just because something compiles and links does not make it a correct
program. This issue is addressed in the first link that I gave to you.
The funny thing is that you are repeating the same argument that most
novice programmers. The sad part is that you are an Microsoft MVP and are
just as wrong and you are teaching new programmers incorrect information.
I suppose one could make the case that you never plan to use another
compiler or another platform, however, if you disable language extensions
on the VS 2005 compiler, you will indeed get the proper warning.
C4326: return type of 'main' should be 'int' instead of 'void'
So I guess that means that you can't change the default compiler settings
either if you plan to continue to use the non-standard contruct.
Post by Vipin
I don't care whatever links
you give me.
That's obvious judging from your general attitude.
Post by Vipin
void main()
{
}
Isn't now, and never was standard C or C++...
-Pete
Pete Delgado
2006-01-18 21:22:03 UTC
Permalink
Post by Vipin
you are a psycho.
That you for resorting to personal insults. That's always helpful.
Post by Vipin
You simply won't listen and above that you say that I am not worth being
MVP,
I did not say that you were not worth being an MVP. I did say that in
*this* particular case you are just as wrong as a novice programmer and that
the fact that you are an MVP makes it worse because others will emulate your
code due to your status as an MVP.

As far as not listening, I have read your posts and I don't believe that I
have misrepresented anything. We simply have a disagreement on the facts.
Post by Vipin
what is wrong in the answers I post.
I have already answered that question several times. Technically you are
incorrect if you purport to be programming in standard C or C++. Certainly
Microsoft has extended the language and allows void main() in particular
versions of the compiler, but it is not standard C or C++ -just as the links
I cited state. This means that your programs are not guaranteed to compile
or run correctly on *any* other compiler -even the newer ones from
Microsoft. I have already shown you that VS 2005 will flag the code with a
warning if you try to compile it.
Post by Vipin
Go read this which clearly states that main can return void.
For the implementation of the Visual C++ 6.0 compiler the Microsoft
extensions allow it, but it is still not standard C or C++. I think that
you are confusing what the compiler will allow with standard C or C++.

BTW: That is why Microsoft has a topic entitled "Breaking Changes" for each
version of the compiler. As the compiler becomes more standards complient,
things like void main() no longer are allowed and will not compile.
Post by Vipin
I don't care with a DJGPP compiler's documentation
The DJGPP compiler documentation comments on standard C. Not just the
compiler's implementation of the standard. Since I don't have a link to the
ANSI/ISO C standards that I could point to, I used the next best thing. I'm
sure that if you had the standards documents you would find similar wording.
Post by Vipin
This is a Microsoft Newsgroup and read Microsoft documentation if you
http://msdn.microsoft.com./library/default.asp?url=/library/en-us/vclang98/HTML/_pluslang_program_startup.3a_.the_main_function.asp
Again, this refers to a Microsoft extension to the language. What I am
commenting on is standard C and C++ which is independant of any compiler. I
simply was pointing out that void main() is not standard C or C++. You seem
to want to make the argument that it is, which is dead wrong.

There are many cases where you may want to write a portable library using
Visual Studio and the Microsoft C++ compiler, why put yourself at a
disadvantage and target the Microsoft flavor of C++ and not portable,
standards complient C++?
Post by Vipin
consider my posts are worthless.
I never said that I consider your posts worthless. Since you obviously
spend a great deal of time answering questions in the newsgroup and for the
most part give fairly good information it would be silly for me to assert
such a thing. I don't know how you got that impression from my posts. I am
simply saying that you are mistaken on *this* particular point.


-Pete
Vipin
2006-01-18 21:43:53 UTC
Permalink
I have no clue why this should become a big hype. I will agree to your
remarks from a standard c/c++ perspective.

Your thread tries not to address the OP's topic(yes or no) and says the
program is
invalid. Isn't this a vc++ newsgroup? I never say, the code I provide here
is going to build on other environments.All I use is the Microsoft VC++
compiler.

If you go buy c++ Primer from Stanley Lippman( whom I assume is an architect
on vc++ team )
There are several dozens of places where his code shows up as
int main()
{
....
}

There isn't a return statement being called, may be he has an errata now in
place somewhere, I don't know.
Does that make him an ignorant person to you?

For me he is a C++ God. I considering programming methodologies more
important than mugging up
all of syntax of a langauage and specifics of each standard.

If you are that smart, tell me what this the below expression would evaluate
to without running it in a program.

"Hello"[1] == ??? ( again if you are man, you should say rightaway before
you compile/run and ask the compiler
to give you the answer)
--
Vipin Aravind
Microsoft - MVP
Post by Pete Delgado
Post by Vipin
you are a psycho.
That you for resorting to personal insults. That's always helpful.
Post by Vipin
You simply won't listen and above that you say that I am not worth being
MVP,
I did not say that you were not worth being an MVP. I did say that in
*this* particular case you are just as wrong as a novice programmer and
that the fact that you are an MVP makes it worse because others will
emulate your code due to your status as an MVP.
As far as not listening, I have read your posts and I don't believe that I
have misrepresented anything. We simply have a disagreement on the facts.
Post by Vipin
what is wrong in the answers I post.
I have already answered that question several times. Technically you are
incorrect if you purport to be programming in standard C or C++.
Certainly Microsoft has extended the language and allows void main() in
particular versions of the compiler, but it is not standard C or C++ -just
as the links I cited state. This means that your programs are not
guaranteed to compile or run correctly on *any* other compiler -even the
newer ones from Microsoft. I have already shown you that VS 2005 will
flag the code with a warning if you try to compile it.
Post by Vipin
Go read this which clearly states that main can return void.
For the implementation of the Visual C++ 6.0 compiler the Microsoft
extensions allow it, but it is still not standard C or C++. I think that
you are confusing what the compiler will allow with standard C or C++.
BTW: That is why Microsoft has a topic entitled "Breaking Changes" for
each version of the compiler. As the compiler becomes more standards
complient, things like void main() no longer are allowed and will not
compile.
Post by Vipin
I don't care with a DJGPP compiler's documentation
The DJGPP compiler documentation comments on standard C. Not just the
compiler's implementation of the standard. Since I don't have a link to
the ANSI/ISO C standards that I could point to, I used the next best
thing. I'm sure that if you had the standards documents you would find
similar wording.
Post by Vipin
This is a Microsoft Newsgroup and read Microsoft documentation if you
http://msdn.microsoft.com./library/default.asp?url=/library/en-us/vclang98/HTML/_pluslang_program_startup.3a_.the_main_function.asp
Again, this refers to a Microsoft extension to the language. What I am
commenting on is standard C and C++ which is independant of any compiler.
I simply was pointing out that void main() is not standard C or C++. You
seem to want to make the argument that it is, which is dead wrong.
There are many cases where you may want to write a portable library using
Visual Studio and the Microsoft C++ compiler, why put yourself at a
disadvantage and target the Microsoft flavor of C++ and not portable,
standards complient C++?
Post by Vipin
consider my posts are worthless.
I never said that I consider your posts worthless. Since you obviously
spend a great deal of time answering questions in the newsgroup and for
the most part give fairly good information it would be silly for me to
assert such a thing. I don't know how you got that impression from my
posts. I am simply saying that you are mistaken on *this* particular
point.
-Pete
Pete Delgado
2006-01-18 22:44:16 UTC
Permalink
Post by Vipin
I have no clue why this should become a big hype. I will agree to your
remarks from a standard c/c++ perspective.
Your thread tries not to address the OP's topic(yes or no)
The OP had been pointed in the correct direction and appeared to have gotten
it to work. It would have not served any purpose to answer the question
again. I merely wanted to point out that "technically" your answer was
incorrect if you were writing C or C++ and to point anyone who was curious
as to why, in the proper direction.
Post by Vipin
and says the program is
invalid. Isn't this a vc++ newsgroup? I never say, the code I provide here
is going to build on other environments.All I use is the Microsoft VC++
compiler.
The point that I made earlier is that the code that you have written is not
guaranteed to compile even on a newer version of the Microsoft compiler
because it does not conform to the standard. A simple code change is all
that is required and you're good to go. Why would you continue to resist
it? What purpose does it serve?
Post by Vipin
If you go buy c++ Primer from Stanley Lippman( whom I assume is an
architect on vc++ team )
I believe he is involved if my MSDN magazines are correct!
Post by Vipin
There are several dozens of places where his code shows up as
int main()
{
....
}
There isn't a return statement being called, may be he has an errata now
in place somewhere, I don't know.
The code is correct if it is C++. In the C++ standard it is stated that
there is an "implicit" return value of 0 if one is not explicitly written.
So, as written, the code is correct if it is C++. This information was
contained in the second link that I gave you.
Post by Vipin
Does that make him an ignorant person to you?
No. His code is accurate and he is far more articulate and knowlegable
about the standards than I am.
Post by Vipin
For me he is a C++ God.
Then perhaps you would consider emulating him! ;)
Post by Vipin
I considering programming methodologies more important than mugging up
all of syntax of a langauage and specifics of each standard.
There lies the rub. There are many places to trip you up in languages like
C and C++. If you are not aware of the places that have tripped others up
before you, you are destined to make the same mistakes. There are times
when order of evaluation, sequence points and other such minutae of the
language make a huge difference. It is best to learn these things before
you write the bug that takes a week to find!

It doesn't necessarily mean that you have to become a language lawyer, but
it does mean that you need to pay attention to the details of the language.
Post by Vipin
If you are that smart, tell me what this the below expression would
evaluate to without running it in a program.
"Hello"[1] == ??? ( again if you are man, you should say rightaway
before you compile/run and ask the compiler
to give you the answer)
I don't claim to be perfect, but given that your example is malformed and
won't compile as given anyway, I can only guess at what you are looking for
since given the code, what you *really* get is a compiler error due to the
invalid trigraph sequence and lack of semi-colon.

Let's see though, we have a narrow string literal which means that we have a
type of "6 element array of const char" and static storage duration. You
are referencing the second array element at position [1] with a value that
represents 'e'. You are comparing it with something, but the rest of the
line is invalid as the compiler would surely tell you.


-Pete
Vipin
2006-01-19 03:49:28 UTC
Permalink
Now you are saying Microsoft c++ compiler has issues.

This is the warning I get for:-
int main()
{
}
main.cpp
main.cpp(6) : warning C4508: 'main' : function should return a value; 'void'
ret
urn type assumed
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Now what is your logic, Is it language extenstions?

I just posed what this expression would evaluate to "Hello"[1].

But you are really strange, you are expecting me to type in a semicolon
here.
Come on, I won't be able to write a single program without knowing about
semicolons in c/c++,
and I think you may be even thinking that is the case. Anyway I have no need
to do any convincing.
--
Vipin Aravind
Microsoft - MVP
Post by Pete Delgado
Post by Vipin
I have no clue why this should become a big hype. I will agree to your
remarks from a standard c/c++ perspective.
Your thread tries not to address the OP's topic(yes or no)
The OP had been pointed in the correct direction and appeared to have
gotten it to work. It would have not served any purpose to answer the
question again. I merely wanted to point out that "technically" your
answer was incorrect if you were writing C or C++ and to point anyone who
was curious as to why, in the proper direction.
Post by Vipin
and says the program is
invalid. Isn't this a vc++ newsgroup? I never say, the code I provide here
is going to build on other environments.All I use is the Microsoft VC++
compiler.
The point that I made earlier is that the code that you have written is
not guaranteed to compile even on a newer version of the Microsoft
compiler because it does not conform to the standard. A simple code
change is all that is required and you're good to go. Why would you
continue to resist it? What purpose does it serve?
Post by Vipin
If you go buy c++ Primer from Stanley Lippman( whom I assume is an
architect on vc++ team )
I believe he is involved if my MSDN magazines are correct!
Post by Vipin
There are several dozens of places where his code shows up as
int main()
{
....
}
There isn't a return statement being called, may be he has an errata now
in place somewhere, I don't know.
The code is correct if it is C++. In the C++ standard it is stated that
there is an "implicit" return value of 0 if one is not explicitly written.
So, as written, the code is correct if it is C++. This information was
contained in the second link that I gave you.
Post by Vipin
Does that make him an ignorant person to you?
No. His code is accurate and he is far more articulate and knowlegable
about the standards than I am.
Post by Vipin
For me he is a C++ God.
Then perhaps you would consider emulating him! ;)
Post by Vipin
I considering programming methodologies more important than mugging up
all of syntax of a langauage and specifics of each standard.
There lies the rub. There are many places to trip you up in languages
like C and C++. If you are not aware of the places that have tripped
others up before you, you are destined to make the same mistakes. There
are times when order of evaluation, sequence points and other such minutae
of the language make a huge difference. It is best to learn these things
before you write the bug that takes a week to find!
It doesn't necessarily mean that you have to become a language lawyer, but
it does mean that you need to pay attention to the details of the language.
Post by Vipin
If you are that smart, tell me what this the below expression would
evaluate to without running it in a program.
"Hello"[1] == ??? ( again if you are man, you should say rightaway
before you compile/run and ask the compiler
to give you the answer)
I don't claim to be perfect, but given that your example is malformed and
won't compile as given anyway, I can only guess at what you are looking
for since given the code, what you *really* get is a compiler error due to
the invalid trigraph sequence and lack of semi-colon.
Let's see though, we have a narrow string literal which means that we have
a type of "6 element array of const char" and static storage duration.
You are referencing the second array element at position [1] with a value
that represents 'e'. You are comparing it with something, but the rest
of the line is invalid as the compiler would surely tell you.
-Pete
Pete Delgado
2006-01-19 07:01:34 UTC
Permalink
Post by Vipin
Now you are saying Microsoft c++ compiler has issues.
No. I said that the Microsoft compiler includes non-standard extensions and
is not completely standards complient.
Post by Vipin
This is the warning I get for:-
int main()
{
}
main.cpp
main.cpp(6) : warning C4508: 'main' : function should return a value;
'void' ret
urn type assumed
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
If you turn off the extensions in VS 2005 you will recieve the error that I
quoted. The fact that you are using a compiler that is at least 3 releases
old and released before the C++ standard was released means that many of the
standard complience issues still remain in the compiler that you are using.
What did you expect from an 8 year old compiler?

I'm not saying that VC++ 6 isn't a good tool, just that it is dated and that
I would not expect it to conform to the C++ standard.
Post by Vipin
Now what is your logic, Is it language extenstions?
The particular implementation that you are using was good -at the time it
was released. But it is old. Still usable, but old. It was released even
before the ISO/EIC C++ standard if I recall correctly. If you take a look
at the C++ standard library you will notice that it includes many things
that are nonstandard and nonconforming. While it would be nice for the
compiler to flag your erroneous code, it apparently doesn't.

That is not a statement of logic, but a statement of fact.
Post by Vipin
I just posed what this expression would evaluate to "Hello"[1].
No, that is distinctly different than what you posted earlier. The
expression that you posted earlier was
"Hello"[1] == ???

Which I have already parsed and explained. If you meant something else, you
should have written it or explained it. In any case, I have posted a
response for all to see, have you?
Post by Vipin
But you are really strange, you are expecting me to type in a semicolon
here.
No. I expect that if you wish me to waste my time solving your silly little
riddles that you at least post code that will compile or explain your little
"test" explicitly. If you plan to post code fragments, identify them as
such.
Post by Vipin
Come on, I won't be able to write a single program without knowing about
semicolons in c/c++,
Really? Using the included project wizard in Visual C++ 6.0 you can create
and compile a complete working program without knowing *anything* about C++
or semi-colons. All you need to know is how to use a mouse and a keyboard.
Certainly it is trivial, but it proves your statement incorrect -again...
Post by Vipin
and I think you may be even thinking that is the case. Anyway I have no
need to do any convincing.
You have already convinced me that you desperately need the following links
should your ego allow you to look.

http://home.att.net/%7Ejackklein/ctips01.html#int_main
http://www.comeaucomputing.com/learn/faq/

Otherwise, enjoy yourself chasing elusive bugs!

-Pete
Vipin
2006-01-19 09:22:54 UTC
Permalink
look, my intention of representing like this
was to intend what the right side of the equality operator would be.

"Hello"[1] == ???

I don't intend to continue this thread anyway.
--
Vipin Aravind
Microsoft MVP
Post by Pete Delgado
Post by Vipin
Now you are saying Microsoft c++ compiler has issues.
No. I said that the Microsoft compiler includes non-standard extensions
and is not completely standards complient.
Post by Vipin
This is the warning I get for:-
int main()
{
}
main.cpp
main.cpp(6) : warning C4508: 'main' : function should return a value;
'void' ret
urn type assumed
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
If you turn off the extensions in VS 2005 you will recieve the error that
I quoted. The fact that you are using a compiler that is at least 3
releases old and released before the C++ standard was released means that
many of the standard complience issues still remain in the compiler that
you are using. What did you expect from an 8 year old compiler?
I'm not saying that VC++ 6 isn't a good tool, just that it is dated and
that I would not expect it to conform to the C++ standard.
Post by Vipin
Now what is your logic, Is it language extenstions?
The particular implementation that you are using was good -at the time it
was released. But it is old. Still usable, but old. It was released even
before the ISO/EIC C++ standard if I recall correctly. If you take a look
at the C++ standard library you will notice that it includes many things
that are nonstandard and nonconforming. While it would be nice for the
compiler to flag your erroneous code, it apparently doesn't.
That is not a statement of logic, but a statement of fact.
Post by Vipin
I just posed what this expression would evaluate to "Hello"[1].
No, that is distinctly different than what you posted earlier. The
expression that you posted earlier was
"Hello"[1] == ???
Which I have already parsed and explained. If you meant something else,
you should have written it or explained it. In any case, I have posted a
response for all to see, have you?
Post by Vipin
But you are really strange, you are expecting me to type in a semicolon
here.
No. I expect that if you wish me to waste my time solving your silly
little riddles that you at least post code that will compile or explain
your little "test" explicitly. If you plan to post code fragments,
identify them as such.
Post by Vipin
Come on, I won't be able to write a single program without knowing about
semicolons in c/c++,
Really? Using the included project wizard in Visual C++ 6.0 you can
create and compile a complete working program without knowing *anything*
about C++ or semi-colons. All you need to know is how to use a mouse and
a keyboard. Certainly it is trivial, but it proves your statement
incorrect -again...
Post by Vipin
and I think you may be even thinking that is the case. Anyway I have no
need to do any convincing.
You have already convinced me that you desperately need the following
links should your ego allow you to look.
http://home.att.net/%7Ejackklein/ctips01.html#int_main
http://www.comeaucomputing.com/learn/faq/
Otherwise, enjoy yourself chasing elusive bugs!
-Pete
Loading...