www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Calling ShellExecute to open a URL in the default browser

reply Daniel Worthington <daniel.worthington gmail.com> writes:
I am trying to compile the following code using:
dmd test.d
  or
dmd test.d shell32.lib


import std.c.windows.windows;

int main(string[] args) {

    extern (Windows) HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR,
LPCWSTR, LPCWSTR, INT);

    HINSTANCE i = ShellExecuteW(null, "open",
"http://www.example.com", null, null, SW_SHOW);

    return 0;

}


In either case I get the following error:

import std.c.windows.windows;

int main(string[] args) {

    extern (Windows) HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR,
LPCWSTR, LPCWSTR, INT);

    HINSTANCE i = ShellExecuteW(null, "open",
"http://www.example.com", null, null, SW_SHOW);

    return 0;

}

Error 42: Symbol Undefined
__D4test4mainFAAyaZi13ShellExecuteWMWT4core3sys7windows7windows6HANDLEPxuPxuPxuPxuiZT4core3sys7windows7windows6HANDLE 24


I think I must be doing something really stupid, and I'm new to D :-)

Daniel
Aug 04 2010
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Daniel Worthington <daniel.worthington gmail.com> wrote:

 import std.c.windows.windows;

 int main(string[] args) {

     extern (Windows) HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR,
 LPCWSTR, LPCWSTR, INT);

     HINSTANCE i = ShellExecuteW(null, "open",
 "http://www.example.com", null, null, SW_SHOW);

     return 0;

 }

 Error 42: Symbol Undefined
 __D4test4mainFAAyaZi13ShellExecuteWMWT4core3sys7windows7windows6HANDLEPxuPxuPxuPxuiZT4core3sys7windows7windows6HANDLE 24

Move your declaration of ShellExecuteW outside main, and it will work: import std.c.windows.windows; extern (Windows) HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT); int main(string[] args) { HINSTANCE i = ShellExecuteW(null, "open", "http://www.example.com", null, null, SW_SHOW); return 0; } This should work, though, so I'm filing a bug on it: http://d.puremagic.com/issues/show_bug.cgi?id=4581 -- Simen
Aug 04 2010