?
Solved

ShellExecute(...htm) fails with 16 bit

Posted on 1998-12-30
22
Medium Priority
?
279 Views
Last Modified: 2010-04-04
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
Comment
Question by:Softtech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 4
  • +1
22 Comments
 
LVL 7

Expert Comment

by:ahalya
ID: 1353829
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
 
LVL 7

Expert Comment

by:ahalya
ID: 1353830
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
 
LVL 17

Expert Comment

by:inthe
ID: 1353831
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Softtech
ID: 1353832
>>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
 

Author Comment

by:Softtech
ID: 1353833
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
 
LVL 17

Expert Comment

by:inthe
ID: 1353834
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
 
LVL 5

Expert Comment

by:heathprovost
ID: 1353835
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
 

Author Comment

by:Softtech
ID: 1353836
>>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
 

Author Comment

by:Softtech
ID: 1353837
>>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
 

Author Comment

by:Softtech
ID: 1353838
>>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
 

Author Comment

by:Softtech
ID: 1353839
Ooops.  Looks I pressed SUBMIT a wee too many times.

Sorry folks for the redundant comment.  ;-(
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1353840
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
 
LVL 17

Expert Comment

by:inthe
ID: 1353841
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
 
LVL 5

Expert Comment

by:heathprovost
ID: 1353842
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
 

Author Comment

by:Softtech
ID: 1353843
>>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
 
LVL 5

Expert Comment

by:heathprovost
ID: 1353844
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
 

Author Comment

by:Softtech
ID: 1353845
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
 
LVL 17

Expert Comment

by:inthe
ID: 1353846
well done heathprovost :-)
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1353847
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
 
LVL 5

Expert Comment

by:heathprovost
ID: 1353848
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
 

Author Comment

by:Softtech
ID: 1353849
>>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
 
LVL 5

Accepted Solution

by:
heathprovost earned 210 total points
ID: 1353850
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question