Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

32bit code in form gives error when running on Windows10 - Need help - Thank you

Status
Not open for further replies.

GordonSH

Technical User
Mar 30, 2021
28
US

I need to change this code in a form to what will work on Windows 10 Please help, Thank you
--------------------------------------------------------------------------------------------------------------------
#DEFINE W32sDLL "W32SCOMB.DLL"
#DEFINE W32DLL "USER32.DLL"
IF "3.5" $ OS(1) OR "Windows 4" $ os(1) or "NT" $ os(1) &&
cDLL = W32DLL
ELSE
cDLL = W32sDLL
ENDIF

DECLARE integer FindWindow IN &cDLL integer, string
DECLARE integer ShowWindow IN &cDLL Integer, Integer

SW_MAXIMIZE = 3
SW_SHOWNORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWGONE = 0

Thisform.showstate = SW_SHOWNORMAL

NullPointer = 0
Set Order to WIZARD_1
ThisForm.FoxHWND = FindWindow(NullPointer, _SCREEN.Caption)

ThisForm.FoxGone = ShowWindow(ThisForm.FoxHWND, SW_SHOWGONE)

---------------------------------------------------------------------------
 


guessing but try..

Code:
IF "3.5" $ OS(1) OR "Windows 4" $ os(1) or "NT" $ os(1) or "Windows 6" $ os(1)

but this code must date back to Windows95 vs NT days ; also guessing it didn't work on Vista or Windows 7 either?

hth

n
 
The FindWindow and ShowWindow APIs are both part of USER32.DLL and have been so for over 20 years. So you should change you code accordingly.
 
I would think for the time being you could just say that cDLL = W32DLL

There are not likely to me many clients running anything less than Win7/Vista.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Vernspace said:
The FindWindow and ShowWindow APIs are both part of USER32.DLL

Good point. In fact, it should be enough to do:

Code:
DECLARE integer FindWindow [b]IN WIN32API[/b] integer, string
DECLARE integer ShowWindow [b]IN WIN32API[/b] integer, string

without having to know the DLL version.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Cannot load 32-bit DLL W32SCOMB.DLL (Error message)

DECLARE integer FindWindow IN &cDLL integer, string (Where error occurred)

What do I remove and what should I replace in the code?

The original program compiled and ran on XP

Now it won't even compile due to the error.

Thank you,
Gordon
 
unless this program still needs to run on NT/Win95 replace the #DEFINEs,IF THEN and DECLAREs with the two lines Mike gave you above.

Code:
DECLARE integer FindWindow IN WIN32API integer, string
DECLARE integer ShowWindow IN WIN32API integer, string 
SW_MAXIMIZE = 3
SW_SHOWNORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWGONE = 0

Thisform.showstate = SW_SHOWNORMAL

NullPointer = 0
Set Order to WIZARD_1
ThisForm.FoxHWND = FindWindow(NullPointer, _SCREEN.Caption)

ThisForm.FoxGone = ShowWindow(ThisForm.FoxHWND, SW_SHOWGONE)

if this program does still need to run on win95/NT boxes (unlikely i hope).... there are more uptodate functions around to determine OS version.

n
 
This is the code on the EXIT program button.


*Command9.click - Exit
_screen.visible=.f.
hide window screen
IF V_DEL_TRUE = .T.
use donate excl
set dele off
pack
ENDIF
close data
ThisForm.Release
ThisForm.FoxGone = ShowWindow(ThisForm.FoxHWND, ThisForm.showstate)
_screen.visible=.f.
DO Back2vfp
--------------------------
I have compiled the EXE and
when I run the exe and then click on EXIT I get the error:

Data type mismatch

I just click IGNORE to finish.

Please help..
 
Gordon,

Have you actually tried any of our suggestions (especially the one about using WIN32API in place of the actual DLL name)?

Also, re the code in your Exit button: how is this connected to your original problem? Or is this something different?

Again, it would help to know which line of code throws the error. As far as I can see, the only one that could cause a a data type mismatch is the one containing [tt]IF V_DEL_TRUE = .T.[/tt], but then hitting Ignore would cause a further error on the ENDIF.

So, please, give us more information, and state your problem(s) clearly.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
To your first question: Here you have an overview about which values OS() returns for which Windows versions, that may help to decide for which DLL to use. But I also agree with the others FindWindows and ShowWindow are such old and central OS API functions, VFP will find the right system DLL when you specify IN WIN32API.

Towards your second question about the Exit button code; if the line which errors is the ShowWindow line this will be mended with the right eclaration, too. All calls to the API funcitons will error as long as the declaration doesn't work, no matter where they are, and they'll all be mend once the declaration works.

In general type errors always point out an assignment of a non-valid value for a field or property or variable, which has a specific type. For example the TAG property of any VFP object can only be a string, not a number or logical value. The data type mismatch might also be with the ShowWindow() call, if Thisform.FoxHwnd isn't a numeric value. Any VFP form simply has Thisform.Hwnd as a valid Windows handle, I'd use that, unless there is a specific reason for the additional FoxHWND property. It could also simply be a follow up error because FoxHwnd isn't set properly from code in the initialisation of the application, so it may have to do with the initial error you got.

Chriss
 
Hi Mike,
Yes, I updated the code that Nigel gave and it corrected the first error.
The program compiled and ran.
When I exited the program, I got the data type mismatch.
The program exited after I ignored the error.
I haven't worked on this program for years but my customer's old XP computer failed so i moved the program to a w10 computer.
I had to do this remotely because I moved 1,100 miles away from my client.
I am thinking that the V_DEL_TRUE variable may be the error as it is declared as a PRIV so maybe I should make it PUBL.
What do you think?
Thankful for all of you folks help on this.
 
Gordon,

Try this:

The next time you get that error, when you see the Cancel / Suspend / Ignore dialogue, click on Suspend. Then open the Debugger (for example, by typing DEBUG in the command window).

In the debugger, go to the Trace window. Look for a little yellow arrow on the left-hand side. That will point to the exact line of code that caused the error. Then hover your mouse over any variables in the line of code. You will see a little pop-up bit of text, a bit like a tooltip. That will tell you the contents of that variable, and hence its data type.

That should give you all the information you need to solve the error. When you are ready to proceed, go back to Visual Foxpro and choose Resume from the Program menu (or simply cancel the program).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
*Command9.click - Exit
_screen.visible=.f.
hide window screen
IF V_DEL_TRUE = .T.
use donate excl
set dele off
pack
ENDIF
close data
ThisForm.Release
ThisForm.FoxGone = ShowWindow(ThisForm.FoxHWND, ThisForm.showstate) *****This where the debugger put the arrow*****
_screen.visible=.f.
DO Back2vfp
---------
Hover results: ThisForm.FoxGone=0 ThisForm.FoxHWND =1837582 ThisForm.showstate=1

Please help. Thank you:)-))
 
OK, If you look at your DECLARE for ShowWindow(), you will see that the second parameter is a string:

Code:
DECLARE integer ShowWindow IN WIN32API integer, [highlight #FCE94F]string[/highlight]

But you are passing an integer.

According to the documentation, the second parameter should be an integer. So you should replace the above line with this:

Code:
DECLARE integer ShowWindow IN WIN32API integer, [highlight #FCE94F]integer[/highlight]

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
I changed the DECLARE to below and the program would now exit with no error.

DECLARE integer ShowWindow IN WIN32API integer, integer

Now, I have a different problem that I am stumped about.
Should I start a new topic or can I just add it to this Thread.

My last issue is with the program that prints to a dot matrix printer with 4x1 labels.
When it prints, the label is printed but then the printer form feeds thinking its a full page instead of stopping after the single label.
I have created a 4x1 paper size but still having trouble with the printer.
Below is the code:
-----------------------------------------------------------
*Command14.click - Print a Single Label for current record.
PUBLIC Defaultpr, Printerb
Local Id_Save
SELECT 1
use medspot
Store medspot.id to Id_Save
sele 5
use owner
SELECT Owner
STORE owner.dprinter TO Defaultpr
MESSAGEBOX (" DEFAULT PRINTER IS: &Defaultpr", 0, "Default Printer Status")
STORE owner.lprinter TO Printerb
MESSAGEBOX (" LABEL PRINTER IS: &Printerb", 0, "Label Printer Status")
sele 3
use label
sele label
appe blan
repl id with medspot.id
repl lastname with medspot.lastname
STORE lastname TO Mlast
repl firstname with medspot.firstname
STORE firstname TO Mfirst
repl address1 with medspot.address1
repl company with medspot.company
repl city with medspot.city
repl state with medspot.state
repl zipcode with medspot.zipcode
repl title with medspot.title
repl country with medspot.country
SET PRINTER TO &Printerb
SET PRINTER FONT 'Swiss', 12
REPORT FORM Label-1.frx NOEJECT NOCONS TO PRINTER
MESSAGEBOX ("Label for: "+trim(Mfirst)+" "+trim(Mlast)+" PRINTED ON &Printerb", 0, "Label Status")
SET PRINTER TO &Defaultpr
USE label excl
set safe off
zap
set safe on
USE label share
Select medspot
Set Order to WIZARD_1
Thisform.Grid1.refresh
ThisForm.Refresh
-------------------------------------
Any help would be appreciated.
Let me know if you need more information.
Thank you in advance,
Gordon
 
PrintingPreferencesLayout_u4tm4m.jpg
Printer1_x0ukq4.jpg

If I have selected the 4x1 Label, why does the printing Preferences show a letter image?
 
You should definitely start a new topic for this question (you can cut and paste from the existing posts).

Doing this will help people who have a similar problem, as it will make it easier for them to find the thread. It will also help people who are interested in the original problem, as it will prevent the current thread from becoming bloated. Best of all, it will help you, because you are more likely to get direct replies to the specific questions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
One other thing you can do to help yourself:

When you post code in a forum message, wrap it in [ignore]
Code:
[/ignore] tags. That way, the code will retain all the original indentation, and also it will be formatted with a mono-spaced font, both of which will make it easier to read. To demonstrate, just compare any of the code in this thread that was posted by the regulars with the code that you posted yourself.

You can either type those tags manually, or highlight the code and then click the Code button in the toolbar (between the Quote and the Spoiler buttons).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
Thank you so much! I am new at this.
Gordon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top