Jump to page: 1 2
Thread overview
ShellExecute
Feb 11, 2008
Serj Makaroff
Feb 11, 2008
Simen Kjaeraas
Feb 11, 2008
Serj Makaroff
Feb 11, 2008
Sergey Gromov
Feb 11, 2008
doob
Feb 12, 2008
Sergey Gromov
Feb 13, 2008
torhu
Re: extern(Windows) export in std.c.windows.windows
Feb 16, 2008
Sergey Gromov
Feb 16, 2008
torhu
Feb 11, 2008
Matti Niemenmaa
February 11, 2008
Hello!

I try to use WinAPI function ShellExecute() to start web browser in new
process. I wrote such definition
export {
HINSTANCE ShellExecute(HWND hwnd,LPCTSTR lpOperation,LPCTSTR lpFile,LPCTSTR
lpParameters,LPCTSTR lpDirectory,INT nShowCmd);
}

and called function in such way:

HINSTANCE i = ShellExecute(null, mode, url, null, null, SW_SHOW);

Also I found in MSDN, that this function is in shell32.dll. I added

pragma(lib, "shell32.lib");

I obtain linker error "Symbol Undefined..." Help, pls
February 11, 2008
On Mon, 11 Feb 2008 19:18:27 +0100, Serj Makaroff <serj-makaroff@yandex.ru> wrote:

> Hello!
>
> I try to use WinAPI function ShellExecute() to start web browser in new
> process. I wrote such definition
> export {
> HINSTANCE ShellExecute(HWND hwnd,LPCTSTR lpOperation,LPCTSTR lpFile,LPCTSTR
> lpParameters,LPCTSTR lpDirectory,INT nShowCmd);
> }
>
> and called function in such way:
>
> HINSTANCE i = ShellExecute(null, mode, url, null, null, SW_SHOW);
>
> Also I found in MSDN, that this function is in shell32.dll. I added
>
> pragma(lib, "shell32.lib");
>
> I obtain linker error "Symbol Undefined..." Help, pls

When changing the definition to

extern (Windows)
{
	HINSTANCE ShellExecuteA(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, INT);
	HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT);
}

this works for me.

February 11, 2008
Thank you! It's work.

But why ShellExecute() doesn't work and what is the difference between
ShellExecuteA() and ShellExecuteW()?
February 11, 2008
Serj Makaroff <serj-makaroff@yandex.ru> wrote:
> Thank you! It's work.
> 
> But why ShellExecute() doesn't work and what is the difference between
> ShellExecuteA() and ShellExecuteW()?

There is no such Windows function like ShellExecute().  There is ShellExecuteA() which accepts ASCII (CHAR/CHAR*) parameters and returns compatible results, and ShellExecuteW() which accepts Unicode (WCHAR/WCHAR*) parameters and returns accordingly.  The ShellExecute is a macro defined in windows.h for C preprocessor, there is no such symbol in the OS.  This macro expands to either of the former functions depending on whether the _UNICODE macro is defined.  This holds true for most of Windows API.

This reminds me: why all the standard D headers declare Windows functions as

extern(Windows) export void SomeApiFunction() ?

What's the use for export attribute ?

-- 
SnakE
February 11, 2008
Serj Makaroff wrote:
> But why ShellExecute() doesn't work and what is the difference between
> ShellExecuteA() and ShellExecuteW()?

ShellExecute is a macro, #defined somewhere in windows.h as either ShellExecuteA or ShellExecuteW depending on whether you're using Unicode or not.

Many Windows functions are similar #defines. If something doesn't link out of the box, try appending A or W (whichever is the one you want): most of the time it solves the problem.

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
February 11, 2008
Sergey Gromov wrote:
> Serj Makaroff <serj-makaroff@yandex.ru> wrote:
>> Thank you! It's work.
>>
>> But why ShellExecute() doesn't work and what is the difference between
>> ShellExecuteA() and ShellExecuteW()?
> 
> There is no such Windows function like ShellExecute().  There is ShellExecuteA() which accepts ASCII (CHAR/CHAR*) parameters and returns compatible results, and ShellExecuteW() which accepts Unicode (WCHAR/WCHAR*) parameters and returns accordingly.  The ShellExecute is a macro defined in windows.h for C preprocessor, there is no such symbol in the OS.  This macro expands to either of the former functions depending on whether the _UNICODE macro is defined.  This holds true for most of Windows API.
> 
> This reminds me: why all the standard D headers declare Windows functions as
> 
> extern(Windows) export void SomeApiFunction() ?
> 
> What's the use for export attribute ?
> 

From the language specification: "Export means that any code outside the executable can access the member. Export is analogous to exporting definitions from a DLL."

Tango doesn't use export with win api functions
February 12, 2008
doob <doobnet@gmail.com> wrote:
> Sergey Gromov wrote:
> > This reminds me: why all the standard D headers declare Windows functions as
> > 
> > extern(Windows) export void SomeApiFunction() ?
> > 
> > What's the use for export attribute ?
> > 
> 
>  From the language specification: "Export means that any code outside
> the executable can access the member. Export is analogous to exporting
> definitions from a DLL."
> 
> Tango doesn't use export with win api functions

Thanks.  I did know what the specs were saying, I was just wondering if I missed something.  I also know that it does work without `export'--- because I've tried.  Is it a left-over from an earlier versions of the language ?  The example-driven programmers keep copying this code around, making it sort of common practice...

-- 
SnakE
February 13, 2008
Sergey Gromov wrote:
 > Thanks.  I did know what the specs were saying, I was just wondering if
> I missed something.  I also know that it does work without `export'---
> because I've tried.  Is it a left-over from an earlier versions of the language ?  The example-driven programmers keep copying this code around, making it sort of common practice...
> 

I guess you're supposed to use it where you'd use __declspec(dllimport) in C, but it I'm not sure why it works anyway for functions.  It's possible that it's not needed since a function prototype can never be a definiton.  So it's safe for the linker to resolve it to a function in the import library (.lib).  Unless the function is defined in another module you're linking with.  Not sure what happens then, maybe you just get that function instead of the one in the dll.

It's needed when linking to variables that are in a DLL, though.  If you don't add it, even variable declarations with the 'extern' storage class will turn into definitions.
February 13, 2008
"Sergey Gromov" <snake.scaly@gmail.com> wrote in message news:MPG.221c192f273aa432989691@news.digitalmars.com...

>
> Thanks.  I did know what the specs were saying, I was just wondering if I missed something.  I also know that it does work without `export'--- because I've tried.  Is it a left-over from an earlier versions of the language ?  The example-driven programmers keep copying this code around, making it sort of common practice...

I think it's used when exporting a symbol _from_ a library/app (i.e. as a symbol to export from a DLL, which does actually work), but when dealing with external symbols, I'm not entirely sure what it's supposed to do.  I suppose if it works fine without it, there's no need for it.  It might just be one of those cases where D ignores spurious protection attributes.


February 16, 2008
torhu <no@spam.invalid> wrote:
> It's needed when linking to variables that are in a DLL, though.  If you don't add it, even variable declarations with the 'extern' storage class will turn into definitions.

This explains it, thanks.  This also means that export is sometimes also import because extern is not actually for an extern symbol but merely a calling convention specifier.

I can live with that. :)

-- 
SnakE
« First   ‹ Prev
1 2