Solved

ShellExecute(...htm) fails with 16 bit

Posted on 1998-12-30
22
269 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
  • 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 70 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now