• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

ShellExecute(...htm) fails with 16 bit

The following code below works fine with Delphi 3...it calls up a Web page.  However, when the very same code is run from Delphi 1, nothing at all happens.  Same machine (NT 4), same user.

The Instance return value when run from Delphi 1 is "33", if that helps any.

Why does this code not function successfully with Delphi 1?

var
      Instance: THandle;
begin
      try
            Instance := ShellExecute(Application.Handle, 'open','http://www.yahoo.com/index.htm', Nil,
                  nil, SW_SHOWNORMAL      );
            showmessage(inttostr(instance));
      except

      end;
end;
0
Softtech
Asked:
Softtech
  • 9
  • 7
  • 4
  • +1
1 Solution
 
ahalyaCommented:
If there is an error then ShellExecute returns a value less than 32 !!
(see Delphi help on ShellExec)

since you're getting 33, i wonder whether there is really an error.
0
 
ahalyaCommented:
just a quick thought

instead of specifying "nil" as the parameters try sending in a null string.

ShellExecute(App.Handle, 'open','http://www.yahoo.com/index.htm', '','', SW_SHOWNORMAL );
0
 
intheCommented:
i thought shellexecute is 32 bit and only work in delphi 1 on a win3.1 machine ,maybe not
have you tried winexec or createprocess instead


and as ahayla said 33 ?? should be 32 or less
what about this instead of showmessage(inttostr(instance));
 
if instance<=32 then
  begin
   Application.MessageBox('An Error Occured',
   'Error',mbOK+mbIconHand);
end;
Regards Barry
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
SofttechAuthor Commented:
>>Instead of specifying "nil" as the parameters try sending
>>in a null string.

>> ShellExecute(App.Handle,
>>'open','http://www.yahoo.com/index.htm', '','', SW_SHOWNORMAL );

I tried your suggestion, and it does the very same thing as when I use "Nil".

Here is something else I discovered.  IF, and only IF, I already have a Web browser up and running, then, and only then, will the above code take me to Yahoo!  However, if I shut the browser down and exit, then running the above code does nothing.  It simply returns an Instance of 33, but that's it.  No Web browser window pops up, and no Yahoo!

Any further ideas?  Again, the above code works flawlessly in Delhpi 3, but in Delhpi 1, I can only get to Yahoo IF an existing browser window is already up and active.

OK, I tried your suggestion.
0
 
SofttechAuthor Commented:
To Barry (inthe)

>>and as ahayla said 33 ?? should be 32 or less
>>what about this instead of showmessage(inttostr(instance));

I never said that the ShellExecute was returning an error.  All I said was that the Instance value was 33.  I realize 32 or less are error values, but that is not relevant in this case.

As far as ShellExecute being 32 bit...I don't think so.  ShellExecute shows up in Delphi 1's API help file.
0
 
intheCommented:
ok i stand corrected :-)
maybe this is wrong to but i have never used 'open' in shellexecute statement i always put nil there instead and it works ok.
B.T.W if thats the address your using it needs to be 'html' not 'htm' but i suspect thats an example only
Regards Barry



0
 
heathprovostCommented:
To help anyone else working on this problem - I just tested questioners code verbatim in Delphi 1 under Windows 98 - Works perfectly fine. Must be something with NT - Am checking on that now.
0
 
SofttechAuthor Commented:
>>maybe this is wrong to but i have never used 'open' in
>>shellexecute statement i always put
>>   nil there instead and it works ok.

To Barry (inthe)

I tried replacing 'open' with Nil, and it makes no difference.

Also, the "www.yahoo.com/index.htm" is just an example.  Actually, it should make no difference.  Changing .htm to .html gives the same results...i.e., under NT 4, with Delphi 1, the browser window will never open.

0
 
SofttechAuthor Commented:
>>maybe this is wrong to but i have never used 'open' in
>>shellexecute statement i always put
>>   nil there instead and it works ok.

To Barry (inthe)

I tried replacing 'open' with Nil, and it makes no difference.

Also, the "www.yahoo.com/index.htm" is just an example.  Actually, it should make no difference.  Changing .htm to .html gives the same results...i.e., under NT 4, with Delphi 1, the browser window will never open.

0
 
SofttechAuthor Commented:
>>maybe this is wrong to but i have never used 'open' in
>>shellexecute statement i always put
>>   nil there instead and it works ok.

To Barry (inthe)

I tried replacing 'open' with Nil, and it makes no difference.

Also, the "www.yahoo.com/index.htm" is just an example.  Actually, it should make no difference.  Changing .htm to .html gives the same results...i.e., under NT 4, with Delphi 1, the browser window will never open.

0
 
SofttechAuthor Commented:
Ooops.  Looks I pressed SUBMIT a wee too many times.

Sorry folks for the redundant comment.  ;-(
0
 
heathprovostCommented:
I do not understand this one.  I have tested your code under Delphi 3 and Delphi 1 under both Windows 98 and Windows NT 4 and it works perfectly!  Everytime I run it the return value is 42 and it works whether browser is open or not. I have even compiled under each OS with both environments and works the same.  I think you should try to look to see if problem is maybe with the installation of NT or even the installation of Delphi 1.  Hope this helps
0
 
intheCommented:
ok
the reason i said html was because i wondered if the system recognized the extension htm was related to internet document
i've had that trouble before when i was playing with registry keys i deleted one by mistake and couldnt open htm files.

any luck heathprovost?
Regards Barry
0
 
heathprovostCommented:
I do not understand this one.  I have tested your code under Delphi 3 and Delphi 1 under both Windows 98 and Windows NT 4 and it works perfectly!  Everytime I run it the return value is 42 and it works whether browser is open or not. I have even compiled under each OS with both environments and works the same.  I think you should try to look to see if problem is maybe with the installation of NT or even the installation of Delphi 1.  Hope this helps
0
 
SofttechAuthor Commented:
>>I do not understand this one.  I have tested your code
>> under Delphi 3 and Delphi 1 under
>>both Windows 98 and Windows NT 4 and it works perfectly!


Thank you for taking the time to test this on NT4.  After receiving your reply, I rebooted my NT 4 workstation, then tried this exercise again.  Unfortunately, the same results occur.  Under Delphi 1...no browser window.  Under Delphi 3...browser window pops up and the HTML page/Web site gets loaded.

I can't see this as a bad Delphi 1 install, for if I take the same code, compile it on a Win98 PC, then take the compiled EXE to the NT machine...the same thing occurs...i.e., no browser window, no Web page loaded.  It can't be a bad Delphi 1 install, therefore.
0
 
heathprovostCommented:
I have a theory here if you are willing to try it.  Create or copy a HTM file and save it on your hardrive. then replace your code with the following and see what happens.

var
Instance: THandle;
AppFileName: Array [0..255] of char;
begin
  Instance := ShellExecute(Application.Handle,
  'open','C:\whatever.htm', Nil,
  nil, SW_SHOWNORMAL );
  If Instance > 32 then
  If FindExecutable('whatever.htm', 'C:\', AppFileName) > 32 then
    showmessage(inttostr(instance) +  StrPas(AppFileName))
  else
    showmessage(inttostr(instance) + ' No App Associated');
end;

This should at least tell you what application your code is calling under Delphi 1.  I bet it probably works right with a local file also.  My guess it is some kind of problem with your browsers file association. Please reply on this one it is very interesting.
0
 
SofttechAuthor Commented:
To heathprovost...

Thanks for sticking with me.  Your theory resulted in fixing the problem, but I don't know why.

I used your suggestion and saved/created a HTML file on my hard disk, then ran ShellExecute on that disk file.  This worked fine, and brought up Netscape Communicator, and loaded the saved HTML file.  I then reverted back to my original problematic code in Delphi 1, and ran it, with Netscape closed.

To my surprise, the following code now works!...

Instance := ShellExecute(Application.Handle, 'open','http://www.yahoo.com/index.htm', Nil,
    nil, SW_SHOWNORMAL );

.or to be more precise, it starts up Netscape and attempts to connect to Yahoo.

I even rebooted and tried again, thinking that the problem would come back again to haunt me...but so far, the above code works fine now.  Any ideas as to why executing your code SHOOK some sense into NT?

I can't believe NT didn't know what to do with HTM/HTML extensions, because even when the problem existed, I could go to "Start > Run" and type http://www.yahoo.com/index.htm and Netscape would start.  So surely NT knew what to do with the HTM extension, or perhaps it simply knew what to do with "http", and not HTM?
0
 
intheCommented:
well done heathprovost :-)
0
 
heathprovostCommented:
I dont know how to explain that one.  The reason I had you make a local file is because the FindExecutable function requires one (it wont work with a url).  I did some searching for Specific problems with NT, and I did find one on the MS Knowledge base.  Are you positive your original code has SW_SHOWNORMAL for the show flag?  The KB article stated the EXACT same behavior you were experiance if you called ShellExecute from a 16-bit app, but only if you used SW_SHOWDEFAULT as the flag.  Well anyway I am glad you got this fixed (it seems :)).
0
 
heathprovostCommented:
BTW I re-read the KB article and it applies only to Win32s apps - that was not your problem - I am more puzzled than I was before......
0
 
SofttechAuthor Commented:
>>Are you positive your original code has SW_SHOWNORMAL for
>> the show flag?


Yes I am sure...since I stole the code from another program of mine, which definitely has SW_SHOWNORMAL.

By the way, SW_SHOWDEFAULT is not even a valid constant!  Check the Win 3.1 API help file.  Perhaps you or Microsoft meant "SW_SHOWNORMAL"?  What value does SW_SHOWDEFAULT contain?

How about submitting an answer rather than a comment, so that I can reward you with the 75 points?


0
 
heathprovostCommented:
SW_SHOWDEFAULT is a valid constant for the ShellExecute function - but only under Win32 and Win32s.  Sorry about that, I mis-read the KB article.  Anyway, glad I could help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 9
  • 7
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now