WIN-DOS Graphic Converter - need help in VB programming!

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
User avatar
Wile E. Coyote
Tycoon
Tycoon
Posts: 8515
Joined: 08 Jul 2004 22:14
Skype: wile.e.coyote2
Location: Belgrade, Serbia
Contact:

WIN-DOS Graphic Converter - need help in VB programming!

Post by Wile E. Coyote »

I'm working on program which will convert WIN graphics (GRF and EXE) to DOS graphics and vice versa. I know to program in Visual Basic only. I wrote algorhythms, but I have some problems in programming:

1. Of course, this program needs GRFcodec. Problem is that my program is faster than GRFcodec. When I convert file, GRFcodec must be executed twice (I use Shell command) and converter is trying to execute other GRFcodec, but first is not executed. That confuses program. I fixed it by inserting empty DOO-LOOP, but is there any other way to stop program executing during Shell command? Or is is other way to call programs from command prompt?

2. I can convert only GRFs. EXEs are less popular, but there are some of them available for download and I want to convert them too. I have problems again with Shell command. I must have data what sprites are changed, and their numbers. This is not problem to obtain, but I must create some file and then read this data. I can't create file. Command sequence

Code: Select all

commandString = Graphic & " -l > " & tempFolder & "\sprites.txt"
Shell (commandString)
doesn't make any file.

3. I also have problem with package and deployment wizard. When I make installer, I can't install program. I use WIN XP. Is VB 6.0 compatible with WIN XP? Or maybe my VB is corrupted?

Thanx for help.
Last edited by Wile E. Coyote on 03 Mar 2005 20:36, edited 1 time in total.
Serbian rail set with Serbian scenario (ECS, PBI, FIRS and Tourist set compatible) Website | Topic and download | Latest version: 03.06.2015.
Serbian tram set Tracking table | TTD Patch tram set Latest version: 17.06.2015. | Open TTD Remix Latest version: 11.07.2015.
WIN-DOS GRF Converter Topic and download | Version 0.2.1: 09.01.2005.


Runner-up in "Best avatar Forums award" for years 2006 and 2010!
Prof. Frink
Tycoon
Tycoon
Posts: 3849
Joined: 20 Jan 2003 14:51
Location: Broadstone, Dorset
Contact:

Post by Prof. Frink »

@ point 2:
Why not allow it to run grdtogrf first, then convert the resulting grf file?
User avatar
Wile E. Coyote
Tycoon
Tycoon
Posts: 8515
Joined: 08 Jul 2004 22:14
Skype: wile.e.coyote2
Location: Belgrade, Serbia
Contact:

Post by Wile E. Coyote »

Certainly that will be option in program, to convert EXE to GRF. But this is case when I'm trying to convert WIN EXE to DOS EXE and vice versa.
Serbian rail set with Serbian scenario (ECS, PBI, FIRS and Tourist set compatible) Website | Topic and download | Latest version: 03.06.2015.
Serbian tram set Tracking table | TTD Patch tram set Latest version: 17.06.2015. | Open TTD Remix Latest version: 11.07.2015.
WIN-DOS GRF Converter Topic and download | Version 0.2.1: 09.01.2005.


Runner-up in "Best avatar Forums award" for years 2006 and 2010!
User avatar
orudge
Administrator
Administrator
Posts: 25178
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Re: WIN-DOS Graphic Converter - need help in VB programming!

Post by orudge »

Wile E. Coyote wrote:1. Of course, this program needs GRFcodec. Problem is that my program is faster than GRFcodec. When I convert file, GRFcodec must be executed twice (I use Shell command) and converter is trying to execute other GRFcodec, but first is not executed. That confuses program. I fixed it by inserting empty DOO-LOOP, but is there any other way to stop program executing during Shell command? Or is is other way to call programs from command prompt?
Try using the following code:

Code: Select all

Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Global Const NORMAL_PRIORITY_CLASS = &H20&
Global Const INFINITE = -1&

Private Type STARTUPINFO
    cb As Long
    lpReserved As String

    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Private Type PROCESS_INFORMATION
    hProcess As Long
    
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

Sub ExecCmd(CmdLine As String)
   Dim proc As PROCESS_INFORMATION
   Dim start As STARTUPINFO

   ' Initialize the STARTUPINFO structure:
   start.cb = Len(start)

   ' Start the shelled application:
   ret& = CreateProcessA(0&, CmdLine, 0&, 0&, 1&, _
      NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

   ' Wait for the shelled application to finish:
   ret& = WaitForSingleObject(proc.hProcess, INFINITE)
   ret& = CloseHandle(proc.hProcess)
End Sub
Then just call ExecCmd "command line" to use it.
Command sequence ... doesn't make any file.
You can't use pipes like that except from the command interpreter. Now then, with the example I gave you above, you could do this (untested!):

Code: Select all

' declare section
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const CREATE_ALWAYS = 2
Private Const FILE_ATTRIBUTE_NORMAL = &H80

' ...

Sub ExecCmd(CmdLine As String)
   Dim proc As PROCESS_INFORMATION
   Dim start As STARTUPINFO
   Dim hndl As Long

   ' Initialize the STARTUPINFO structure:
   start.cb = Len(start)

   hndl = CreateFile("c:\path\to\filename", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)

   If Hndl <> 0 Then
      start.hStdOutput = Hndl
   End If

   ' Start the shelled application:
   ret& = CreateProcessA(0&, CmdLine, 0&, 0&, 1&, _
      NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

   ' Wait for the shelled application to finish:
   ret& = WaitForSingleObject(proc.hProcess, INFINITE)
   ret& = CloseHandle(proc.hProcess)

   If Hndl <> 0 Then
      CloseHandle(Hndl)   ' you now have the output text in the file
   End If
End Sub
3. I also have problem with package and deployment wizard. When I make installer, I can't install program. I use WIN XP. Is VB 6.0 compatible with WIN XP? Or maybe my VB is corrupted?
Possibly VB is corrupted. The VB PDW is a horrible thing anyway, don't use it. Just distribute your EXE file, most people have the VB6 runtimes.
User avatar
Wile E. Coyote
Tycoon
Tycoon
Posts: 8515
Joined: 08 Jul 2004 22:14
Skype: wile.e.coyote2
Location: Belgrade, Serbia
Contact:

Post by Wile E. Coyote »

Thanx! :D This is first version (working only with GRFs, soon I'll add EXEs conversion). Please test it, I tested it only with WIN TTDpatch. Post here any bugs you'll found, so I'll fix them!
Attachments
gc02.zip
(27.24 KiB) Downloaded 1050 times
Serbian rail set with Serbian scenario (ECS, PBI, FIRS and Tourist set compatible) Website | Topic and download | Latest version: 03.06.2015.
Serbian tram set Tracking table | TTD Patch tram set Latest version: 17.06.2015. | Open TTD Remix Latest version: 11.07.2015.
WIN-DOS GRF Converter Topic and download | Version 0.2.1: 09.01.2005.


Runner-up in "Best avatar Forums award" for years 2006 and 2010!
JEB
Engineer
Engineer
Posts: 65
Joined: 12 Mar 2004 15:05

Post by JEB »

I created a shell program that worked out of dos and does all this.
I was unhappy with grfwizard and wanted more control.
Granted it is limited to dos names but because I was able to tie it
into other programs like grdtogrf, it gave me quite a menu for doing
all these functions to create a new grf. Since then I have added Sprites and
renum to the GRFMENU. I sure if you're interested you can do a search for it
here and find when I uploaded the code, etc. I haven't been able to find
the orginal author of the powre menu system.

JEB

If you would like my latest version which ties graphic and other programs
into grfmenu, Let me know and will ul to you.
User avatar
Wile E. Coyote
Tycoon
Tycoon
Posts: 8515
Joined: 08 Jul 2004 22:14
Skype: wile.e.coyote2
Location: Belgrade, Serbia
Contact:

Post by Wile E. Coyote »

Yes, of course! Why you don't post it in forum here or in new topic?

I worked those days on next converter version. I had problems with second shell routine. I know it's untested, but if you help me? Here are problems:
1. There was problem with undefined variable:

Code: Select all

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long 
SECURITY_ATTRIBUTES was undefined. I changed this to

Code: Select all

lpSecurityAttributes As Long
Did I made a mistake?
2. Big problem is this code still doesn't make any file. I tried variants:

Code: Select all

commandString = Graphic & " -l > " & tempFolder & "\sprites.txt" 
ExecCmd (commandString) 

Code: Select all

commandString = Graphic & " -l \to\ " & tempFolder & "\sprites.txt" 
ExecCmd (commandString) 
I think I don't understand fthis:

Code: Select all

hndl = CreateFile("c:\path\to\filename", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0) 
What I need to write as "c:\path\to\filename"?
Thanx!
Serbian rail set with Serbian scenario (ECS, PBI, FIRS and Tourist set compatible) Website | Topic and download | Latest version: 03.06.2015.
Serbian tram set Tracking table | TTD Patch tram set Latest version: 17.06.2015. | Open TTD Remix Latest version: 11.07.2015.
WIN-DOS GRF Converter Topic and download | Version 0.2.1: 09.01.2005.


Runner-up in "Best avatar Forums award" for years 2006 and 2010!
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Post by Gremnon »

Hmmm... I know some VB, although I don't pretend to know everything. I do have a few books about here I use to help.
I could look into the source code for you, root about and see if I can find any problems, but I'm not promising anything. It's been a while since I last used it.
Incidentally, VB6 works perfectly on 98SE, ME and 2k, but I've always had problems with XP and VB6. It's probably easier to get Microsoft Visual Studio, which contains VB6 and another program for working in C. I know nothing of C, so I just got VB6.
Anyway, I'll stop waffling for now.
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13233
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Post by Hyronymus »

Please let old topics alone, Gremmon. It's been close to 2 years that this topic saw it's last reply which means you didn't happen to stumble upon it.
User avatar
athanasios
Tycoon
Tycoon
Posts: 3138
Joined: 23 Jun 2005 00:09
Contact:

Post by athanasios »

By the way, when a long time ago, I used this, the generated graphics had errors (some colors were wrong).
http://members.fortunecity.com/gamesart
"If no one is a fool I am also a fool." -The TTD maniac.


I prefer to be contacted through PMs. Thanks.
User avatar
Lakie
TTDPatch Developer
TTDPatch Developer
Posts: 1799
Joined: 26 May 2004 16:37
Location: Britain
Contact:

Post by Lakie »

I never saw what was wrong with using GrfCodec's own Win to DOS palette converter.
(the -m ? option).

~ Lakie
TTDpatch Developer 2005 - 2010 ~ It all started because of shortened vehicle not loading correctly, now look where I've gone with it!
Grfs coded ~ Finnish Train Set (Teaser) | Bm73 (Release 3) | Emu 680 (Release 3)| Glass Station (Release 1) | UK Roadset (Version 1.1a) | New Water Coasts (Version 7)
Pikka: "Lakie's a good coder, but before he'll add any feature to TTDP you have to convince him that you're not going to use it to destroy the world as we know it."
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 6 guests