compiling a simple ShellExecute with C

H

hkMicro

Having problems compiling the following code in C USING CL.EXE
// shell.c LANGUAGE = .NET 2003
#include <iostream.h>
#include <windows.h>

int main()
{
SHELLEXECUTE(NULL, "open", "notepad.exe", NULL, NULL, SW_SHOWNORMAL);
RETURN 0;
}

Results:

C:\ > CL /EHs shell.c
....... Incremental Linker Version 6.00.8447
......
shell.obj : error LNK2001: unresolved external symbol __imp__ShellExecuteA@24
shell.exe : fatal error LNK1120: 1 unresolved externals
C:\>

I suppose the problem has to do with Unicode. but am not sure. Any help
appreciated.

Thanks,

Hank
 
M

Mattias Sjögren

SHELLEXECUTE(NULL, "open", "notepad.exe", NULL, NULL, SW_SHOWNORMAL);

The function is called ShellExecute, not SHELLEXECUTE.

C:\ > CL /EHs shell.c
...... Incremental Linker Version 6.00.8447
.....
shell.obj : error LNK2001: unresolved external symbol __imp__ShellExecuteA@24
shell.exe : fatal error LNK1120: 1 unresolved externals

Try adding

/link shell32.lib



Mattias
 
H

hkMicro

Try adding

/link shell32.lib
Thank you, Mattias. That definitely compiled and it works.

Just starting to use this C with the command line compiler. So, whenever the
Documentation says in the Function Information something like:
"Import Library : shell32.lib"
I need to tell the compiler to link against that library.

But I notice that if I eliminate the <windows.h> and replace it with
<shellapi.h>--the documentation says: " Header : shellapi.h"--I receive about
100 errors. But If I just include <windows.h> by itself alone (no
<iostream.h>)

This must be because I'm compiling on Windows? And need to include the
Windows headers?

Thanks,

Hank
 
B

Ben Voigt [C++ MVP]

hkMicro said:
Thank you, Mattias. That definitely compiled and it works.

Just starting to use this C with the command line compiler. So, whenever
the
Documentation says in the Function Information something like:
"Import Library : shell32.lib"
I need to tell the compiler to link against that library.

But I notice that if I eliminate the <windows.h> and replace it with
<shellapi.h>--the documentation says: " Header : shellapi.h"--I receive
about
100 errors. But If I just include <windows.h> by itself alone (no
<iostream.h>)

Most all Win32 functions should be brought in using windows.h regardless of
which header is listed on the documentation.

You may want to try to #define WINVER, _WIN32_WINNT, WIN32_LEAN_AND_MEAN and
STRICT to speed up compile times

See http://msdn2.microsoft.com/en-us/library/aa383745.aspx
 
D

David Wilkinson

hkMicro said:
Having problems compiling the following code in C USING CL.EXE
// shell.c LANGUAGE = .NET 2003
#include <iostream.h>
#include <windows.h>

int main()
{
SHELLEXECUTE(NULL, "open", "notepad.exe", NULL, NULL, SW_SHOWNORMAL);
RETURN 0;
}

Results:

C:\ > CL /EHs shell.c
...... Incremental Linker Version 6.00.8447
.....
shell.obj : error LNK2001: unresolved external symbol __imp__ShellExecuteA@24
shell.exe : fatal error LNK1120: 1 unresolved externals
C:\>

I suppose the problem has to do with Unicode. but am not sure. Any help
appreciated.

Hank:

Note that iostream (which you are not actually using) is C, not C++. And
<iostream.h> is an obsolete header (use <iostream>).

You are not really in the right group; use microsoft.public.vc.language
for questions that do not have to do with.NET.
 
D

David Wilkinson

David said:
Hank:

Note that iostream (which you are not actually using) is C, not C++. And
<iostream.h> is an obsolete header (use <iostream>).

You are not really in the right group; use microsoft.public.vc.language
for questions that do not have to do with.NET.

Of course I meant: iostream is C++, not C.
 
J

Jeffrey Tan[MSFT]

Hi Hank,

Yes, this is because <Windows.h> includes a lot of important(or must have)
windows header files, such as <windef.h>, <winbase.h> etc... These files
define must of the windows structures types, such as DWORD, BOOL etc..

So we'd better always include <windows.h> if you are programming Windows
SDK applications. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Hank,

Have you reviewed all the replies to you? If you still need any help or
have any concern, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top